I have this #include function:
procedure GetOpenPositions(filename,varname) {
if (Status("stocknum") == 0) {
StaticVarRemove(varname);
my_symbols = "|";
fh=fopen(filename, "r", True);
if (fh)
{
while (! feof(fh))
{
line = StrTrim(StrTrim(fgets(fh),"\n")," ");
if (line == "") continue;
if (StrLeft(line,1) == "#" OR StrLeft(line,1) == "/") continue;
my_symbols+=line+"|";
}
fh=fclose(fh);
}
StaticVarSetText(varname,my_symbols);
}
}
And here is how I call it in my main program:
// Exploration Analysis - this column flags if the Sell has been previously bought (based on data in an external file)
MyOpenPositions="";
GetOpenPositions("C:\\Temp\\MyOpenPositions.txt","MyOpenPositions");
MyOpenPositions=StaticVarGet("MyOpenPositions");
find=(StrFind(MyOpenPositions,Name()) != 0);
AddMultiTextColumn(IIf(Sell,find,Null),"No\nYES","In Trade?",0,colorDefault,IIf(find,colorRed,colorDefault));
I get this intermittent error:
during Explore and Optimization. If Explore I just click Explore again and it works. However, during a long running Optimization it ruins my day.
The only thing I can figure is there is an occasional situation where I don't have
Status("stocknum") == 0
so the StaticVar doesn't get set, and the calling code sets MyOpenPositions to a number.
However, I'm afraid if I move StaticVarSetText outside the if condition it will kill performance.
So...is there ever a situation where there is no "stocknum==0"?