[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How can I perform an action on the first bar only?



PureBytes Links

Trading Reference Links

In TS 8, how can I perform an action on the first bar only? 

I want to do a print statement that occurs only on the first bar, but when I use certain functions, the statement repeats. I used the following indicator code on a 1 minute stock chart with a duration of two days: 

Var: FirstDate(0);
Var: InitRun(False);
Var: FileText("");

if CurrentBar = 1 then
	begin
	print("InitRun was ", InitRun," Bar = ",numtostr(currentbar,0));
	InitRun = True;
	print("set InitRun to True");
	print("InitRun is now ", InitRun," Bar = ",numtostr(currentbar,0));
	end;

FileText = ""; //
FileText = FileText + numtostr(AverageFC(Close,20),2)+","; // Print("20MA");// 20 Bar M


InitRun was  FALSE Bar = 1
set InitRun to True
InitRun is now   TRUE Bar = 1
InitRun was  FALSE Bar = 1
set InitRun to True
InitRun is now   TRUE Bar = 1

How can I do this? 

Thanks, 

Cash