Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IF Condition not working?

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

    IF Condition not working?

    Hello,

    I am testing a strategy that uses Keltner Channels. The summary of this strategy is that, when the price is equal to the midline of the Keltner Channel, the action will be to place a buy order around the lower channel. For some reason, I cannot get the IF condition to trigger the action.

    My logic is currently this: "GetCurrentAsk(Default input) = KeltnerChannel(Open, 1, 10).Midline[0]"

    This is stating that when the Current Ask Price is equal to the Midline of the Keltner channel, the action will get triggered (Buy Order by the Lower Channel should be placed)

    The Action statement works by itself, but with the IF condition, it will not place the order ever even though this scenario happens many times a day.

    Any thoughts? Thanks!

    #2
    Hello tradingbobby,
    Try below code:-
    Code:
    if (BarsInProgress != 0)
    return;
    
    if (CurrentBars[0] < 1)
    return;
    
    // Set 1
    if (GetCurrentAsk(0) == KeltnerChannel1.Midline[0])
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }
    You can use Strategy Builder & get it working.

    Comment


      #3
      Hello tradingbobby,

      Thanks for your post and welcome to the NinjaTrader forums!

      The test for equality may fail because you are comparing a price level against a calculated value (for the Keltner line) For example, while the price might be 1304.25 the midline might be at 1304.250001 and these would not be equal values. You could add a print statement to print out both the price value and the value of the midline to verify if this is the case.

      You could instead test to see if price has crossed above or crossed below the Midline.

      You could instead test to see if the ask is >= (greater or equal) or <= (less than or equal) to the midline.

      You could instead round the Midline price to match the price using C#..Net Math.Round(). Please see https://docs.microsoft.com/en-us/dot...ew=netcore-3.1
      Paul H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by aslane, Today, 02:50 AM
      0 responses
      3 views
      0 likes
      Last Post aslane
      by aslane
       
      Started by fx.practic, Today, 02:07 AM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Marco  
      Started by Ousher, Today, 01:29 AM
      0 responses
      8 views
      0 likes
      Last Post Ousher
      by Ousher
       
      Started by tonynt, Today, 01:23 AM
      0 responses
      4 views
      0 likes
      Last Post tonynt
      by tonynt
       
      Started by cmarkb, Today, 01:18 AM
      1 response
      11 views
      0 likes
      Last Post cmarkb
      by cmarkb
       
      Working...
      X