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

GETDAYBAR and MAX

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

    GETDAYBAR and MAX

    On a mulit-time frame, is there are more elegant way of getting the Highest high in the last three days using GETDAYBAR and MAX other than getting each day one at a time and comparing each of them as in
    If A > B then biggest = A Else biggest = B
    If C > biggest then biggest = C

    #2
    Kentoes, I would not have a performance comparison unfortunately available but you could also store the highest High value seen as your OnBarUpdate() progresses through the bars.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Max()

      For your multi-timeframe strategy, you could use this MAX() overload...

      Code:
       
      MAX(IDataSeries input, int period)[int barsAgo]
      With..

      - DataSeries input = daily, assuming your multi-timeframe strategy uses a daily IDataSeries, otherwise number of bars in trading session.
      - period = 3, for daily dataseries
      - barsAgo = 1, assuming not considering current day's trading data.

      Comment


        #4
        Originally posted by borland View Post
        For your multi-timeframe strategy, you could use this MAX() overload...

        Code:
         
        MAX(IDataSeries input, int period)[int barsAgo]
        With..

        - DataSeries input = daily, assuming your multi-timeframe strategy uses a daily IDataSeries, otherwise number of bars in trading session.
        - period = 3, for daily dataseries
        - barsAgo = 1, assuming not considering current day's trading data.
        This may work. If I also wanted to capture the Highest Close from the past 3 days, how would that be possible?

        Comment


          #5
          Same overload, but instead of using BarsArray[1] for IDataSeries input, use Highs[] ..

          Code:
           
          MAX( Highs[1], 3) [1]
          where [1] is the barSeriesIndex for your daily.

          Comment


            #6
            You did say highest close. Sorry, that was a inefficient use of data filtering. Instead, replace Highs[1] in the above post with

            Code:
             
            Closes[1]

            Comment


              #7
              So if I am using minute data and there are 405 minutes in a session, to get the highest high in the last 3 days, not including today would be?

              Comment


                #8
                Highest high would be such as borlands first example on a 1440 minute data series, which would give you a 24 hour period.

                Code:
                MAX( Highs[1], 3) [1]
                MatthewNinjaTrader Product Management

                Comment


                  #9
                  I'm getting "Index was outside the bounds of the array." error when running:
                  Code:
                   protected override void OnBarUpdate()
                          {
                              if (CurrentBars[0] < 0 || CurrentBars[1] < 0) return; 
                              double yValue = MAX(Closes[1],Days)[1] - MIN(Lows[1],Days)[1];
                  }
                  Days is a variable set to 3.

                  Comment


                    #10
                    You need to add the daily bars timeseries in your Initialize() method using the Ninjascript method Add() which also assigns the index (e.g., index = 1).

                    You should change your variable "Days" to "days" or "_Days" so as to avoid confusion with .NET "Days" property. User variables should start with lower case characters.
                    Last edited by borland; 05-05-2012, 07:52 PM.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by cre8able, Today, 06:18 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post cre8able  
                    Started by ETFVoyageur, Today, 06:05 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post ETFVoyageur  
                    Started by TAJTrades, 04-28-2024, 09:46 AM
                    2 responses
                    17 views
                    0 likes
                    Last Post TAJTrades  
                    Started by ETFVoyageur, Today, 02:04 PM
                    2 responses
                    19 views
                    0 likes
                    Last Post ETFVoyageur  
                    Started by mjbatts91, Today, 04:48 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post mjbatts91  
                    Working...
                    X