Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue with "OR"

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

    Issue with "OR"

    Hello,

    I have two separate conditions in my strategy for triggering a signal.
    When I use Condition 1 in my code it works well, the same goes for Condition 2.
    Now, I'd like to use the OR function to obtain the following.


    if (Condition 1 == true || Condition 2 == true)
    {
    LongSignal = true;
    }
    else
    {
    LongSignal= false;
    }

    The prolem is, as soon as I use "||" it doesn't work anymore.
    Is this the right syntax for using "OR"?
    The signal is valid if EITHER ONE of the conditions is met.

    Thanks.

    #2
    Hello laocoon,

    Thanks for your post.

    Yes, that is the correct use of OR ( || ). This could be seen by setting up conditions in the Strategy Wizard and clicking the 'View code' button to see the generated code.

    The if-else syntax that checks is Condition1 is true OR Condition2 is true would look something like this.

    Code:
    if ((Condition1 == true)
    || (Condition2 == true))
    {
      //do something.
    }
    else
    {
      //do something.
    }
    Ultimately, to understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    Please let me know if I may further assist
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    546 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X