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 Logic.

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

    Order Entry Logic.

    I have three conditions that have to be met before I enter a position. I initially had the conditions as follows:

    if (strxav2 == "DT" && strxav1 == "DT")
    if (strsingle == "MACD Cross DOWN")
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    Print("-----------RGAuto:" + strsingle);
    Print("single:" + strsingle + " XAV1:" + strxav1 + " Xav2:" + strxav2);

    {
    int m = 0;
    EnterShortStopLimit(0, true, 1, High[0] - 10 * TickSize, High[0] - 10 * TickSize, "DT+DT");//
    RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Ninja Trader7\MyScalper");
    key.SetValue("Signalname", "DT+DT.Short");
    key.Close();
    }
    }


    But I found that only this condition was being adhered to and an order placed "if (strxav2 == "DT" && strxav1 == "DT")" it failed to catch the other two.

    Is it possible that this will work;

    if (strxav2 == "UT" && strxav1 == "UT") eventTotal++;
    if (strsingle == "MACD Cross UP") eventTotal++;
    if (Position.MarketPosition == MarketPosition.Flat) eventTotal++;

    if (eventTotal == 3)
    {
    Print("-----------RGAuto:" + strsingle);
    Print("single:" + strsingle + " XAV1:" + strxav1 + " Xav2:" + strxav2);

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


    Do I need to place anything in protected override void Initialize() ?

    #2
    Hi Gille1983, thanks for your question.

    The group of IF statements in incorrect. To group boolean conditions together you must use the && or || operators.

    See here for a guide on using these:

    C# logical operators perform logical negation (`!`), conjunction (AND - `&`, `&&`), and inclusive and exclusive disjunction (OR - `|`, `||`, `^`) operations with Boolean operands.




    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by funk10101, Today, 09:43 PM
    0 responses
    6 views
    0 likes
    Last Post funk10101  
    Started by pkefal, 04-11-2024, 07:39 AM
    11 responses
    37 views
    0 likes
    Last Post jeronymite  
    Started by bill2023, Yesterday, 08:51 AM
    8 responses
    44 views
    0 likes
    Last Post bill2023  
    Started by yertle, Today, 08:38 AM
    6 responses
    26 views
    0 likes
    Last Post ryjoga
    by ryjoga
     
    Started by algospoke, Yesterday, 06:40 PM
    2 responses
    24 views
    0 likes
    Last Post algospoke  
    Working...
    X