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

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
    }
    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 Barry Milan, Yesterday, 10:35 PM
        5 responses
        16 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by DanielSanMartin, Yesterday, 02:37 PM
        2 responses
        13 views
        0 likes
        Last Post DanielSanMartin  
        Started by DJ888, 04-16-2024, 06:09 PM
        4 responses
        13 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by terofs, Today, 04:18 PM
        0 responses
        12 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by nandhumca, Today, 03:41 PM
        0 responses
        8 views
        0 likes
        Last Post nandhumca  
        Working...
        X