Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-timeframe chart/databox not in sync with indicator

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

    Multi-timeframe chart/databox not in sync with indicator

    I am trying to create an indicator that creates a summary aggregation of multiple data series which uses 5, 10, 15, 20 minute time frames. However, the values are not syncing with what is in the various data series on the chart as displayed in the data box. As indicated in the attached graphic, the bars at 11:40 have different values displayed in the indicator verses what is displayed in the data box when the mouse is hovering over the chart for that column. Below is the indicator code and a screenshot. What am I missing?

    protected override void OnStateChange() {

    if (State == State.SetDefaults) {

    AddPlot(new Stroke(Brushes.Black, 1), PlotStyle.Dot, "5 Minute");
    AddPlot(new Stroke(Brushes.Black, 1), PlotStyle.Dot, "10 Minute");
    AddPlot(new Stroke(Brushes.Black, 1), PlotStyle.Dot, "15 Minute");
    AddPlot(new Stroke(Brushes.Black, 1), PlotStyle.Dot, "20 Minute");
    }
    else if (State == State.Configure) {
    AddDataSeries(Data.BarsPeriodType.Minute, 10);
    AddDataSeries(Data.BarsPeriodType.Minute, 15);
    AddDataSeries(Data.BarsPeriodType.Minute, 20);
    }
    }

    protected override void OnBarUpdate() {
    if (CurrentBars[0] <= BarsRequiredToPlot ||
    CurrentBars[1] <= BarsRequiredToPlot ||
    CurrentBars[2] <= BarsRequiredToPlot ||
    CurrentBars[3] <= BarsRequiredToPlot)
    return;​

    // Fixed points for display
    Bars5Plot[0] = 0;
    Bars10Plot[0] = 5;
    Bars15Plot[0] = 10;
    Bars20Plot[0] = 15;

    var o = Opens[0][0];
    var c = Closes[0][0];
    var i = CurrentBars[0]; // bar index

    if (BarsInProgress == 0) {
    SetCurrentBrushColor(i, o, c, Bars5PlotBrush);
    My.Draw.Text(this, GetUniqueTag($"5BarText"), $"5 min i: {i} o: {o} c: {c}", Bars5Plot[0] + VerticalOffset, SmallFont);
    }

    if (BarsInProgress == 1) {
    o = Opens[1][0];
    c = Closes[1][0];
    i = CurrentBars[1];
    SetCurrentBrushColor(i, o, c, Bars10PlotBrush);
    My.Draw.Text(this, GetUniqueTag($"10BarText"), $"10 min i: {i} o: {o} c: {c}", Bars10Plot[0] + VerticalOffset, SmallFont);
    }

    if (BarsInProgress == 2) {
    o = Opens[2][0];
    c = Closes[2][0];
    i = CurrentBars[2];
    SetCurrentBrushColor(i, o, c, Bars15PlotBrush);
    My.Draw.Text(this, GetUniqueTag($"15BarText"), $"15 min i: {i} o: {o} c: {c}", Bars15Plot[0] + VerticalOffset, SmallFont);
    }

    if (BarsInProgress == 3) {
    o = Opens[3][0];
    c = Closes[3][0];
    i = CurrentBars[3];
    SetCurrentBrushColor(i, o, c, Bars20PlotBrush);
    My.Draw.Text(this, GetUniqueTag($"b20Text"), $"20 min i: {i} o: {o} c: {c}", Bars20Plot[0] + VerticalOffset, SmallFont);
    }
    }
    private void SetCurrentBrushColor(int index, double open, double close, BrushSeries plotBrush) {
    Print($"i: {index} o: {open}, c: {close}, c LT o: {close.LT(open)}, c GT o: {close.GT(open)}");
    if (close.LT(open))
    plotBrush[0] = Brushes.Red;
    else if (close.GT(open))
    plotBrush[0] = Brushes.LimeGreen;
    else
    plotBrush[0] = Brushes.Black;
    }​

    Click image for larger version

Name:	ntchart.png
Views:	200
Size:	105.7 KB
ID:	1299937

    #2
    Hi Brandon,
    Thanks for your prompt reply. I implemented your changes as indicated below. However, the issue still persists.

    private double _o5, _o10, _o15, _o20;
    private double _c5, _c10, _c15, _c20;
    private int _i5, _i10, _i15, _i20;
    private DateTime _t5, _t10, _t15, _t20;

    protected override void OnBarUpdate() {
    if (CurrentBars[0] <= BarsRequiredToPlot ||
    CurrentBars[1] <= BarsRequiredToPlot ||
    CurrentBars[2] <= BarsRequiredToPlot ||
    CurrentBars[3] <= BarsRequiredToPlot)
    return;

    // Fixed points for display
    Bars5Plot[0] = 0;
    Bars10Plot[0] = 5;
    Bars15Plot[0] = 10;
    Bars20Plot[0] = 15;

    if (BarsInProgress == 0) {
    _o5 = Opens[0][0];
    _c5 = Closes[0][0];
    _i5 = CurrentBars[0];
    _t5 = Times[0][0];
    SetCurrentBrushColor(_i5, _o5, _c5, Bars5PlotBrush);
    My.Draw.Text(this, GetUniqueTag($"5MinText"), $"5 min {_t5.Hour}:{_t5.Minute} i: {_i5} o: {_o5} c: {_c5}", Bars5Plot[0] + VerticalOffset, SmallFont);
    }

    if (BarsInProgress == 1) {
    _o10 = Opens[1][0];
    _c10 = Closes[1][0];
    _i10 = CurrentBars[1];
    _t10 = Times[1][0];
    SetCurrentBrushColor(_i10, _o10, _c10, Bars10PlotBrush);
    My.Draw.Text(this, GetUniqueTag($"10MinText"), $"10 min {_t10.Hour}:{_t10.Minute} i: {_i10} o: {_o10} c: {_c10}", Bars10Plot[0] + VerticalOffset, SmallFont);
    }

    if (BarsInProgress == 2) {
    _o15 = Opens[2][0];
    _c15 = Closes[2][0];
    _i15 = CurrentBars[2];
    _t15 = Times[2][0];
    SetCurrentBrushColor(_i15, _o15, _c15, Bars15PlotBrush);
    My.Draw.Text(this, GetUniqueTag($"15MinText"), $"15 min {_t15.Hour}:{_t15.Minute} i: {_i15} o: {_o15} c: {_c15}", Bars15Plot[0] + VerticalOffset, SmallFont);
    }

    if (BarsInProgress == 3) {
    _o20 = Opens[3][0];
    _c20 = Closes[3][0];
    _i20 = CurrentBars[3];
    _t20 = Times[3][0];
    SetCurrentBrushColor(_i20, _o20, _c20, Bars20PlotBrush);
    My.Draw.Text(this, GetUniqueTag($"20MinText"), $"20 min {_t20.Hour}:{_t20.Minute} i: {_i20} o: {_o20} c: {_c20}", Bars20Plot[0] + VerticalOffset, SmallFont);
    }
    }

    private void SetCurrentBrushColor(int index, double open, double close, BrushSeries plotBrush) {
    Print($"i: {index} o: {open}, c: {close}, c LT o: {close.LT(open)}, c GT o: {close.GT(open)}");
    if (close.LT(open))
    plotBrush[0] = Brushes.Red;
    else if (close.GT(open))
    plotBrush[0] = Brushes.LimeGreen;
    else
    plotBrush[0] = Brushes.Black;
    }​

    Comment


      #3
      Hi Brandon, thankyou for your reply. I have attached the requested resources.

      Configure a chart to have 4 data series of 5, 10, 15, 20 minute time frames using heiken-ashi bars for the ES using Days to load of 5 and End date of 4/19/2024 for all data series on the chart then add indicator with Input series as the 5 minute data series.

      MyMultiFrameIndicator_20240418.zip

      Click image for larger version  Name:	chartconfig.png Views:	0 Size:	346.0 KB ID:	1300143
      Last edited by love2code2trade; 04-18-2024, 10:34 PM.

      Comment


        #4
        Hello love2code2trade,

        The code in the script you have posted in post # 5 does not match the code you are suggesting you changed in post # 3.
        This code is calling SetFrame() from BarsInProgress 0 only.

        May we have an export of the updated script?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,
          Thankyou for your reply. My apologies, I took out the code that didnt work per post #3 with the class level variables and just made them direct calls. Additionally, I just did some cleanup and i had taken out some custom helpers that made it harder to export as well as to have nothing else interfering with the base functionality we are troubleshooting. the problem is still the same with the values not syncing with the data box.​ I have attached the updated script from which i am working with the missing BarsInProgress conditional statements added back. Thanks for your help!

          MyMultiFrameIndicator_20240419.zip

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          606 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          353 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          560 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          561 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X