Strategy Tester Gets Stuck - page 2

 
gordon:
That's a matter of opinion and coding style. Although there is a slight performance impact in doing it Russel's way (it's slightly slower - but almost negligibly so)...

I'm not sure if it is actually slower in general. Conditions in a if statement are evaluated from left to right. If a condition isn't met the rest won't be evaluated. In Roeder's approach all conditions are evaluated before the statement is tested. So when you have more conditions "my" approach could be faster. And it gives you a extra level of control.

compare

bool Buying = EMA5 > EMA13;
bool Stochastic = Stochastic5 < 20;
bool OtherSignal = ;

if (Buying && Stochastic && OtherSignal){

}
if (EMA5 > EMA13 && Stochastic5 < 20 && OtherSignal != value ){

}

if the first condition isn't met Stochastic5 < 20 won't be tested. The third condition could hold a evaluation dependent on successful evaluation of 1st or 2nd condition

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) != FALSE && OrderMagicNumber() == MAGICNUMBER && OrderSymbol() == gsSymbol) { }
 
Russell:

If a condition isn't met the rest won't be evaluated.

Not, I believe, true of MQL4. Various discussions on this forum about it not exiting early. For example, in the following code all three functions are called despite the conditions not being met.

int start()
{
   if (Test1() && Test2() && Test3()) {
   
   }
}   

bool Test1() {Print("Test1 called");return (false);}
bool Test2() {Print("Test2 called");return (false);}
bool Test3() {Print("Test3 called");return (false);}
 

It's mentioned in the docs (https://docs.mql4.com/basis/operations/bool):

Logical expressions are calculated completely, i.e., the so-called "short estimate" method does not apply to them.
 
wtf! unbelievable! I stand corrected
 
Russell:
wtf! unbelievable! I stand corrected
Yeah, but I have noticed now that WHRoeder does the same. Somehow I had it in my mind that he was using nested IF's (which is indeed faster)... Sorry.
 

Yes, but a lot of nesting won't help the clarity of code. I guess in most cases it isn't worth the trouble for a few less cycles.

Thanks jjc and gordon for pointing this out to me.

*picking up the pieces of my mql paradigm* 8-)

 
gordon wrote >>
Yeah, but I have noticed now that WHRoeder does the same. Somehow I had it in my mind that he was using nested IF's (which is indeed faster)... Sorry.


nested IF's is the speed-up approach I use, especially helpful when calling/evaluating multiple indicators.

The evalution of all logical expressions makes sense to me, an if() expression is just like a function call and all the parameters being passed to the function IF must be evaluated before the IF function's conditional criterion itself can be processed.

 
The evalution of all logical expressions makes sense to me
In many programming languages this is not the case. The if statement would be processed as I described above. I assumed this was also true in MQL. Assumptions and programming don't mix very well, specially when you try it with MQL ;-)
 
Russell:
In many programming languages this is not the case. The if statement would be processed as I described above. I assumed this was also true in MQL. Assumptions and programming don't mix very well, specially when you try it with MQL ;-)


Guys, need your help, again..

I have an indicator which calculates three arrays, one array is not shown on the chart.

I want to call these arrays in an EA and see the conditions for buy or selling, like if the line on the chart is in green to buy and if its red to sell,

how is it possible?

Thanks!!! Everybody!

 

Jay,


iCustom is your best bet for getting data from an indicator into an EA

https://docs.mql4.com/indicators/iCustom

Just need to put the correct number in mode for the respective buffer. You would call icusotm three times each with a different number in for mode (0/1/2) to get the value of the three buffers.

Hope that helps

V