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

Highest Bar in an earlier range of bars

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

    Highest Bar in an earlier range of bars

    Guys, I need to find the highest bar in a prior range of bars. For example, how would I find the number of bars back the highest bar occured in the 10-bar range of 50 to 60 bars ago? One approach would be a loop like

    do {HighBar=HighestBar(High,60)} while (HighBar<50);

    But is there a more elegant (and faster) method? HighestBar(High,10) won't work because it has no "[barAgo]" input. MAX(High,10)[50] returns the high of the bar in question, but not the number of bars ago it occurred. Does NinjaScript have other functions that I'm missing for this task?

    Thank you for your help...

    Light
    Last edited by Light; 01-26-2010, 12:10 AM.

    #2
    Originally posted by Light View Post
    ...But is there a more elegant (and faster) method? HighestBar(High,10) won't work because it has no "[barAgo]" input. MAX(High,10)[50] returns the high of the bar in question, but not the number of bars ago it occurred. Does NinjaScript have other functions that I'm missing for this this ...
    I am not aware of other NT functions.
    You could store the result of HighestBar(High,10) in a data series and access the data series with the bars-ago-index.

    Regards
    Ralph

    Comment


      #3
      Thanks Ralph - you could take a look at GetBar() as well Light, would offer access to the bar number ago of the DateTime passed in.

      BertrandNinjaTrader Customer Service

      Comment


        #4
        Thanks Ralph and Bertrand. Ralph, unfortunately the range over which I might look is variable -- 10 bars one time, 20 the next, 7 the next, etc. So there is no single range to store. But I'll keep your idea in mind.

        Bertrand, GetBar requires the time stamp of the bar in question, which is unknown. As far as I can tell, the only information about the highest bar accessible from built-in Ninja methods is its high, via MAX(High,10)[50], from which the bar itself cannot be found.

        This type of test is fairly standard. The obvious analogy is the HighestBar function in Easy Language, which contains two "barsAgo" placement options: HighestBar(High,10)[50] and HighestBar(High[50],10). (Output from the second is measured from the first bar in the 10-bar range.) Here it is in Ensign's ESPL: Highest(eHigh,50,10, function returns Bar Index here ,1,0) = highest high.

        Does Ninja have plans to add a "[barsAgo]" option to HighestBar/LowestBar in NT7? If not, could I suggest that it please be included?

        Thanks for your help guys.

        Best wishes,

        Light
        Last edited by Light; 01-26-2010, 11:32 PM.

        Comment


          #5
          Thanks Light. Currently those methods will be remaining the same for NT7.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Light, in that situation I would write a function with the same parameter set you explained and loop through the desired range of bars starting with the desired starting bar. I guess nothing else would happen if NT provides such functionality. And I guess that is what you had in mind originally yourself. Or is there a special point which makes it worth to spend some more effort on this task?

            Regards
            Ralph

            Comment


              #7
              Thanks again Ralph. That is indeed what I am doing now. One of my concerns was speed, but I have primarily worked in EL and ESPL where functions act like bottlenecks. That may not be true in Ninja. If speed is typically no different between user-written and native NinjaScript methods, then you are quite right -- no need to spend further effort on this thread. I'll write my own method (or just write the loops inline).

              Thanks again for your help...

              Best wishes,

              Light

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by trilliantrader, Today, 08:16 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by bill2023, Yesterday, 08:51 AM
              3 responses
              20 views
              0 likes
              Last Post bltdavid  
              Started by yertle, Today, 08:38 AM
              0 responses
              4 views
              0 likes
              Last Post yertle
              by yertle
               
              Started by Mestor, 03-10-2023, 01:50 AM
              15 responses
              379 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by samish18, Yesterday, 08:57 AM
              10 responses
              28 views
              0 likes
              Last Post samish18  
              Working...
              X