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