I am working on an multi-timeframe indicator, and part of its calculation involves looking for values within a dynamic time range given by the current trend as defined by a double-crossover method.
Here is part of the code:
protected override void OnBarUpdate()
{
if (BarsInProgress != 0) // Logic applies to primary series only
return;
IDataSeries dataSeries = BarsArray[Series - 1];
IDataSeries Indicator = RSI(Period, 1); // *** CUSTOMISABLE ***
if (CurrentBar - 1 < Slow
|| Indicator.IsValidPlot(CurrentBar - 1) == false
|| CurrentBars[1] < 0) // Sufficient data checks
return;
if (CrossAbove(EMA(dataSeries, Fast), EMA(dataSeries, Slow), 1)
|| CrossBelow(EMA(dataSeries, Fast), EMA(dataSeries, Slow), 1)) // Resets lookBack at the start of a new trend
lookBack = 1;
else
lookBack++;
However, the code is producing the wrong results when the primary data series is Daily and the secondary data series is Weekly...
For some reason, whenever there is crossover based on the Weekly (secondary) series, I get a whole week of Daily (primary) bars where lookBack equals 1 (when values should have ranged from 1 to 5). It is only after week 2 when the Daily bars update correctly, with lookBack increasing on Daily intervals.
Is there anything wrong in my code? Or could this be a bug?
Thanks for your help,
Stopped
Comment