OrderModify

 

Anyone got any idea why this happens ?

In my EA I test if an order stoploss has been modified like this:

if(sl > openprice+5*Point)

if that is true it should mean order was not already modified because the original stop loss was much larger than that so then I modify the order to the same sl as the test

int ticket = OrderTicket();
double op  = OrderOpenPrice();
double tp  = OrderTakeProfit()+1*Point;
double sl  = op+5*Point;
bool response = OrderModify(ticket,op,sl,tp,0,Lime);

So it should only modify the order one time but it doesnt, when i run it in tester it keeps modifying it over and over, it seems that even though I modify it to openprice+5*Point and the modify is succesful, the sl is still bigger than openprice+5*Point so it does it again why is this ?

I changed the test to 6 pips while leaving the modify at 5 pips:

if(sl > openprice+6*Point)

when the test is at 6 pips it modifys the order only 1 time like I wanted, does this have something to do with the price doubles getting rounded down or something like that ?

 
check MarketInfo(Symbol(),MODE_STOPLEVEL)
 
I'm pretty sure it's a double precision issue: Can price != price ?
 
Can you paste the complete if-else loop where you are equating prices..??
 
May be normalizedouble can help you.
 

Yes - its the pecularities of using the math chip to get a value and a value stored in memory. While MathRound(openprice+5*Point) should get solve it I am curious if temp=openprice+5*Point and then if (sl>temp) does the same thing.

Calculations will be sent to the math chip but, I am not sure where how comparasons are done for double. There is a register in the processor chip that when it does subtraction checks the 'carry flag' to see if the result was negative. That carry flag if set or not determines if the result of greater than! So it all comes down to how MT4 interprits what we write and where (math chip or the accumulator of the processor) the 'negative' decision is made.

 

Your Question

when the test is at 6 pips it modifys the order only 1 time like I wanted, does this have something to do with the price doubles getting rounded down or something like that ?

Looks to me like RaptorUK pointed out the problem

for sell you have the condition to do the modify

if(sl > openprice+5*Point) 

it is continu modify the trade

and changed to openprice+6*Point it modifies one time

I think if you make this condition for sell

if(sl > OrderOpenPrice()+5.1*Point)

it will likely doing it also one time modifying the trade

So Yes your problem has to do with rounding up issue

 
dineshydv:
May be normalizedouble can help you.
Nope, it just causes more trouble . .
 
SDC:

Anyone got any idea why this happens ?

In my EA I test if an order stoploss has been modified like this:

if(sl > openprice+5*Point)

if that is true it should mean order was not already modified because the original stop loss was much larger than that so then I modify the order to the same sl as the test?

  1. Your code is for a BUY order but your journal shows a SELL
  2. Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
  3. What are Function return values ? How do I use them ? - MQL4 forum
  4. Not adjusting for 4/5 digit brokers.






 
WHRoeder:
  1. Your code is for a BUY order but your journal shows a SELL
  2. Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
  3. What are Function return values ? How do I use them ? - MQL4 forum
  4. Not adjusting for 4/5 digit brokers.


Code is for a sell order, the original stop loss is 100 pips above open price, I wanted to bring it down to just 5 pips above open price, reason why, I use a soft stop loss in my code which is broker stoploss - 5 pips so the soft stoploss will be at breakeven and the broker stop loss 5 pips higher as a disconnect failsafe

I never normalize Bid/Ask ... You said that so many times it is engraved in my brain lol

I have error handlng to test all return codes and perform the neccesary actions

I didnt adjust for 4/5 digit brokers because this is my own EA. My broker is 4 digit and so it is for use on my broker only.

 
Ickyrus:

Yes - its the pecularities of using the math chip to get a value and a value stored in memory. While MathRound(openprice+5*Point) should get solve it I am curious if temp=openprice+5*Point and then if (sl>temp) does the same thing.

Calculations will be sent to the math chip but, I am not sure where how comparasons are done for double. There is a register in the processor chip that when it does subtraction checks the 'carry flag' to see if the result was negative. That carry flag if set or not determines if the result of greater than! So it all comes down to how MT4 interprits what we write and where (math chip or the accumulator of the processor) the 'negative' decision is made.


Thanks for your reply Ickyrus this rounding issue is tough to deal with it doesnt seem to make sense that you can set SL = openprice+5*Point but then when you test it, SL != openprice+5*Point

I tested your two suggestions:

if ( sl > MathRound(openprice+5*Point)) that didnt work order still modified multiple times

double temp = openprice+5*Point; if(sl > temp) that didnt work either

i also tried if ( sl != openprice+5*Point ) but that didn't work, i didnt really expect it to

so then I did DeVries suggestion:

if ( sl > openprice + 5.1*Point ) This does work, it modifies one time only, so it has to be a rounding issue

Reason: