Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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.
Can you help answer these questions from other members on NexusFi?
"||" -> 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.
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:
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.
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.