When running a backtest I get different results from when I use the same code when clicking on a chart. The code I run is simply dragged onto the screen as a new indicator,
The part of the code is
_TRACE("========= buy ======");
_TRACE("symbol " + tradeSymbol);
buyDate = buyTrades[i][1];
_TRACE("buyDate " + buyDate);
_TRACE(" " + typeof(buyDate));
_TRACE("buyDate " + DateTimeToStr( buyDate, mode = 3 ));
barI = Lookup( BarIndex(), buyDate);
_TRACE("barI " + barI);
if( IsNull( barI ) OR (barI == 0))
_TRACE( tradeName + " - barI " + barI + " NOT found" );
else
Result from clicking the screen is
When running the backtest it is
The problem appears to be with the lookup function as the bar index is not found when using the backtest.
The part of the code is contained in an included function that reads from an external CSV file. I don't think this is the problem because it is exactly the same code executed in both cases.
I haven't uploaded the entire code as I just want some tips to try and sort it out. If I am unable I will post the code later.
Short Answer: Dont use Bar index as it can be arbitrary because of QuickAFL. Chart thread and Analysis thread may be working on different subset of data.
If we are using a plugin for Data, the historical data length may "over time" vary so even when using "All bars", we cannot guarantee the same Bar index number for a bar. This is a possible scenario only when data length may change.
And it now works. I will follow up on the use of timestamp (and re visit the quickAFL info) but for now, it is solved. As I am using EOD processing I am not too concerned with the quicjAFL but will look into it.
Requesting all bars always is inefficient. It is like turning heating all the way up and opening all windows in your home at the same time. Waste of energy.