NexusFi: Find Your Edge


Home Menu

 





Code Syntax question


Discussion in NinjaTrader

Updated
    1. trending_up 1,556 views
    2. thumb_up 1 thanks given
    3. group 1 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 
Zxeses's Avatar
 Zxeses 
San Francisco CA
 
Experience: Intermediate
Platform: Ninja
Broker: CQG
Trading: ES
Posts: 139 since Jun 2014
Thanks Given: 90
Thanks Received: 173

I was just editing some code in a strategy (and much thanks go out to the coders)

I've noticed a lot of what I'd call unnessesary grouping parens, would someone look at this code and let me know if I shouldn't rewrite this:

 
Code
		if ( 
			(Historical)&&
			 (
			 (Instrument.FullName == "$USDJPY") || 
			 ( Instrument.FullName=="$GBPJPY" ) || 
			 ( Instrument.FullName=="$EURJPY" ) || 
			 ( Instrument.FullName=="$AUDJPY" ) || 
			 ( Instrument.FullName=="$NZDJPY")
			 )
			)

to this...?

 
Code
		if ( Historical &&
			(
			Instrument.FullName == "$USDJPY" || 
			Instrument.FullName == "$GBPJPY" || 
			Instrument.FullName == "$EURJPY" || 
			Instrument.FullName == "$AUDJPY" || 
			Instrument.FullName == "$NZDJPY"
			)
		)
...

Taking my first stab at C# but some syntax rules seem obvious to me, just wanna make sure I'm not F'*kin this up by applying standard syntax.

-Zx


Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Irans Dual Probability: Guns Quiet at 99.95% While Forma …
Prediction Markets & Event Contracts
Warsh Rate Hike at 40%, Iran June 15 Expires Tonight at …
Prediction Markets & Event Contracts
Memorandum Watch: How the 60-Day MOU Framework Makes May …
Prediction Markets & Event Contracts
White House Drops First Alien Files Today -- Market Says …
Prediction Markets & Event Contracts
Weekend Update: First Qatari LNG Transit Attempted -- IR …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
13 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks
  #3 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,550 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,427



Zxeses View Post
I was just editing some code in a strategy (and much thanks go out to the coders)

I've noticed a lot of what I'd call unnessesary grouping parens, would someone look at this code and let me know if I shouldn't rewrite this:

 
Code
		if ( 
			(Historical)&&
			 (
			 (Instrument.FullName == "$USDJPY") || 
			 ( Instrument.FullName=="$GBPJPY" ) || 
			 ( Instrument.FullName=="$EURJPY" ) || 
			 ( Instrument.FullName=="$AUDJPY" ) || 
			 ( Instrument.FullName=="$NZDJPY")
			 )
			)

to this...?

 
Code
		if ( Historical &&
			(
			Instrument.FullName == "$USDJPY" || 
			Instrument.FullName == "$GBPJPY" || 
			Instrument.FullName == "$EURJPY" || 
			Instrument.FullName == "$AUDJPY" || 
			Instrument.FullName == "$NZDJPY"
			)
		)
...

Taking my first stab at C# but some syntax rules seem obvious to me, just wanna make sure I'm not F'*kin this up by applying standard syntax.

-Zx

They are equivalent but your second version is much better, imho. (I'm guessing like you) I like to see parentheses in conditionals only when needed (i.e. for changing evaluation precedence or logical equivalence). It is an individual preference thang as well though, we all have different eyes.

Just as an aside, remember that '==' is fine if both sides are strings, otherwise you may need to use 'if (myThing.IsEquals("xxx")) instead if one isn't, rarer though.


Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on August 26, 2014


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts