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 futtrader, 04-21-2024, 01:50 AM
    4 responses
    41 views
    0 likes
    Last Post futtrader  
    Started by Option Whisperer, Today, 09:55 AM
    1 response
    12 views
    0 likes
    Last Post bltdavid  
    Started by port119, Today, 02:43 PM
    0 responses
    8 views
    0 likes
    Last Post port119
    by port119
     
    Started by Philippe56140, Today, 02:35 PM
    0 responses
    7 views
    0 likes
    Last Post Philippe56140  
    Started by 00nevest, Today, 02:27 PM
    0 responses
    7 views
    0 likes
    Last Post 00nevest  
    Working...
    X