Announcement

Collapse
No announcement yet.

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'.
    The nested if in c# is an if statement that is the target of another if statement. A nested if statement specifies an if or if-else statement inside the other if statement.



    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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    55 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    132 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X