Which OR operator to use in C# please? - NinjaTrader Programming | futures io social day trading
futures io futures trading


Which OR operator to use in C# please?
Updated: Views / Replies:2,126 / 16
Created: by Al2010 Attachments:1

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

Closed Thread
 1  
 
Thread Tools Search this Thread
 

Which OR operator to use in C# please?

  #1 (permalink)
Trading for Fun
 
Futures Experience: None
Platform: NinjaTrader
 
Posts: 50 since Oct 2010
Thanks: 36 given, 10 received

Which OR operator to use in C# please?

Hi,
There are few OR operators in C# and I'm not sure which one to use. Can anyone help please?
Example, if 50 SMA < 0 (falling) OR 50 WMA < 0 - if either one of these are falling then do smth... Another words if 50 SMA is up/flat but 50 WMA is falling or the other way around then return true as if both are falling.
Thank you very much.

 
  #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)
Elite Member
Houston, Texas
 
Futures Experience: Advanced
Platform: NinjaTrader
 
Posts: 25 since Oct 2010
Thanks: 2 given, 19 received



Al2010 View Post
Hi,
There are few OR operators in C# and I'm not sure which one to use. Can anyone help please?
Example, if 50 SMA < 0 (falling) OR 50 WMA < 0 - if either one of these are falling then do smth... Another words if 50 SMA is up/flat but 50 WMA is falling or the other way around then return true as if both are falling.
Thank you very much.

if( (50 SMA < 0 ) || (50 WMA < 0) )
{
return true;
}
else
{
return false;
}

The following user says Thank You to samWest for this post:
 
  #4 (permalink)
Elite Member
Madison, WI
 
Futures Experience: Advanced
Platform: Sierra Charts, ALT
Favorite Futures: ES
 
aslan's Avatar
 
Posts: 614 since Jan 2010
Thanks: 342 given, 1,077 received

Sam has it right.

There are two "or" operators:

"||" -> this is the logical operator, which is normally what you want to use in boolean expressions (like if's)

"|" -> this is the binary operator, which is used for doing bit operations (i.e. masking)

People sometimes get confused, because the binary operator can still work in logical expressions, just because of the way boolean true/false expressions are represented with numbers 0 & 1. While this is true, you should always use the proper logical or operator to avoid anything the compiler might try to optimize.

The same is true for the "and" operators "&&" and "&".

The following 3 users say Thank You to aslan for this post:
 
  #5 (permalink)
Trading for Fun
 
Futures Experience: None
Platform: NinjaTrader
 
Posts: 50 since Oct 2010
Thanks: 36 given, 10 received


samWest View Post
if( (50 SMA < 0 ) || (50 WMA < 0) )
{
return true;
}
else
{
return false;
}

Hi,
If SMA 50 > 0 and 50 WMA < 0 will this return false? How to make it return true?
Thank you very much.

 
  #6 (permalink)
Trading for Fun
 
Futures Experience: None
Platform: NinjaTrader
 
Posts: 50 since Oct 2010
Thanks: 36 given, 10 received


aslan View Post
Sam has it right.

There are two "or" operators:

"||" -> this is the logical operator, which is normally what you want to use in boolean expressions (like if's)

"|" -> this is the binary operator, which is used for doing bit operations (i.e. masking)

People sometimes get confused, because the binary operator can still work in logical expressions, just because of the way boolean true/false expressions are represented with numbers 0 & 1. While this is true, you should always use the proper logical or operator to avoid anything the compiler might try to optimize.

The same is true for the "and" operators "&&" and "&".

Hi,
Is there an inclusive OR so to speak as in my previous reply to samWest - if 50 SMA> 0 and 50 WMA < 0 then return true, e.g. if one of those true then return true?
Thank you very much.

 
  #7 (permalink)
Elite Member
Madison, WI
 
Futures Experience: Advanced
Platform: Sierra Charts, ALT
Favorite Futures: ES
 
aslan's Avatar
 
Posts: 614 since Jan 2010
Thanks: 342 given, 1,077 received


Al2010 View Post
Hi,
Is there an inclusive OR so to speak as in my previous reply to samWest - if 50 SMA> 0 and 50 WMA < 0 then return true, e.g. if one of those true then return true?
Thank you very much.

Thats the logical and operator ("&&").

The following user says Thank You to aslan for this post:
 
  #8 (permalink)
Elite Member
Houston, Texas
 
Futures Experience: Advanced
Platform: NinjaTrader
 
Posts: 25 since Oct 2010
Thanks: 2 given, 19 received


Al2010 View Post
Hi,
Is there an inclusive OR so to speak as in my previous reply to samWest - if 50 SMA> 0 and 50 WMA < 0 then return true, e.g. if one of those true then return true?
Thank you very much.

Ok Al2010. You seem to be a little weak in you basic logic knowledge. I'm not trying to be critical, just an observation. A basic understanding of the logical AND, and OR are essential skills for programming. Slightly less essential but important are the concepts of EXCLUSIVE OR often notated as XOR. I would suggestion studying what are know as the logical truth tables.

End of lecture . To answer you specific question, as I think I understand it:
The way the logical OR ( || in C# or C++) works is if either side of the OR symbol is true or both sides of the OR symbol are true then the whole statement will evaluate as true. I guess you could call this an "inclusive" OR.

The following user says Thank You to samWest for this post:
 
  #9 (permalink)
Trading for Fun
 
Futures Experience: None
Platform: NinjaTrader
 
Posts: 50 since Oct 2010
Thanks: 36 given, 10 received


samWest View Post
Ok Al2010. You seem to be a little weak in you basic logic knowledge. I'm not trying to be critical, just an observation. A basic understanding of the logical AND, and OR are essential skills for programming. Slightly less essential but important are the concepts of EXCLUSIVE OR often notated as XOR. I would suggestion studying what are know as the logical truth tables.

End of lecture . To answer you specific question, as I think I understand it:
The way the logical OR ( || in C# or C++) works is if either side of the OR symbol is true or both sides of the OR symbol are true then the whole statement will evaluate as true. I guess you could call this an "inclusive" OR.


Thanks aslan and samWest.
Thanks for the lecture, samWest. Wish i was in my 20s again to learn all i can learn...

That's exactly what I would expect from || as you descr. above. I lost that example that confused me with ORs... If I have another one I will post it.
Maybe you guys can help me with other small problem I have. I have a simple program that draws arrows whenever the Stochastic crosses above/below 20-80. I'm checking for multiple crosses but I want my program draw arrows only once per cross. Here's the small check program I'm running:

int crsAbvCheck = 0;
if (Stochastics(periodD, periodK, smooth).K[0] > 20 && Stochastics(periodD, periodK, smooth).K[0] < 30)
{
if (CrossAbove(Stochastics(periodD, periodK, smooth).K, 20, 1))
{
crsAbvCheck = 20;
Print("Cross abv = " +crsAbvCheck+ "---Time:......"+Time[0]);
}
}
else if (Stochastics(periodD, periodK, smooth).K[0] > 30 && Stochastics(periodD, periodK, smooth).K[0] < 40)
{
if (CrossAbove(Stochastics(periodD, periodK, smooth).K, 30, 1))
{
crsAbvCheck = 30;
Print("Cross abv = " +crsAbvCheck+ "---Time:......"+Time[0]);
}
}
else { crsAbvCheck = 0; }

Here's the output - 6E 300 volume chart:

Cross abv = 20---Time:......12/9/2010 10:21:32 AM
Cross abv = 30---Time:......12/9/2010 10:21:32 AM

// Getting both messages for both crosses 20 and 30 whenever the Stoch is below 20 and crossing up...
Cross abv = 20---Time:......12/9/2010 12:32:26 PM
Cross abv = 30---Time:......12/9/2010 12:34:49 PM

As you can see the program fails. When the Stoch is below 20 and crossing up it prints messages for both crosses 20 and 30. I would get two arrows up on my chart -20 and 30 arrows whenever cross above 20=true. I expected to get only one message/arrow for the lowest cross above, e.g. crs. abv 20. Yes there was a price jump at that time... But still, I'd like to stop my program somehow if the lowest cross above is true. Is this my fuzzy logic again? Another lecture maybe? I will gladly take it, honestly.
How to fix it please? How to get only one message/arrow per cross, e.g. if above 20 and below 30 then only cross abv 20=true, if above 30 but below 40 then only cross abv 30=true...
Thank you very much.


Last edited by Al2010; December 9th, 2010 at 01:42 PM.
 
  #10 (permalink)
Elite Member
Houston, Texas
 
Futures Experience: Advanced
Platform: NinjaTrader
 
Posts: 25 since Oct 2010
Thanks: 2 given, 19 received


I'm sorry Al2010, I'm not going to write your code for you. My suggestion would be to go over to the indicator download area and look for something that is similar to what you want to do. Downloaded it, and look at the code. Studying other peoples code is great way to improve you coding skills.

The following user says Thank You to samWest for this post:

Closed Thread



futures io > > > > > Which OR operator to use in C# please?

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     


All times are GMT -4. The time now is 08:40 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-12 in 0.19 seconds with 19 queries on phoenix via your IP 54.90.207.75