C# inline 'if' with multiple statements - NinjaTrader Programming | futures io social day trading
futures io futures trading


C# inline 'if' with multiple statements
Updated: Views / Replies:2,091 / 5
Created: by Big Mike Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors – all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you don’t need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

C# inline 'if' with multiple statements

  #1 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,352 given, 83,231 received

C# inline 'if' with multiple statements

I'm trying to do an inline if with multiple statements. I'm not sure this is possible?

int divisor = 1;
data = (!string.IsNullOrEmpty(symbol01) ? Closes[1][0] * Symbol01weight : 0) / divisor;

This is the simplest example, the actual condition is more complex.

What I want to do is change the 'true' condition to multiple statements:

Closes[1][0] * Symbol01weight; divisor++;

But I can't figure out a way to do this. At least not inline...

Thoughts? I tried Google but perhaps I am not wording it correctly, or it is impossible, because I can't find a solution (without rewriting the entire code block to not use an inline if).

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,352 given, 83,231 received


Here is the whole block the way it exists now. Please be kind, I'm 3-years out of practice with C#. Feel free to propose a more efficient block.

 
Code
int divisor = 1;
if (!string.IsNullOrEmpty(symbol01)) divisor++;
if (!string.IsNullOrEmpty(symbol02)) divisor++;
if (!string.IsNullOrEmpty(symbol03)) divisor++;
if (!string.IsNullOrEmpty(symbol04)) divisor++;
if (!string.IsNullOrEmpty(symbol05)) divisor++;
if (!string.IsNullOrEmpty(symbol06)) divisor++;
if (!string.IsNullOrEmpty(symbol07)) divisor++;
if (!string.IsNullOrEmpty(symbol08)) divisor++;
if (!string.IsNullOrEmpty(symbol09)) divisor++;
if (!string.IsNullOrEmpty(symbol10)) divisor++;
data = (Closes[0][0] * Symbol00weight + (!string.IsNullOrEmpty(symbol01) ? Closes[1][0] * Symbol01weight : 0) + (!string.IsNullOrEmpty(symbol02) ? Closes[2][0] * Symbol02weight : 0) + (!string.IsNullOrEmpty(symbol03) ? Closes[3][0] * Symbol03weight : 0) + (!string.IsNullOrEmpty(symbol04) ? Closes[4][0] * Symbol04weight : 0) + (!string.IsNullOrEmpty(symbol05) ? Closes[5][0] * Symbol05weight : 0) + (!string.IsNullOrEmpty(symbol06) ? Closes[6][0] * Symbol06weight : 0) + (!string.IsNullOrEmpty(symbol07) ? Closes[7][0] * Symbol07weight : 0) + (!string.IsNullOrEmpty(symbol08) ? Closes[8][0] * Symbol08weight : 0) + (!string.IsNullOrEmpty(symbol09) ? Closes[9][0] * Symbol09weight : 0) + (!string.IsNullOrEmpty(symbol10) ? Closes[10][0] * Symbol10weight : 0))/divisor;
Aggregate.Set(data);
Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #4 (permalink)
Elite Member
Northern Germany
 
Futures Experience: Intermediate
Platform: NT
Favorite Futures: FDAX, CL
 
vvhg's Avatar
 
Posts: 1,583 since Mar 2011
Thanks: 1,016 given, 2,807 received


Big Mike View Post
Here is the whole block the way it exists now. Please be kind, I'm 3-years out of practice with C#. Feel free to propose a more efficient block.

 
Code
int divisor = 1;
if (!string.IsNullOrEmpty(symbol01)) divisor++;
if (!string.IsNullOrEmpty(symbol02)) divisor++;
if (!string.IsNullOrEmpty(symbol03)) divisor++;
if (!string.IsNullOrEmpty(symbol04)) divisor++;
if (!string.IsNullOrEmpty(symbol05)) divisor++;
if (!string.IsNullOrEmpty(symbol06)) divisor++;
if (!string.IsNullOrEmpty(symbol07)) divisor++;
if (!string.IsNullOrEmpty(symbol08)) divisor++;
if (!string.IsNullOrEmpty(symbol09)) divisor++;
if (!string.IsNullOrEmpty(symbol10)) divisor++;
data = (Closes[0][0] * Symbol00weight + (!string.IsNullOrEmpty(symbol01) ? Closes[1][0] * Symbol01weight : 0) + (!string.IsNullOrEmpty(symbol02) ? Closes[2][0] * Symbol02weight : 0) + (!string.IsNullOrEmpty(symbol03) ? Closes[3][0] * Symbol03weight : 0) + (!string.IsNullOrEmpty(symbol04) ? Closes[4][0] * Symbol04weight : 0) + (!string.IsNullOrEmpty(symbol05) ? Closes[5][0] * Symbol05weight : 0) + (!string.IsNullOrEmpty(symbol06) ? Closes[6][0] * Symbol06weight : 0) + (!string.IsNullOrEmpty(symbol07) ? Closes[7][0] * Symbol07weight : 0) + (!string.IsNullOrEmpty(symbol08) ? Closes[8][0] * Symbol08weight : 0) + (!string.IsNullOrEmpty(symbol09) ? Closes[9][0] * Symbol09weight : 0) + (!string.IsNullOrEmpty(symbol10) ? Closes[10][0] * Symbol10weight : 0))/divisor;
Aggregate.Set(data);
Mike

You could stick it into a loop like for each symbol is empty reduce divisor by one.
But I think it would not be any more efficient, so it would probably only be for the looks.

vvhg

Hic Rhodos, hic salta.
Reply With Quote
 
  #5 (permalink)
Elite Member
Denver, CO
 
Futures Experience: Advanced
Platform: SierraChart
Broker/Data: Optimus, Rithmic
Favorite Futures: ES
 
Posts: 67 since Sep 2011
Thanks: 6 given, 32 received

 
Code
int divsor = 1 + new[] { symbol01, symbol02, symbol03, symbol04, symbol05, symbol06, symbol07,
symbol08, symbol09, symbol10 }.Count(s => !string.IsNullOrEmpty(s));
could you consider changing symbol01..symbol10 to string[] symbols = new string[10] ? it would simplify above to "divisor = 1 + symbols.Count(s => !string.IsNullOrEmpty(s));" :P

Reply With Quote
 
  #6 (permalink)
Elite Member
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,327 since Jul 2009
Thanks: 1,246 given, 2,635 received

Are you sure you are asking the right question?

Give some thought to how many times this test needs to be made and where this code is located.

Does it need to execute on every tick, on every bar, or just once (which is what it looks like to me, in which case it should be located in OnStartUp. Looks like that would require a different approach regarding what to do in response to the test.

Reply With Quote
The following user says Thank You to Zondor for this post:

Reply



futures io > > > > > C# inline 'if' with multiple statements

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Broker statements...safe to publish? patbateman The Elite Circle 11 August 1st, 2012 02:20 AM
PFG Founder Admits: I Forged Bank Statements for 20 Years Quick Summary News and Current Events 0 July 13th, 2012 05:50 PM
New PC virus doesn't just steal your money it creates fake online bank statements kbit Off-Topic 4 January 8th, 2012 02:34 PM
Conditional Nested Boolean Statements serac NinjaTrader Programming 4 November 27th, 2011 07:44 PM
IB: Analyse Statements Henrik Beginners and Introductions 4 March 12th, 2010 07:29 PM


All times are GMT -4. The time now is 11:22 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-14 in 0.10 seconds with 19 queries on phoenix via your IP 54.227.51.103