Using "Switch" versus multiple "if's"...any preference to be given one over the other? - page 2

 

I just used phillip's code for the test without thinking of the specifics... But yeah, I agree MarketInfo() might affect the results. Redoing simpler tests and I'm getting inconsistent results as well. Strange... Don't know what to make of it.

 
cameofx wrote >>
Switch is great, if it only can test multiple conditions. Also why haven't I seen nested Switch used ?
I use nested switch to check symbol type (EURUSD vs GBPJPY, etc) followed by ordertype (Buy, Sell). Works just fine. Just have to mind the breaks.
 
gordon:

I just used phillip's code for the test without thinking of the specifics... But yeah, I agree MarketInfo() might affect the results. Redoing simpler tests and I'm getting inconsistent results as well. Strange... Don't know what to make of it.

FYI, I don't seem to be getting absolutely identical output from MathRand() after using MathSrand(1). Over the course of your 1000000 iterations I'm sometimes seeing one or two values which are different across the two tests.
 
jjc:
FYI, I don't seem to be getting absolutely identical output from MathRand() after using MathSrand(1). Over the course of your 1000000 iterations I'm sometimes seeing one or two values which are different across the two tests.
WTF?! That's surprising... Well that certainly might explain the inconsistencies in timing results. But the idea that MathRand() does not produce the same series for a specific seed is disturbing.
 
jjc:
Over the course of your 1000000 iterations I'm sometimes seeing one or two values which are different across the two tests.

U sure? I can't seem to find any inconsistencies with MathRand()...

// script produces 2 random number series (starting with same seed) and compares them
#define SIZE  100000000
#define SEED  1                 // trying other values still produces consistent results (identical random number series)

int start()
  {
   int a[SIZE],b[SIZE],i;
   
   MathSrand(SEED);
   for (i=0; i<SIZE; i++) 
      a[i]=MathRand();          // fill a[] array with a series of random numbers
   
   MathSrand(SEED);
   for (i=0; i<SIZE; i++) 
      b[i]=MathRand();          // fill b[] array...  
   
   for (i=0; i<SIZE; i++)
      if (a[i]!=b[i])           // verify identical arrays a[] and b[]
         Print("iteration ",i," failed!");
  }
 

jjc it might be hardware related...as in a flipped bit in your ram somewhere...do you use ECC? not using oc'ed rig, are you? time to breakout memtest+ and prime95

 
gordon:

U sure? I can't seem to find any inconsistencies with MathRand()...

I tried replicating it immediately with code such as yours, and failed. I no longer have the code (based on your SpeedTest) which seemed to be triggering it. I'll keep an eye on this. It was probably me doing something dumb, but I can't think what.
 

" Gordon : For clarity's sake... A nested switch is almost always avoidable. "

--> Yep, besides that, not that easy typing it too, I don't see why if a Switch condition is fulffiled (1/more case's constant/s is met) we need the obligatory break? still ranks a distant 3rd in my list :)

" Phillip : I use nested switch to check symbol type (EURUSD vs GBPJPY, etc) followed by ordertype (Buy, Sell). Works just fine. Just have to mind the breaks."

--> As I mentioned the break IMHO makes it less convenient... BTW MQL5 introduced 'new' do...while... 'more options' now.

 
cameofx wrote >>

" Phillip : I use nested switch to check symbol type (EURUSD vs GBPJPY, etc) followed by ordertype (Buy, Sell). Works just fine. Just have to mind the breaks."

--> As I mentioned the break IMHO makes it less convenient... BTW MQL5 introduced 'new' do...while... 'more options' now.


Personally I like having the extra control and flexibility in engineering nested switches with the breaks. I hope they don't take this away in MQL5 (or whatever they are calling the metaquote language for MT5 platform).
 
1005phillip:

Personally I like having the extra control and flexibility in engineering nested switches with the breaks. I hope they don't take this away in MQL5 (or whatever they are calling the metaquote language for MT5 platform).

flexibility doesn't come to mind, when I think of switch, if you care to show it / have some example, it would be awsome...

In my experience, Switch often cannot do without If, while If will sail through without the former.

Reason: