Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bug in Time Calculation When Using 2 TF/BarsArrays

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Bug in Time Calculation When Using 2 TF/BarsArrays

    Hello,

    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.
    Attached Files

    #2
    Hello josebolde,

    When using Calculate.OnBarClose, the time would be for the most recent fully closed bar. The

    Also, you should specify which BarsInProgress is updating when fetching by the time.

    If BarsInProgress is 1, supplying Time[0] of the secondary series to BarsArray[0].GetTime() would be trying to get a bar from the primary series using the bar time of the secondary series.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    160 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    307 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    244 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    348 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    178 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Working...
    X