Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Entry Conditions - Is this the correct way.

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

    Order Entry Conditions - Is this the correct way.

    Good afternoon,

    I am learning to write my strategy ideas but need some guidance. I have a set of conditions that all must be met for a trade to be placed but I am not getting the desired result. Please can you explain the correct way to code the conditions.

    In my strategy I have the following conditions to be met before the order is placed: Here are the conditions in order

    1) strxav2 == "UT" && strxav1 == "UT" // Called from indicator
    2) strsignal == "MACD Cross UP" // Called from an indicator
    3) ADX(14)[0] > ADXlong // Set at 20 //
    4) Close[0] > SMA(36)[0] // Price is above the SMA

    So I require all 4 to match to enter an order I have this as follows:

    if (strxav2 == "UT" && strxav1 == "UT" && strsignal == "MACD Cross UP" && ADX(14)[0] > ADXlong && Close[0] > SMA(36)[0])
    //if (Position.MarketPosition == MarketPosition.Flat)

    {
    Print("-----------RGAuto:" + strsignal);
    Print("signal:" + strsignal + " XAV1:" + strxav1 + " Xav2:" + strxav2);

    {
    int n = 0;
    EnterLong(lots, "UT+UT");
    //EnterLongStopLimit(0, true, 1, High[0] + 4 * TickSize, High[0] + 4 * TickSize, "UT+UT");
    RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Ninja Trader7\MyScalper");
    key.SetValue("signalname", "UT+UT.Long");
    key.Close();

    }


    }

    Now when I run the strategy, the results are sporadic. it seems to adhere to separate conditions on separate occasions rather than meeting all to enter the trade.

    Can you please explain how to code this to meet all conditions before trade entry.

    Thank you


    #2
    Hello Gille1983,

    As far as I can tell all 4 conditions are in the if statement.

    Are you using prints outside of the condition set to see what the values of these are when the condition is evaluating as true at an unexpected time?

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.


    What is the time of the bar, what is the value of strxav2, what is the value of strxav1, what is the value of strsignal, what is the value of ADX(14)[0], what is the value of ADXlong, what is the value of Close[0], what is the value of SMA(36)[0]?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      would this be correct ?

      if (strxav2 == "UT" && strxav1 == "UT")
      {
      Print("Condition 1");
      }
      if (strsignal == "MACD Cross UP");
      {
      Print("Condition 2");
      }
      if (ADX(14)[0] > ADXlong);
      {
      Print("Condition 3");
      }
      if (Close[0] > SMA(36)[0])
      {
      Print("Condition 4");
      }

      Comment


        #4
        Hello Gille1983,

        Take a look at the videos in the post I have linked.

        I recommend:

        Print(string.Format("{0} | strxav2: {1} == UT && strxav1: {2} == UT && strsignal: {3} == MACD Cross UP && ADX(14)[0]: {4} > ADXlong: {5} && Close[0]: {6} > SMA(36)[0]: {7}", Time[0], strxav2, strxav1, strsignal, ADX(14)[0], ADXlong, Close[0], SMA(36)[0]));
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chelsea, Ill have a look through and get to grips with it, thank you so much for your help as always

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          553 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          100 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          543 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          546 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X