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

If statements and bool variable

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

    If statements and bool variable

    I am new to C# and am learning by working my way through strategies found in the Ninjascripts library. I'm having trouble understanding the logic in one particular section of the PZO Strategy.
    Code:
    //UpTrendRules
    			if (Close[0] > EMA(EMAPeriod)[0] &&	ADX(ADXPeriod)[0] > 18)
    			{
    				if (CrossAbove(PriceZoneOscillator(PZOPeriod), -40, 1))
    					EnterLong("Buy1");
    				
    				if (CrossAbove(PriceZoneOscillator(PZOPeriod), 0, 1))
    					B2_SU = true;
    				
    				if (B2_SU && CrossAbove(PriceZoneOscillator(PZOPeriod), 15, 1))
    				{
    					EnterLong("Buy2");
    				}				
    			}
    The "B2_SU" variable is a bool variable that is by default false. As you can see above if it crosses above 0 in the last bar it is true. My issue is I don't understand the next line. "If B2_SU... and PZO crosses above 15 then enter long." If B2_SU what? There's no action there. I could understand if it said if B2_SU equals true and ...

    Is there an inherent code in an if statement with bool variables that I haven't learned yet? Please translate if you could be so kind.

    Thanks!
    Brian

    #2
    Originally posted by BReal View Post
    I am new to C# and am learning by working my way through strategies found in the Ninjascripts library. I'm having trouble understanding the logic in one particular section of the PZO Strategy.
    Code:
    //UpTrendRules
    			if (Close[0] > EMA(EMAPeriod)[0] &&	ADX(ADXPeriod)[0] > 18)
    			{
    				if (CrossAbove(PriceZoneOscillator(PZOPeriod), -40, 1))
    					EnterLong("Buy1");
    				
    				if (CrossAbove(PriceZoneOscillator(PZOPeriod), 0, 1))
    					B2_SU = true;
    				
    				if (B2_SU && CrossAbove(PriceZoneOscillator(PZOPeriod), 15, 1))
    				{
    					EnterLong("Buy2");
    				}				
    			}
    The "B2_SU" variable is a bool variable that is by default false. As you can see above if it crosses above 0 in the last bar it is true. My issue is I don't understand the next line. "If B2_SU... and PZO crosses above 15 then enter long." If B2_SU what? There's no action there. I could understand if it said if B2_SU equals true and ...

    Is there an inherent code in an if statement with bool variables that I haven't learned yet? Please translate if you could be so kind.

    Thanks!
    Brian
    You are correct. It is a short way of saying if (B2_SU == true && ....)
    You will gradually find this natural later on, especially if the variable name is self explaining. For example:

    if (RSI_Overbought && ... ) EnterShort();
    Cheers.
    Pi
    ninZa
    NinjaTrader Ecosystem Vendor - ninZa.co

    Comment


      #3
      Hello Brian,

      Pi is correct. You can call the bools in such a manner, for example equals false can be !B2_SU.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Jessejames1964, Today, 01:56 PM
      2 responses
      8 views
      0 likes
      Last Post Jessejames1964  
      Started by zstheorist, 04-26-2024, 07:52 PM
      4 responses
      36 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by Board game geek, 11-02-2023, 04:05 AM
      4 responses
      964 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by bill2023, Today, 01:14 PM
      3 responses
      12 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by artson, Today, 12:25 PM
      4 responses
      13 views
      0 likes
      Last Post artson
      by artson
       
      Working...
      X