has anyone ever had the first lower timeframe bar of a new higher timeframe bar get a bug on its BarsArray.GetTime() method?
I striped down my code to the following for the issue to be easier to spot:
namespace NinjaTrader.NinjaScript.Indicators
{
public class DebugErrorTF : Indicator
{
Series<DateTime> HTFTime;
Series<DateTime> LTFTime;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "DebugErrorTF";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
}
else if (State == State.Configure)
{
AddDataSeries(BarsPeriodType.Second, 30);
HTFTime = new Series<DateTime>(this);
LTFTime = new Series<DateTime>(this);
}
}
protected override void OnBarUpdate()
{
HTFTime[0] = BarsArray[1].GetTime(CurrentBars[1]);
LTFTime[0] = BarsArray[0].GetTime(CurrentBar);
Print("HTF Time: " + HTFTime[0]);
Print("LTF Time: " + LTFTime[0]);
Print("Current Bar: " + CurrentBar);
}
}
}
region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private DebugErrorTF[] cacheDebugErrorTF;
public DebugErrorTF DebugErrorTF()
{
return DebugErrorTF(Input);
}
public DebugErrorTF DebugErrorTF(ISeries<double> input)
{
if (cacheDebugErrorTF != null)
for (int idx = 0; idx < cacheDebugErrorTF.Length; idx++)
if (cacheDebugErrorTF[idx] != null && cacheDebugErrorTF[idx].EqualsInput(input))
return cacheDebugErrorTF[idx];
return CacheIndicator<DebugErrorTF>(new DebugErrorTF(), input, ref cacheDebugErrorTF);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.DebugErrorTF DebugErrorTF()
{
return indicator.DebugErrorTF(Input);
}
public Indicators.DebugErrorTF DebugErrorTF(ISeries<double> input )
{
return indicator.DebugErrorTF(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.DebugErrorTF DebugErrorTF()
{
return indicator.DebugErrorTF(Input);
}
public Indicators.DebugErrorTF DebugErrorTF(ISeries<double> input )
{
return indicator.DebugErrorTF(input);
}
}
}
#endregion
The indicator is running in a 5s chart.
As you can see in the uploaded screenshot, when the higher timeframe bar changes, there seems to be an extra calculation that momentarily messes with the lower timeframe CurrrentBar Index and DateTime, sending it back to what I assume is the first bar?
Any input on this would be really appreciated.
BR,
Jose.

Comment