Announcement

Collapse
No announcement yet.

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

    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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        62 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        134 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        75 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X