MetaTrader can't do simple math?

 

Hi,


I'm working on a trailing stop EA, and for some reason I can't get the platform to compare numbers correctly, and it's driving me up the wall.


Before trying to set a new SL value, I check to see if the new calculated SL is great than or lesser than the current SL, depending on it being a Buy or Sell, simply using "NewSL > OrderStopLoss()" or "NewSL < OrderStopLoss()", but for some reason MetaTrader STILL tries to trail the SL even if the values are equal, and I get an ErrorCode = 1. I have even tried using a != clause but to no avail.


I have been looking through code all weekend, and I haven't been able to find a single EA or piece of code that handled this differenly, so what am I missing?


Does anyone know why MetaTrader for some reason can't do a number comparison? I have even tried with NormalizeDouble, but that didn't help eiher.


If I log the values, I can see that the two values are equal, but for some reason MetaTrader thinks that one is greater than the other, or lesser than the other. MetaTrader is even oblivious to a != comparison, even though I can see that the two values are identical.


This is driving me nuts, and any feedback would be greatly appreciated.



Regards,


Kieran

 

You should have posted that piece of code, where you are trying to compare stop losses. But top of my head, you've probably forgotten to issue OrderSelect(...) before you call OrderStopLoss(). 

 
kieran.w:

Hi,


I'm working on a trailing stop EA, and for some reason I can't get the platform to compare numbers correctly, and it's driving me up the wall.


Before trying to set a new SL value, I check to see if the new calculated SL is great than or lesser than the current SL, depending on it being a Buy or Sell, simply using "NewSL > OrderStopLoss()" or "NewSL < OrderStopLoss()", but for some reason MetaTrader STILL tries to trail the SL even if the values are equal, and I get an ErrorCode = 1. I have even tried using a != clause but to no avail.


I have been looking through code all weekend, and I haven't been able to find a single EA or piece of code that handled this differenly, so what am I missing?


Does anyone know why MetaTrader for some reason can't do a number comparison? I have even tried with NormalizeDouble, but that didn't help eiher.


If I log the values, I can see that the two values are equal, but for some reason MetaTrader thinks that one is greater than the other, or lesser than the other. MetaTrader is even oblivious to a != comparison, even though I can see that the two values are identical.


This is driving me nuts, and any feedback would be greatly appreciated.



Regards,


Kieran


Have you tried using the CompareDoubles() function?

Reason: