I followed the instructions of this article and it worked for me.
In contrast to this article I want to plot DAILY indicator values in the trade list of an INTRADAY strategy. So if a trade happened on 7/12/2017 I’d like to plot the indicator value (e.g. ATR) as of the close of 7/11/2017.
In the main section of the code if define my Daily indicator as follows:
if(dreportingOn)
{// Compress to Daily
TimeFrameSet (inDaily);
dATR20=ATR(20);
dClose=C;
TimeFrameRestore();
StaticVarSet(Name()+"dATR20", datr20,False);
StaticVarSet(Name()+"dClose",dclose,false);
StaticVarSet(Name()+"dClose1",ref(dclose,-1),False);
}
.....
The backtesting interface should pick the correct values like this:
if(Status("action")==actionPortfolio)
....
for (trade=bo.GetFirstTrade(); trade; trade=bo.GetNextTrade())
{
if(dreportingOn)
{
mydatr=StaticVarGet(trade.Symbol+"dATR20");
trade.AddCustomMetric("dATR20",Lookup(mydatr, trade.EntryDateTime,-1));
mydclose=StaticVarGet(trade.Symbol+"dClose");
trade.AddCustomMetric("dClose",Lookup(mydclose, trade.EntryDateTime,-1));
mydclose1=StaticVarGet(trade.Symbol+"dClose1");
trade.AddCustomMetric("dClose1",Lookup(mydclose1, trade.EntryDateTime,-1));
}
}
bo.ListTrades();
}
However the lookup function seems to return wrong values, when used in combination with compressed arrays. Any ideas how to solve this ?
Thanks.