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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      67 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      36 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      59 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      62 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      53 views
      0 likes
      Last Post CarlTrading  
      Working...
      X