AFL help new candle skips


Active Member
Hi - Need help with my AFL. The code is not trigerring on every new candle first tick.

I want to dump complete candles OHLC values in a file as soon as tick for a new bar arrives. I am on a 15 min timeframe chart and every time a new candle starts, the afl should dump last completed candles value . Also after dumping the values, I want to call a program using alertif . This program has the logic of whatever i want to do with the values..

I have written this AFL but it triggers the new candle only skips some of the new candle ticks and neither the values are dumped in a file nor the binary is called, and I am not sure why. Any idea if I am doing anything wrong here....

_SECTION_BEGIN("New candle dump");
filename = "e:\\" + Name() + ".txt";
PrevTN = StaticVarGet("TimeNumber");
TN = LastValue(TimeNum());
NewBar = TN != PrevTN;
barcomplete = BarIndex() < LastValue(BarIndex());

if (NewBar)
fh = fopen( filename, "w");
if( fh )

qs = StrFormat("%.2f, %.2f, %.2f, %.2f, %.0f\n",
Open[ BarCount - 2], High[ BarCount - 2], L[ BarCount-2], C[ BarCount-2],ttime );
fputs( qs, fh );

fclose( fh );
AlertIf( barcomplete OR NewBar , "EXEC e:\\trading.exe " , Name(),1);


Please assist

Similar threads

Trade in Rs 20, No more % brokerage

Are you a day trader?