Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi Time Frame (MTF) Indicator

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

    #16
    Hi Peter Cherry,

    Is this the exact script you are running on your end?

    I am not able to run this script. You are attempting to set a plot that is synced with the daily series in the bars in progress of the hour series. This means that the plot value does not exist yet (because the day bar does not exist yet) and this causes the following error for me:
    Error on calling 'OnBarUpdate' method for indicator 'Example' on bar 5: Index was outside the bounds of the array.

    Have you changed this script?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Hi,
      sorry I did the small mistake during cutting unimportant script logic. This version should work fine.

      I am updating the plot within the hour series, because I would like update of daily bar (e.g. color) immediately when the condition on 60-min series is met.

      Peter
      Attached Files

      Comment


        #18
        Hi Peter Cherry,

        I am still unable to run this script.

        From an ES 06-14 Daily chart I am getting the following in the output window:

        Open BIP1: 1601 > 1845
        Error on calling 'OnBarUpdate' method for indicator 'Example' on bar 73: Index was outside the bounds of the array.

        Is this script running successfully on your end?

        What does your output look like?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          Hi,
          no problem on my machine (see my output and settings).
          Or how would you update the script not to have a yellow line 1 day ahead?
          Thanks for support
          Peter
          Attached Files

          Comment


            #20
            Hi Peter Cherry,

            I had to reload the script but I am getting results now.

            OK, so when I run this script, on the 24th this bar is historical data and is being run with calculate on bar close as true.

            Open BIP1: 1845.25 > 1845
            2/21/2014 3:15:00 PM
            2/24/2014 2:00:00 PM

            At 2:00 PM the most completed bar (with COBC (Calculate on bar close) true) is the friday on the 21st.

            For today we get:
            Open BIP1: 1876.75 > 1845
            5/2/2014 3:15:00 PM
            5/5/2014 11:00:00 AM

            Open BIP1: 1876.75 > 1845
            5/5/2014 3:15:00 PM
            5/5/2014 11:00:00 AM

            This is because right at 11:00 this script does its last historical print and then the live prints start coming through. With the live data COBC is false. This means that Times[0][0] now refers to the bar that is building (today's bar) and not the bar that has most recently closed.

            The data does appear to be referencing the correct day.

            The issue I think you are running into is that the plots are always syncronized with the primary data series which is the daily series.

            So TmpUpTargetBuffer[0]=TmpUpTargetBuffer[1]; on the 24th, means you will be setting the plot of the most currently completed day which is the 21st.

            You may want to try replacing:
            Code:
            UpTargetBuffer[0]=TmpUpTargetBuffer[0];
            DnTargetBuffer[0]=TmpDnTargetBuffer[0];
            with:
            Code:
            if (Historical)
            {
            UpTargetBuffer.Set(-1, TmpUpTargetBuffer[0]);
            DnTargetBuffer.Set(-1, TmpDnTargetBuffer[0]);
            }
            else
            {
            UpTargetBuffer[0]=TmpUpTargetBuffer[0];
            DnTargetBuffer[0]=TmpDnTargetBuffer[0];
            }
            Chelsea B.NinjaTrader Customer Service

            Comment


              #21
              Hi ChelseaB,
              it is possible to use this workaround, but then you get into the similar problem on Secondary 60-min resolution (line starts one bar after the condition, because of this -1). I would like to create simple universal framework to have everything ok on all resolutions (Primary, Secondary etc.).

              BTW, is it possible to sync plots to the secondary data series as same as it is done for buffers?

              Thanks
              Peter

              Comment


                #22
                Hi Peter,

                When you say
                "but then you get into the similar problem on Secondary 60-min resolution (line starts one bar after the condition, because of this -1)"
                do you have a screenshot of this happening?

                The check for historical should prevent live data from plotting a day ahead.

                No, it is not possible to synchronize a plot with a secondary data series. Plots are synced with the primary data series because that is what is showing on the chart and the chart has time intervals for.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #23
                  Hi,
                  here you have the screenshot. It is obvious, we shifted it on Daily time-frame back, but on 60-min time-frame (when PRIMARY = SECONDARY) it is also shifted 1 bar back, which is wrong.

                  M former solution worked fine on 60-min time-frame, but it had problem on daily time-frame.

                  Unfortunately we are moving in a circle

                  Peter
                  Attached Files

                  Comment


                    #24
                    Hi Peter,

                    If the primary and secondary data series are the exact same, then when Closes[1][0] closes it will have the same bar time as Closes[0][0].

                    In other words this issue doesn't exist where the bar time of the current hour bar refers to the previous day as that is the most recent fully closed bar.

                    You will have to add special logic to handle these differently.

                    Something like:
                    Code:
                    if (Historical && BarsPeriods[0].Id != PeriodType.Minute && BarsPeriods[0].Value != 60)
                    {
                    UpTargetBuffer.Set(-1, TmpUpTargetBuffer[0]);
                    DnTargetBuffer.Set(-1, TmpDnTargetBuffer[0]);
                    }
                    else
                    {
                    UpTargetBuffer[0]=TmpUpTargetBuffer[0];
                    DnTargetBuffer[0]=TmpDnTargetBuffer[0];
                    }
                    }
                    Aught to do the job.

                    This code says that if the bar type is minute and the period is 60 then to not plot a day ahead.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #25
                      Hi ChelseaB,
                      it seems this workaround fixed the problem

                      Anyway, do you think my approach is fine or would it be better to design this MTF in different way at all?
                      I mean mainly my TmpBuffers (synced to Secondary series) and Plots filled within Secondary series code)....

                      My general idea is to set basic calculating time-frame first (e.g.: 60min) and see lines on any other time-frame with the same results. For example to see on daily (weekly) chart basic support level calculated from hourly / minute data.

                      Thanks for your opinion
                      Peter

                      Comment


                        #26
                        Hi Peter Cherry,

                        My only advice would be to set the plot when the primary data series is being processed using variables that are updated in the secondary series.

                        This will help keep the logic smoother as you will always know when it will plot.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #27
                          Hi ChelseaB,
                          so you mean not to use UpTargetBuffer.Set within BarsInProgress = 1 section and add some variable(e.g. over = true/false) to know when to plot within BarsInProgress = 0 ?
                          Peter

                          Comment


                            #28
                            Hi Peter Cherry,

                            That is correct. As plots can only be synced with the primary data series, it makes the logic smoother and easier to understand if the plots are set on the primary data series.

                            This is not required, I just find it helpful when creating code and trying to understand what will happen in my head.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #29
                              Thanks for answer.

                              Additionally, I realize that BarsInProgress=0 is processed before any other timeseries, so the following simple example doesn't work, becuase TmpUpBuffer is zero (and plot = false).

                              if (BarsInProgress == 1)
                              {
                              TmpUpTargetBuffer[0]=1845;
                              plot = true;
                              }

                              if (BarsInProgress == 0)
                              {
                              if(plot == true) Plot[0]=TmpUpTargetBuffer[0];
                              }

                              Comment


                                #30
                                HI Peter Cherry,

                                BarsInProgress 0 is not always processed before any other BarsInProgress.

                                OnBarUpdate is a truely event driven method. OnBarUpdate will trigger for a particular BarsInProgress when a tick is received after the time of a bar close (so that a new bar can be opened).

                                If you have a 5 minute primary series and a 1 minute secondary series BarsInProgress 1 will definitely trigger before BarsInProgress 0.

                                If you have a 1 minute primary series and 1 minute secondary series with a different instrument, then which ever tick is received first after the time of a bar close will be the BarsInProgress that is triggered first.

                                So that being said, if BarsInProgress 1 has a smaller time frame than BarsInProgress 0, then OnBarUpdate will trigger before BarsInProgress 0. Lets say a 5 minute primary and 1 minute secondary series again. In this situation BarsInProgress 1 is going to process 4 times before BarsInProgress 0 will trigger.
                                Chelsea B.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                581 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                338 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                103 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                554 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                552 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X