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 NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X