Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Buy If Close higher than previous highest bar

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

    Buy If Close higher than previous highest bar

    I'm trying to write out a strategy where I will buy if the current bar closes above the Highest High of a green bar (Open < Close) in the previous 20 bars.


    Any help or suggestions?

    Thanks!
    Last edited by Ousher; 07-21-2020, 08:14 PM.

    #2
    Hello Ousher,

    Thanks for your post and welcome to the NinjaTrader forums!

    If I understand correctly you want to buy if the current bar is green and closes above the previous 20 bar high.

    A bar is green if the Close[0] is greater than the Open[0]

    You can get the Highest high value of the previous 20 bars by using the MAX() indicator set to the High data series, starting at the previous bar with a look-back of 20, something like MAX(High, 20)[1]. Reference: https://ninjatrader.com/support/help...aximum_max.htm

    Putting it together would be:

    if (Close[0] > Open[0] && Close[0] > MAX(High, 20)[1])
    {
    // entry order here
    }

    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello Ousher,

      Thanks for your post and welcome to the NinjaTrader forums!

      If I understand correctly you want to buy if the current bar is green and closes above the previous 20 bar high.

      A bar is green if the Close[0] is greater than the Open[0]

      You can get the Highest high value of the previous 20 bars by using the MAX() indicator set to the High data series, starting at the previous bar with a look-back of 20, something like MAX(High, 20)[1]. Reference: https://ninjatrader.com/support/help...aximum_max.htm

      Putting it together would be:

      if (Close[0] > Open[0] && Close[0] > MAX(High, 20)[1])
      {
      // entry order here
      }
      Hi Paul, thanks for the response.

      Thats basically it but with one little twist. The High of the previous 20 bars HAS to be Green as well.

      So if we're in a downtrend and all the previous 20 bars are red, then we wont do anything.

      Comment


        #4
        Hello Ousher,

        Thanks for your reply.

        We do have a HighestBar() but that would include the current bar so it would not work for you. I would suggest running a for loop and checking for the highest high and as found save the high value in a variable and save the bars ago in a variable. With the bars ago you can then check the Close to Open of that bar.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        90 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        135 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        119 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        69 views
        0 likes
        Last Post PaulMohn  
        Working...
        X