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

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
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by futtrader, 04-21-2024, 01:50 AM
    5 responses
    56 views
    0 likes
    Last Post NinjaTrader_Eduardo  
    Started by PeakTry, Today, 10:49 AM
    0 responses
    2 views
    0 likes
    Last Post PeakTry
    by PeakTry
     
    Started by llanqui, Today, 10:32 AM
    0 responses
    5 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by StockTrader88, 03-06-2021, 08:58 AM
    45 responses
    3,992 views
    3 likes
    Last Post johntraderuser2  
    Started by TAJTrades, Today, 09:46 AM
    0 responses
    8 views
    0 likes
    Last Post TAJTrades  
    Working...
    X