You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I don't follow, with switch you have the choice of using break to exit or opt to not use break and allow the cascading switch conditions execute as well. What exactly would you like an example of? a nested switch? (not a facetious question, I will be happy to provide but want to make sure I am answering the right question)
I don't follow, with switch you have the choice of using break to exit or opt to not use break and allow the cascading switch conditions execute as well. What exactly would you like an example of? a nested switch? (not a facetious question, I will be happy to provide but want to make sure I am answering the right question)
"...flexibility and extra control...", I thought you have some other tricks to abuse Switch. An elaborate nested Switch would be great.
Below is my recent use of Switch that on my attempt can't do without If. Perhaps you have an alternative view/s.
Ah, I see what you are speaking to now. Yes switch is only useful for those cases where the evaluated expression holds explicity bounded values.
Now in your specific example, the use of Period() is an explicitly bounded parameter unless you have created your own timeframe (which you could then hardcode just as well into the switch).
So I'd look to implement the following:
and here is an example of nested switching:
Below is my recent use of Switch that on my attempt can't do without If. Perhaps you have an alternative view/s.
Just one comment - you realize that using IF-ELSE's would likely be much faster... Plus, depending on the expected possible values, the last 'IF' statement is redundant if done like so:
1005phillip wrote >> Ah, I see what you are speaking to now. Yes switch is only useful for those cases where the evaluated expression holds explicity bounded values.
Now in your specific example, the use of Period() is an explicitly bounded parameter unless you have created your own timeframe (which you could then hardcode just as well into the switch).
So I'd look to implement the following:
and here is an example of nested switching:
new 21 standard Mql5 periods.
yeah I would implement if/else-if like gordon's example in your situation, the idea isn't to contort every situation into becomming switch-friendly, switch can help keep some code clean and easier to manipulate but nested if/else-if's are certainly a far more general approach imo.
Just one comment - you realize that using IF-ELSE's would likely be much faster... Plus, depending on the expected possible values, the last 'IF' statement is redundant if done like so:
yeah I would implement if/else-if like gordon's example in your situation, the idea isn't to contort every situation into becomming switch-friendly, switch can help keep some code clean and easier to manipulate but nested if/else-if's are certainly a far more general approach imo.
best regards
cameo