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, 07: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
    }
    Paul H.NinjaTrader Customer Service

    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.

        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by swcooke, Today, 07:17 PM
        0 responses
        6 views
        0 likes
        Last Post swcooke
        by swcooke
         
        Started by aguison, Today, 04:20 PM
        0 responses
        11 views
        0 likes
        Last Post aguison
        by aguison
         
        Started by timko, Today, 04:11 PM
        0 responses
        6 views
        0 likes
        Last Post timko
        by timko
         
        Started by djkiwi, Today, 03:25 PM
        2 responses
        12 views
        0 likes
        Last Post djkiwi
        by djkiwi
         
        Started by hdge4u, Today, 12:29 PM
        1 response
        21 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X