Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Last Historical Bar?

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

    Last Historical Bar?

    Any suggestion on how to trigger OnBarUpdate on last historical bar only?

    Bars.LastHistorical or Bars.Loaded properties would be handy properties for this purpose.

    The indicator I´m working with uses Infinite lookback and performs all historical calculations (0 -> CurrentBar looping) on each bar - hence last historical/current bar update only would make loading faster.

    Kindly, Fredrik
    Last edited by FREEN; 11-09-2011, 04:25 AM.

    #2
    Hi Frederik, try doing your calcs then in a condition like this :

    if (Bars.Count - 2 == CurrentBar && Historical)
    {
    do calcs on last historical bar
    }
    BertrandNinjaTrader Customer Service

    Comment


      #3
      HI Guys,

      I would like to do exactly what Freen has requested here.

      Bertrand, I tried your solution.... am I missing something here because your suggested code still only allows the indicator to load if it is the last bar on the chart. "Bars.Count" returns the same value as "Count" for me. So therfore your code will skip every bar until we are at Count - 2 which is when all historical bars are already loaded. What if we want the indicators code to only initiate once the CurrrentBar has arrived at the current scroll point of the chart?

      Comment


        #4
        Can you clarify the meaning of "scroll point"? A screenshot with your notes on it will easily explain.
        ninZa
        NinjaTrader Ecosystem Vendor - ninZa.co

        Comment


          #5
          Originally posted by marty087 View Post
          HI Guys,

          I would like to do exactly what Freen has requested here.
          Then you are not doing exactly what Freen is doing.

          Comment


            #6
            Originally posted by ninZa View Post
            Can you clarify the meaning of "scroll point"? A screenshot with your notes on it will easily explain.
            Scroll point in the sense last bar on screen, that might not be bars.count.

            Comment


              #7
              Originally posted by ninZa View Post
              Can you clarify the meaning of "scroll point"? A screenshot with your notes on it will easily explain.
              See pic for clarification
              Attached Files

              Comment


                #8
                In short....

                CurrentBar returns the id of the last bar displyed on the right of the screen irrecpective of whether the chart is scrolled to the end or not.

                Count OR Bars.Count returns how many bars are in the chart once fully loaded / scrolled to the right alll the way

                So..... if i am in the middle of the chart and want my indicator to only execute once it has arrived at the furtherest scrooled bar, is there any way to do this?

                FREEN, is it fair to say that the supplied code below (Bertrand's contribution) didnt provide a solution for you?

                Cheers Guys.

                Comment


                  #9
                  marty087, please try LastBarIndexPainted. I'm not sure this works in your case. This will give you the last bar painted on chart after the bars are loaded. In your case, you want to get the value in advance, so I'm not sure. Please test it, if it doesn't work, we will have to take another approach.

                  Thanks.
                  Last edited by ninZa; 02-04-2015, 02:22 AM.
                  ninZa
                  NinjaTrader Ecosystem Vendor - ninZa.co

                  Comment


                    #10
                    Originally posted by marty087 View Post
                    In short....

                    CurrentBar returns the id of the last bar displyed on the right of the screen irrecpective of whether the chart is scrolled to the end or not.

                    Count OR Bars.Count returns how many bars are in the chart once fully loaded / scrolled to the right alll the way

                    So..... if i am in the middle of the chart and want my indicator to only execute once it has arrived at the furtherest scrooled bar, is there any way to do this?

                    FREEN, is it fair to say that the supplied code below (Bertrand's contribution) didnt provide a solution for you?

                    Cheers Guys.
                    marty087, when you are in the middle of the chart, the indicator will only execute until the last bar printed on your chart and then it will temporarily stop there, until a LIVE tick comes in. If there are no live data coming in, the indicator will not reach the actual last bar (whose index is Bars.Count - 1). You have to manually scroll your chart back to the actual last bar. This is my 30-minute inspection on the issue, need a confirmation from NT staff.

                    However, if in a live market with fast coming data, you can execute the following unsupported codes to ignore all bars until the last painted bar:


                    if (ChartControl.GetXByBarIdx(BarsArray[0], CurrentBar) < ChartControl.CanvasRight) return;
                    Cheers.
                    Pi
                    Last edited by ninZa; 02-04-2015, 03:08 AM.
                    ninZa
                    NinjaTrader Ecosystem Vendor - ninZa.co

                    Comment


                      #11
                      Originally posted by ninZa View Post
                      marty087, please try LastBarIndexPainted. I'm not sure this works in your case. This will give you the last bar painted on chart after the bars are loaded. In your case, you want to get the value in advance, so I'm not sure. Please test it, if it doesn't work, we will have to take another approach.

                      Thanks.
                      BOOM! Worked a charm. Where did you pull that one from?

                      Thanks.
                      Attached Files

                      Comment


                        #12
                        Originally posted by marty087 View Post
                        BOOM! Worked a charm. Where did you pull that one from?

                        Thanks.
                        It works actually? I'm not sure, so I gave you another solution above.

                        I don't remember where I got the info of LastBarIndexPainted. Perhaps searched something on Google and found it.

                        Regards.
                        Pi
                        ninZa
                        NinjaTrader Ecosystem Vendor - ninZa.co

                        Comment


                          #13
                          Originally posted by ninZa View Post
                          It works actually? I'm not sure, so I gave you another solution above.

                          I don't remember where I got the info of LastBarIndexPainted. Perhaps searched something on Google and found it.

                          Regards.
                          Pi
                          Great stuff. Thanks again

                          Comment


                            #14
                            Originally posted by marty087 View Post
                            BOOM! Worked a charm. Where did you pull that one from?

                            Thanks.
                            Probably from here: http://www.ninjatrader.com/support/f...d.php?p=261631

                            Though, given his skills, Ninza may have come upon that independently.

                            Comment


                              #15
                              Originally posted by koganam View Post
                              Probably from here: http://www.ninjatrader.com/support/f...d.php?p=261631

                              Though, given his skills, Ninza may have come upon that independently.
                              My skill is googling Koganam lol.

                              Regarding your comment about the dependence on COBC, should we reverse the order? I mean the 1st one (ChartControl) should be absolute, and the 2nd one is dependent on COBC?
                              Last edited by ninZa; 02-04-2015, 06:21 PM.
                              ninZa
                              NinjaTrader Ecosystem Vendor - ninZa.co

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by TheMarlin801, 10-13-2020, 01:40 AM
                              20 responses
                              3,914 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Started by timmbbo, 07-05-2023, 10:21 PM
                              3 responses
                              151 views
                              0 likes
                              Last Post grayfrog  
                              Started by Lumbeezl, 01-11-2022, 06:50 PM
                              30 responses
                              808 views
                              1 like
                              Last Post grayfrog  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              3 responses
                              11 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by Johnny Santiago, 10-11-2019, 09:21 AM
                              95 responses
                              6,194 views
                              0 likes
                              Last Post xiinteractive  
                              Working...
                              X