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

Else If Exit Conditions

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

    Else If Exit Conditions

    Hello,

    Is it possible to create 2 exit conditions with an esle if statement within NT8?

    For example, I want the trades to exit on the first exit statement. But IF the second exit statement happens before the first exit statement; exit on the second statement. I hope im explaining this correctly. Also if this is the appopriate way to do this, is there a way to complete this in strategy builder or manually coding is the only option for an else if statement.

    if (CrossBelow(DEMA1, SMA1, 1))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "", @"enterLong1");
    }

    If (CrossAbove(DEMA1, SMA1,1))
    {
    ExitLong(Convert.ToInt32(DefaultQuantity), "", @"enterLong1");
    }
    else if (CrossAbove(DEMA2,SMA2,1))
    {
    ExitLong​(Convert.ToInt32(DefaultQuantity), "", @"enterLong1");​

    #2
    Hello amigatlin,

    An 'else if' branching command would have to manually coded. In the Strategy Builder, these would be separate conditions, that are mutually exclusive (meaning one can't be true if the other is true.

    However, you can nest if statements in C#.

    Below is a link to a tutorial from a google search of 'C# nested if'.
    C# - Nested if Statements - It is always legal in C# to nest if-else statements, which means you can use one if or else if statement inside another if or else if statement(s).



    Currently, the code you have suggested is not nested.

    Code:
    if (/* outer condition that must be true for both inner conditions */)
    {
    
        if (/* first inner connection */)
        {
            // 
        }
    
        else if (/* second inner condition only evaluated if the first inner condition is not true */)
       {
          //
       }
    }
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by llanqui, Today, 03:53 AM
    0 responses
    2 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    10 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    14 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Yesterday, 08:42 PM
    0 responses
    11 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Yesterday, 07:51 PM
    0 responses
    14 views
    0 likes
    Last Post strategist007  
    Working...
    X