Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multitimeframe Indicator

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

    Multitimeframe Indicator

    Hi
    I need a little help to understand what I do wrong.

    Code:
    else if (State == State.Configure)
    {
    AddDataSeries( BarsPeriodType.Month, 1);
    
    }
    and am trying to get the realtime value right now and the open of the month by doing this
    Code:
    if(State == State.Realtime)
    {
    Print(BarsArray[1].GetClose(0)+ " "+BarsArray[1].GetOpen(0));
    }
    I do get the now value but the open value is not the open of the month.

    Best Regards,
    Sune

    #2
    Hello SuneSorgenfrei,

    Thanks for your post.

    The Get methods you are using require a bar index value and you are using 0 which would be the very first bar of the data set. Typically, you would want to use the Close[] and Open[] Price types, and in multi time frame you would use the plurals of those, IE: Closes[][], Opens[][] where the first [] is the bars array and the second [] is the specific bars ago, for example Closes[1][0] and Opens[1][0] would provide the current bar Open and Close of the first added data series.

    References:





    If you are new to multi time frame/series programming, we highly recommend a complete review of the help guide that covers this topic in detail: https://ninjatrader.com/support/help...nstruments.htm

    Comment


      #3
      HI
      Thanks for your answer but that does also not work. Anytime I try to get the values from the added dataseries with Opens[1][0] or Closes[1][0] I get an error
      Code:
      Indicator 'TheStratTFC': Error on calling 'OnBarUpdate' method on bar 39244: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart..
      What I am trying to do is on a lower TimeFrame chart like let us say 60 min on each pricechange I need at least the open value of the added dataseries at that point in time. I thought that that value would be accessible as I am only reacting to events in realtime but seems it is not.

      Comment


        #4
        Hello SuneSorgenfrei,

        Thanks for your reply.

        The error is advising that "when" you are accessing a bars ago value that the bar does not exist.

        Please make sure you review the Multi time frame reference information in post #2 as this addresses making sure that you are only accessing the data when the appropriate BarsInProgress calls the OnBarUpdate(). Both data series will call the OnBarUpdate(), with calculate.OnPriceChange, both will call it on each price change during live data. Historically the OnBarUpdate will only be called once per bar per data series.

        Also, if you are using calculate.OnBarClose OR are running your script on historical data, the "current bar" would be the bar that just closed and not the currently forming bar, meaning that you may be looking back 1 more month than you think, again this is discussed and diagrammed in that reference section.

        When you add a script to a chart, the script will process your code on a bar by bar basis all the way through all of the historical data until it reaches live data and at that point will begin processing with Calculate.OnPriceChange, prior to that it would process as Calculate.OnBarClose. When on live data with Calculate.OnPriceChange, the current bar bars ago reference of [0] changes from just closed bar to the currently forming bar.

        Sorry if this seems like a lot of information but with MTF type scripts there are other considerations for programming.

        Comment


          #5
          Hi Paul,

          I am looking at getting last price value of currently forming Monthly bar but as you rightly said, I get 1 month back data. How can I access the updated last price of the forming bar? Sincerely appreciate your guidance here.

          "Also, if you are using calculate.OnBarClose OR are running your script on historical data, the "current bar" would be the bar that just closed and not the currently forming bar, meaning that you may be looking back 1 more month than you think, again this is discussed and diagrammed in that reference section.
          "

          Thanks

          Comment


            #6
            Hello bpathak,

            Thanks for your post.

            On Live data (or Playback with Market replay data), to pull the current month data, you would need your code to run with Calculate.OnEachTick or Calculate.OnPriceChange.

            Comment


              #7
              Thanks for your reply. I have tried both OnPriceChange and OnEachTick. My primary series is daily on the chart and the strategy I am running is also using weekly and Monthly data which is being referenced as below. However, the weekly and monthly values are of previous candle and not the forming bar. The OnPriceChange is not taking effort for weekly and monthly data. How can I achieve this?

              if (State == State.SetDefaults)
              { //Calculate = Calculate.OnPriceChange;
              Calculate = Calculate.OnEachTick;}

              else if (State == State.Configure)
              { AddDataSeries(Data.BarsPeriodType.Week, 1);
              AddDataSeries(Data.BarsPeriodType.Month, 1);}

              Comment


                #8
                Hello bpathak,

                Thanks for reply.

                I created a short video to demonstrate accessing the current bar of each of the data series.




                Comment


                  #9
                  Thanks a lot Paul for creating the video. I guess there is no way to get this working on historical data. I was hoping to have visibility to weekly and monthly forming bars in the strategy with daily data as primary.

                  Thanks

                  Comment


                    #10
                    Hello bpathak,

                    Thanks for your reply.

                    On Historical data, you would have to have "tick data" from your historical provider and you would have to enable Tick Replay. You would need to tick data for the entire history of the chart bars days to load.

                    Reference: https://ninjatrader.com/support/help...ick_replay.htm

                    Comment


                      #11
                      Hi Paul, I subscribed to IBKR Pro connection and view realtime charts, however on running strategy the "State" shows "Historical" and not "Realtime". Would you know whats the issue?

                      Comment


                        #12
                        Hello bpathak,

                        Thanks for your reply.

                        "the "State" shows "Historical" and not "Realtime".", Can you clarify where or how you are observing this? If you are testing in the strategy analyzer, you would never get to State.RealTime because it is only historical data.




                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        589 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        342 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
                        555 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