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 blar58, Today, 01:21 PM
        0 responses
        1 view
        0 likes
        Last Post blar58
        by blar58
         
        Started by tonynt, Today, 01:21 PM
        0 responses
        5 views
        0 likes
        Last Post tonynt
        by tonynt
         
        Started by Byron22, Today, 12:19 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_PaulG  
        Started by Trader17, Today, 12:25 PM
        2 responses
        8 views
        0 likes
        Last Post Trader17  
        Started by focus333, Today, 10:48 AM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_Kate  
        Working...
        X