Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Logical OR

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

    Logical OR

    The Strategy Wizard creates logical AND conditions.

    I want to have a script with a logical OR. And, I don't know how to do it.

    Let me give you my condition from a layman, mathematical prospective. Then, I will paste what the Strategy Wizard created as logical ANDs.

    Layman, mathematical definition:

    If (Fast SMA crosses above Slow SMA) OR
    (Close > Fast SMA AND Close > Slow SMA)
    Enter Long

    This is what the Strategy Wizard created:

    {
    // Condition set 1
    if (CrossAbove(SMA(FastMA), SMA(SlowMA), 1)
    && Close[0] > SMA(FastMA)[0]
    && Close[0] > SMA(SlowMA)[0])
    {
    EnterLong(OrderQty, "");
    }

    // Condition set 2
    if (CrossBelow(SMA(FastMA), SMA(SlowMA), 1))
    {
    ExitLong("", "");
    }
    }


    Thanks

    #2
    StarBright2009,

    Good question!!!

    "OR" in C# is defined by using "pipes" OR = || .

    EX.

    if ((condition10 || condition20) == true)


    You can read up about it here.

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


    Hope this helps,

    RJay
    RJay
    NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

    Comment


      #3
      Thank you very much.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CaptainJack, 05-29-2026, 05:09 AM
      0 responses
      305 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 05-29-2026, 12:02 AM
      0 responses
      196 views
      0 likes
      Last Post CaptainJack  
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      186 views
      1 like
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      274 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      228 views
      0 likes
      Last Post CarlTrading  
      Working...
      X