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 lightsun47, Today, 03:51 PM
    0 responses
    5 views
    0 likes
    Last Post lightsun47  
    Started by 00nevest, Today, 02:27 PM
    1 response
    10 views
    0 likes
    Last Post 00nevest  
    Started by futtrader, 04-21-2024, 01:50 AM
    4 responses
    46 views
    0 likes
    Last Post futtrader  
    Started by Option Whisperer, Today, 09:55 AM
    1 response
    14 views
    0 likes
    Last Post bltdavid  
    Started by port119, Today, 02:43 PM
    0 responses
    10 views
    0 likes
    Last Post port119
    by port119
     
    Working...
    X