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 argusthome, 03-08-2026, 10:06 AM
    0 responses
    57 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    37 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    18 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    20 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    49 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X