Page 1 of 1

MT4: OrderSend error 4107 during back-test

Posted: Tue Jan 29, 2013 4:42 am
by admin
When back-testing on a 4-digit Metatrader 4 terminal, users could encounter the following error:
OrderSend error 4107
Error opening BUYSTOP order []: (4107) invalid price parameter for trade function
invalid price 1.28236000 for OrderSend function
You can resolve the issue by either:

- Modifying your MQ4 mode (if you have access to it). You will need to amend all the "OrderSend" and "OrderModify" commands so they adjust your prices to 4-digits. You can do this by wrapping all prices in the function "NormalizeDouble(price, Digits)". For example, if the code reads like the following:

Code: Select all

   ticket=OrderSend(Symbol(),OP_BUY, lots, Ask, slip, stoploss, takeprofit, EA, MagicNo, 0, Blue);

you will need to change it to:

Code: Select all

   ticket=OrderSend(Symbol(),OP_BUY, lots, NormalizeDouble(Ask, Digits), slip, stoploss, takeprofit, EA, MagicNo, 0, Blue);

- If you do not have the code, you can instead utilise a 5-Digit MT4 terminal to back-test your strategy.

If either option is not viable, an enhancement is planned for the next version of Tickstory to ensure prices are rounded for 4-digit brokers.

Regards.