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 DannyP96, 05-18-2026, 02:38 PM
      1 response
      27 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      117 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      69 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      226 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      417 views
      0 likes
      Last Post CaptainJack  
      Working...
      X