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

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 zstheorist, Today, 07:52 PM
        0 responses
        7 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        150 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Started by mattbsea, Today, 05:44 PM
        0 responses
        6 views
        0 likes
        Last Post mattbsea  
        Started by RideMe, 04-07-2024, 04:54 PM
        6 responses
        33 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Started by tkaboris, Today, 05:13 PM
        0 responses
        6 views
        0 likes
        Last Post tkaboris  
        Working...
        X