Announcement

Collapse
No announcement yet.

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 localappleseed, Yesterday, 03:19 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by westofpluto, Yesterday, 03:07 PM
          2 responses
          21 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by localappleseed, Yesterday, 02:12 PM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by MojoJojo, Yesterday, 12:21 PM
          3 responses
          12 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Jschmelz, Yesterday, 11:40 AM
          5 responses
          26 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X