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

Programing an opening range

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

    Programing an opening range

    I was hoping someone could give me some pointers on programing an opening range.

    I think I need to use the variable function to set the high of X time period and low of X time period as the opening range and then use these variables to enter an exit positions when price behaves a certain way around them.

    I am just having a hard time working out how I can do this with the wizard as i'm not comfortable yet writing code - although i'm learning!

    Thanks very much in advance.

    Mark

    #2
    I'm not sure what you mean by 'open range'? But, I think your referring to the Highest High and the Lowest Low of a look back period. You might also call this a Price Channel on the look back period.

    I've been interested in this too. I looked in the user's guide for a NinjaTrader indicator method and could not find one.

    To roll your own, you could use Highs[] and Lows[] methods like NT shows in this code example.., except you would Add[] enough minutes to cover the look back period.

    Code:
    [FONT=Courier New][COLOR=#0000ff]protected override[/COLOR] [COLOR=#0000ff]void[/COLOR] Initialize()[/FONT] 
    [FONT=Courier New]{[/FONT] 
    [FONT=Courier New]    [COLOR=#008000]// Adds a 5-minute Bars object to the strategy and is automatically assigned[/COLOR][/FONT] 
    [FONT=Courier New][COLOR=#008000]    // a Bars object index of 1 since the primary data the strategy is run against[/COLOR][/FONT] 
    [FONT=Courier New][COLOR=#008000]    // set by the UI takes the index of 0.[/COLOR][/FONT] 
    [FONT=Courier New]    Add(Instrument, PeriodType.Minute, 5);[/FONT][FONT=Courier New][COLOR=#008000]                                       
    [/COLOR]}[/FONT] 
    
    [FONT=Courier New][COLOR=#0000ff]protected override[/COLOR] [COLOR=#0000ff]void[/COLOR] OnBarUpdate()[/FONT] 
    [FONT=Courier New]{[/FONT] 
    [FONT=Courier New]    [COLOR=#008000]// Compares the primary bar's low price to the 5-minute bar's low price[/COLOR][/FONT] 
    [FONT=Courier New]    [COLOR=#0000ff]if[/COLOR] (Low[0][0] > Lows[1][0])[/FONT] 
    [FONT=Courier New]        Print("The current bar's low price is greater");[/FONT] 
    [FONT=Courier New]}[/FONT]
    Maybe there's an easier way.

    Comment


      #3
      There is an easier way.

      if you do a seach for opening range there are examples.

      Comment


        #4
        I did a search of the forum on "open range".... That sounds like Price Gaps, so not what your wanting to discuss. Sorry

        There is also the methods: HighestBar[] and LowestBar[], but these only report back the offset index of the look back period, not price.

        For a 20 period lookback, these should work...

        PriceRangeChannel_Upper = High[HighestBar(High,20)]

        PriceRangeChannel_Lower = Low[LowestBar(Low,20)]

        PriceRangeChannel_Mid = (High[HighestBar(High,20)] - Low[LowestBar(Low,20)])/2
        Last edited by borland; 02-07-2010, 01:12 PM.

        Comment


          #5
          MJUK05, please take a look at the reference sample titled calculating the highest high or lowest low for a certain time period.
          AustinNinjaTrader Customer Service

          Comment


            #6
            Originally posted by borland View Post
            I did a search of the forum on "open range".... That sounds like Price Gaps, so not what your wanting to discuss. Sorry

            There is also the methods: HighestBar[] and LowestBar[], but these only report back the offset index of the look back period, not price.

            For a 20 period lookback, these should work...

            PriceRangeChannel_Upper = High[HighestBar(High,20)]

            PriceRangeChannel_Lower = Low[LowestBar(Low,20)]

            PriceRangeChannel_Mid = (High[HighestBar(High,20)] - Low[LowestBar(Low,20)])/2

            Borland,

            Thanks. I used the following method:

            if (Bars.FirstBarOfSession)
            highestHigh = High[
            0];

            if (Bars.FirstBarOfSession)
            lowestlow = Low[
            0];

            if (Bars.BarsSinceSession < OR && High[0] > highestHigh)
            highestHigh = High[
            0];

            if (Bars.BarsSinceSession < OR && Low[0] < lowestlow)
            lowestlow = Low[
            0];

            OR = opening range is bars in opening range variable
            highestHigh and lowestlow are variables that are set by the statements and re-set at the start of a new session.

            Hope this is useful to you to.

            Austin. Thanks.

            Comment


              #7
              MJUK05,

              I still don't know what open range is, however Austin pointed out the possible use of Max() and Min (). So your code could also look like this.

              Code:
              if (Bars.FirstBarOfSession == true)
              {
                highestHigh = Max(High,10)[0];
                lowestLow = Min(Low,1)[0];
              }
              if ( Bars.BarsSinceSession == true
                   && openRange == false)
                   && Max(High,1)[0] > highestHigh )
              {
                highestHigh = Max(High,1)[0];
              }
              if ( Bars.BarsSinceSession == true
                   && openRange == false)
                   && Min(Low,1)[0] < lowestLow )
              {
                lowestLow = Min(Low,1)[0];
              }

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Waxavi, Today, 02:10 AM
              0 responses
              3 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Started by TradeForge, Today, 02:09 AM
              0 responses
              7 views
              0 likes
              Last Post TradeForge  
              Started by Waxavi, Today, 02:00 AM
              0 responses
              2 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Started by elirion, Today, 01:36 AM
              0 responses
              4 views
              0 likes
              Last Post elirion
              by elirion
               
              Started by gentlebenthebear, Today, 01:30 AM
              0 responses
              4 views
              0 likes
              Last Post gentlebenthebear  
              Working...
              X