I've attached a tiny indicator that shows the issue. But here is an attempt to describe the issue.
OnBarUpdate() behaves as expected -- the index is the same as the CurrentBar
protected override void OnBarUpdate()
{
if (CurrentBar % 2 == 0)
{
Signals[0] = CurrentBar;
}
var isValid = Signals.IsValidDataPoint(0);
Print(string.Format("isValid={0} at {1}", isValid, CurrentBar));
if (isValid)
{
var signal = Signals.GetValueAt(CurrentBar);
Print(string.Format("signal={0} at {1}", signal, CurrentBar));
}
}
But OnRender() has a very different behavior (unless I'm missing something major!).
var ADJUSTMENT = 1;
Print(string.Format("Bars.Count={0},ChartBars.Coun t={1}", Bars.Count, ChartBars.Count));
for (int idx = ChartBars.FromIndex; idx <= ChartBars.ToIndex; idx++)
{
var isValidSignal = Signals.IsValidDataPoint(Bars.Count - 1 - idx);
Print(string.Format("At idx={0} isValidSignal={1}", idx, isValidSignal));
if (!isValidSignal)
{
continue;
}
var signal = Signals.GetValueAt(idx - ADJUSTMENT);
Print(string.Format("At idx={0} signal={1}", idx, signal));
}
So you can see that I have to subtract 1 from the idx for Signals.GetValueAt() but NOT for Signals.IsValidDataPoint(), otherwise I get 0 (wrong) values for the Signals setting at idx.
For example, in the Output window, OnBarUpdate gives me:
isValid=False at 85
isValid=True at 86
signal=86 at 86
isValid=False at 87
But OnRender gives me:
At idx=86 isValidSignal=False
At idx=87 isValidSignal=True
At idx=87 signal=86
At idx=88 isValidSignal=False
Thanks for your help,
Dale
Comment