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

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 sidlercom80, 10-28-2023, 08:49 AM
          172 responses
          2,279 views
          0 likes
          Last Post sidlercom80  
          Started by Irukandji, Yesterday, 02:53 AM
          2 responses
          17 views
          0 likes
          Last Post Irukandji  
          Started by adeelshahzad, Today, 03:54 AM
          0 responses
          4 views
          0 likes
          Last Post adeelshahzad  
          Started by Barry Milan, Yesterday, 10:35 PM
          3 responses
          13 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by WeyldFalcon, 12-10-2020, 06:48 PM
          14 responses
          1,430 views
          0 likes
          Last Post Handclap0241  
          Working...
          X