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

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 AnnBarnes, Today, 12:17 PM
      1 response
      2 views
      0 likes
      Last Post NinjaTrader_Zachary  
      Started by Lopat, 03-05-2023, 01:19 PM
      4 responses
      167 views
      0 likes
      Last Post Sam2515
      by Sam2515
       
      Started by f.saeidi, Today, 12:14 PM
      0 responses
      3 views
      0 likes
      Last Post f.saeidi  
      Started by giulyko00, Today, 12:03 PM
      0 responses
      4 views
      0 likes
      Last Post giulyko00  
      Started by AttiM, 02-14-2024, 05:20 PM
      12 responses
      213 views
      0 likes
      Last Post DrakeiJosh  
      Working...
      X