Barindex null with custom intraday data

Hi,

I get some unexpected behavior while testing my code with custom intraday data.

I have a tick level forex data in CSV. I successfully created a database and added the symbol. (I have uploaded a sample data file and a format file here)

Then I tried to run my AFL code with CBT using Optimize. I have uploaded the code and the apx file, also on above link. (It is a simplified version that produces the problem.)

I put the AFL code also here:

SetOption("UseCustomBacktestProc", True);

l_entry = RSI(12) < 30;
l_exit = Ref(Sum(O - Ref(O, -1) < 0, 1), -7) >= 1;
s_entry = Cross(Ref(C, -6), Ref(BBandTop(C, 60, 0.500), -5));;
s_exit = MACD() > 2;

config_index = Optimize("config_index", 0, 0, 0, 1);

if (Status("actionex") == actionExOptimizeBacktest) 
{ 
	_TRACE("Optimize");
	Buy = l_entry;
	Sell = l_exit;
	Short = s_entry;
	Cover = s_exit;
} 
else if (Status("actionex") == actionBacktest)
{ 
	_TRACE("Backtest");
	Buy = l_entry;
	Sell = l_exit;
	Short = s_entry;
	Cover = s_exit;
}

// actionPortfolio runs for Backtest, actionExOptimizePortfolio runs for Optimize
if ((Status("actionex") == actionPortfolio) || (Status("actionex") == actionExOptimizePortfolio))
{
    bo = GetBacktesterObject(); 
    bo.Backtest(True); 
        
    for (trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade())
    {         
		entry_date = trade.EntryDateTime;
		_TRACEF("Entry_date: %s", DateTimeToStr(entry_date, 3));
		entry_index = Lookup(BarIndex(), entry_date, 0);
		_TRACEF("Bar_index: %f", entry_index);
    }
    
    bo.ListTrades();
}

So if I try to run this on different timeframes. For 5s and 15s it works fine, but for 1s, the trade entry datetime does not seem to have a corresponding index in Barindex(). However I can see a bar with that datetime on the chart in Analysis window. But the Lookup() gives back Null. It can be seen in the Trace log.

Maybe some intraday setting is wrong? First time I work with intraday.

Thank you!
Best regards,
Gabor

Remove third argument of Lookup function (so just use two arguments) then it should output index.
I am not sure why since default mode value is zero (according to manual) and
removing 3rd argument should use that default value zero. So results should be the same ones.


FYI, there are subsecond functions MilliSec() and MicroSec(). So you may use those in Lookup().


Also you should pass arrays to 2nd phase (CBT) via static vars.

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.