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

Swing High and Swing Low Buying Condition Code

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

    Swing High and Swing Low Buying Condition Code

    Hey,

    I'm coding a strategy and one of the conditions I want to be met is that I have a kind of Swing High before shorting or a kind of Swing Low before buying.

    For example, two red bars required before placing the trade to short, or two green bars required before placing the trade to buy.

    What is the code I should use for this?

    Any help would be greatly appreciated!

    Kind regards,
    Stephen

    #2
    Hello Stephen Trading,

    Thanks for the post.

    I believe in this case you are describing a rising or falling trend, or where the price is greater than the previous for a number of bars or less for a number of bars.

    If that is what you wanted you could do that in two ways. For single or 1 bars ago periods you can use the IsRising or IsFalling
    https://ninjatrader.com/support/help...tsub=IsFalling

    For more than 1 BarsAgo you could just use the BarsAgo and price series. For example

    Code:
    Close[0] > Close[1] && Close[1] > Close[2]
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hey,

      Thank you for getting back to me!

      This is a great idea!

      I previously had just this as my code:

      Close[0] > Close[1]

      Didn't think about adding a separate condition in order to get another.

      Thank you,
      Stephen

      Comment


        #4
        Hey,

        There is a slight problem when I change the code to:

        (Close[0] < Close[1]) ; The strategy then doesn't make any trades

        I previously had it at:

        (Close[0] < Close[2]) ; In which case it does make trades

        I tested and isolated this to be the problem, why is that? And is it possible to fix it?

        Kind regards,
        Stephen

        Comment


          #5
          Hello Stephen Trading,

          From the given samples there is not really a discernible difference there besides the BarsAgo. Can you try Printing the values to see if its just that the condition is never true based on the values seen?

          Code:
          Print(Close[0] + " < " + Close[1]); 
          (Close[0] < Close[1]) ;
          One item I do see here is that you have a semi colon after the condition, if that's how it actually is in your code that's likely part of the problem. if conditions don't have any semicolons used:

          Code:
          if(condition)
          { 
          
          }

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Haiasi, Today, 06:53 PM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by ScottWalsh, Today, 06:52 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by ScottW, Today, 06:09 PM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by ftsc2022, 10-25-2022, 12:03 PM
          5 responses
          256 views
          0 likes
          Last Post KeyonMatthews  
          Started by Board game geek, 10-29-2023, 12:00 PM
          14 responses
          244 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Working...
          X