Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Closest candles with same high

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

    Closest candles with same high

    Hi,

    I was wondering if anyone had any idea on the easiest way I could look back and find the closest 3 candles with the same high.

    Thanks!

    #2
    Hello clubfoot,

    To confirm, you are not looking for the last 3 highest bars, you are looking for the last 3 bars with the same high as the current bar's high, is this correct?

    You could use a loop that loops back from the current bar and compares the current bars high to the looped bars high.

    for (int i = 0; i < CurrentBar-1; i++)
    {
    }

    This is basic loop that would loop through all of the bars. In this loop you could add an if statement that compares the High[0] to the High[i] (where i is the looped bar increment from the for statement). If it is, save that bar number. Do this until you have 3 bar numbers saved and then break the loop.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hey Chelsea,

      So it would be not using the current bar at all, it would look back to find the closest 3 matching highest bars, let's say in the last 100 bars that all had the same high. They could be spaced out like the first bar is 25 away and the next is 50 bars away and the 3rd is 75 bars away, but all had the same matching high.


      It needs to loop through each bar going back, looking for 2 candles that match that high. If it is found, store the bar number for the last in the matches. Then continue looping back each bar until you hit that number, looking for any closer matches. Any match you find, shortens how much farther back you’d need to look.
      Last edited by clubfoot; 12-21-2016, 10:39 AM.

      Comment


        #4
        Hello clubfoot,

        You want to find the most recent 3 bars with the same high?

        You would still loop backwards but your if statement would need more complicated logic.
        On every bar, you would need to loop backwards and compare the highs and find the 3 most recent highs. This would give you 3 values for every bar. Once you have 3 values for every bar, you would need to see which bar has the lowest 3 values which will require another loop. This would be cpu intensive. I would suggest limiting the number of bars back that you look through.

        In the support department at NinjaTrader we do not create, debug, or modify code for our clients. This is so that we can maintain a high level of service for all of our clients as well as our partners.

        This thread will remain open for any community members that would like to create this logic for you.

        You can also contact one of our professional NinjaScript Consultants who would be eager to create or modify this script at your request or assist you with your script. Please let me know if you would like our business development follow up with you with a list of professional NinjaScript Consultants who would be happy to create this script or any others at your request.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X