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

Getting Highs of a series of Bars

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

    Getting Highs of a series of Bars

    Hello All-

    I want to put a piece of code into my strategy that check to see if the High of a series of bars is under a certain price.

    The strategy looks for a 3 bar bearish candle pattern that I have defined, then looks for a similar 3 bar bullish candle pattern. In between these 3 bar patterns I have it coded to be a maximum of 8 candlesticks. If there are 1-8 candles between the two patterns it draws a rectangle around all of the candles.

    Now what I want to do is make sure that the potentially up to 8 candles in-between the two 3-bar candle patterns do not exceed a maximum price.

    The problem I am having is that some of the time there are 8 candles in between, but sometimes there are 3 or 4 or any number 1-8.

    What would the code look like to check the highs of those in between candles given that the number of candles I am looking at can vary?

    Thank you,

    Nick

    #2
    Hi Nick, thanks for posting. You need to make sure to save the CurrentBar value at each 3 bar pattern occurrence, then you can use the MAX method to find the max number between those two points. e.g. MAX(int period)[int barsAgo], use this method on the same bar you find the second pattern, then use the SavedCurrentBar - CurrentBar difference value for the period, and barsAgo will be 0 since you are running MAX on the same bar that you found the second pattern.

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Chris-

      Thank you for the response. I keep get the error message "Value of property 'Period' of Ninjascript MAX is -1 and not in valid range between 1 and 2147483647.

      The code I wrote is
      Code:
          BetweenHigh = MAX(High, BarsBetween)[4];
      Where BarsBetween is defined as
      Code:
          BarsBetween = RedCurrent - 3;
      and RedCurrent is the saved CurrentBar when the first pattern appears.

      I have use bars ago of 4 in the MAX code because I want to get the highs of the bars between the two 3 bar candlestick patterns.

      Any thoughts?

      Thank you,

      Nick

      Comment


        #4
        Hi Nick, thanks for the follow up. It means the calcuation of RedCurrent - 3 is less than 1 at some point. If you are deriving this number from a CurrentBar value, make sure to allow for enough bars to generate at the beginning of the chart to avoid this, or check that BarsBetween is not < 1 before using it by returning from OnBarUpdate.

        if(CurrentBar < 10) //allow 10 bars to generate
        return;
        or
        BarsBetween = RedCurrent - 3;
        if(BetweenBars < 1)
        return;
        else
        {
        //continue
        }

        Kind regards,
        -ChrisL

        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by StockTrader88, 03-06-2021, 08:58 AM
        45 responses
        3,992 views
        3 likes
        Last Post johntraderuser2  
        Started by TAJTrades, Today, 09:46 AM
        0 responses
        7 views
        0 likes
        Last Post TAJTrades  
        Started by rhyminkevin, Yesterday, 04:58 PM
        5 responses
        62 views
        0 likes
        Last Post dp8282
        by dp8282
         
        Started by realblubb, Today, 09:28 AM
        0 responses
        8 views
        0 likes
        Last Post realblubb  
        Started by AaronKoRn, Yesterday, 09:49 PM
        1 response
        19 views
        0 likes
        Last Post Rikazkhan007  
        Working...
        X