if ((currsl - pivotlow) != 0)my guess is it never equals zero so it always executes
my guess is it never equals zero so it always executes
Look at stdlib.mq4 on your MetaEditor libraries, it said
//+------------------------------------------------------------------+ //| right comparison of 2 doubles | //+------------------------------------------------------------------+ bool CompareDoubles(double number1,double number2) { if(NormalizeDouble(number1-number2,8)==0) return(true); else return(false); }
if (OrdersTotal() >0 ) { OrderSelect (ticket, SELECT_BY_TICKET);
If the orderselect fails, everything below is bogus. Always test return codes.if ((currsl - pivotlow) != 0) // Equivalent to: if(currsl != pivotlow)
Doubles rarely compare equal (or not equal usually compares true.) Can price != price ? - MQL4 forum
Hi Guys
Thanks for your help .. guess i didn't search the forum deep enough. my bad.
if ((currsl - pivotlow) != 0)
BTW. with that code, it will executed on every tick point. Try make a band of it, for example :
if ( ((currsl - 10*Point) - pivotlow) || ((currsl + 10*Point) - pivotlow) != 0)
BTW. with that code, it will executed on every tick point. Try make a band of it, for example :
Hi onewithzachy
I don't get it how by making a band will optimize the code. care to elaborate more?
Hi onewithzachy
I don't get it how by making a band will optimize the code. care to elaborate more?
Your codes here ...
double currsl = OrderStopLoss (); if ( (currsl - pivotlow) != 0 )//if pivot low is NOT the same as current SL , execute
... is the problem. Because the pivotlow may change on every tick (read : on every single Point), especially if calculated using current price of bar 0.
If for example you band pivotlow like this :
double Upper_pivotlow = pivotlow + 10*Point // << this is depend on ... double Lower_pivotLow = pivotlow - 10*Point // ... whether you using 4 or 5 digits broker double currsl = OrderStopLoss (); if ( (Upper_pivotlow - currs1) <= 0 || // if the real pivotlow is 10 point below ... (Lower_pivotLow - currs1) >= 0 ) // ... or 10 Point higher than SL { // do some act }
... it only be executed if pivotlow is 10 point above or below SL (that's 20 Point bands, btw).
just my IMHO ...
:)
hope I'm not wrong code them ;)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
i've a ordermodify cmd that always execute even when the if statement is false.
please would any experts here tell me why is this so ?