What's wrong with using this to modify orders? - page 2

 
yuan83:

Thanks both for your advice. I will look into them.

 

i am now getting another error when I backtest - invalid price 1.24985571 for OrderSend function  - OrderSend error 4107. 

Is it because there are too many decimal places?

Essentially,  yes.

ERR_INVALID_PRICE_PARAM4107Invalid price.

 

The quick and dirty fix is to use NormalizeDouble(value, Digits)   on that value.  

 
NormalizeDouble will change it to a power of 10. It must be a multiple of ticksize (for pending orders) and Metals are 0.25 not 0.10
 
WHRoeder:
NormalizeDouble will change it to a power of 10. It must be a multiple of ticksize (for pending orders) and Metals are 0.25 not 0.10
Yep,  hence the "quick and dirty" comment ;-)
 
Thanks Raptor and WHRoeder. Just a bit confused; you said it is a quick and dirty fix but on the NormalizeDouble page,it did says using this method to Normalize TP and SL. so this is not the orthodox method?
 
yuan83:
Thanks Raptor and WHRoeder. Just a bit confused; you said it is a quick and dirty fix but on the NormalizeDouble page,it did says using this method to Normalize TP and SL. so this is not the orthodox method?

If you are trying to trade an instrument whose price changes in increments of 0.25 then NormalizeDouble() will not do what you need it to.  For Forex it will work.

For example if you calculated a value of 9.30  and the instrument had a ticksize of 0.25 you would need to adjust this value from  9.30 to 9.25  NormalizeDouble()  could not be used in this instance as it could only give you 9, 9.3 or 9.30

 

Noted, thanks. I saw WHRoeder's post on the other thread, so I believe it Can use that if need to.

 

for mql4, I shd normalise to 4 dp, right? 

 

By the way, is there a command to track that a pending order has been activated? Other than use if price reaches buy stop price etc?

 

thanks 

 
OrderType() changes to OP_BUY/SELL
 
yuan83:

Noted, thanks. I saw WHRoeder's post on the other thread, so I believe it Can use that if need to.

 

for mql4, I shd normalise to 4 dp, right? 

You should Normalize to Digits  
 

Hi WHRoeder,

 I will try that out. Thanks. But for the case of a trade hitting stop loss, what can I use to identify that? Thanks

 

 

Raptor, thanks for the advice! 

Reason: