Dont know if it can help. when opening and modifying orders.
First, you might want to know what’s the minimum stoplevel is set in your broker’s Empty4 server. Adding this line of code will output the current minimum stoplevel for the currency pair of the chart, where you run the EA:
Code: Select all
Print(MarketInfo(Symbol(), MODE_STOPLEVEL));
You shouldn’t be using stop-loss or take-profit level, which are closer than MarketInfo(Symbol(), MODE_STOPLEVEL) to the current market price. If your EA calculates stops and take-profits dynamically, this is what I suggest you to do:
1. Declare a global variable for the minimum StopLevel; e.g.:
2. In the init() function of your expert advisor define the minimum StopLevel:
Code: Select all
StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD);
Note, that adding a spread difference is also required.
3.The next time your stop-loss or take-profit is calculated, just check them to be not less than StopLevel:
Code: Select all
if (StopLoss < StopLevel) StopLoss = StopLevel;
if (TakeProfit < StopLevel) TakeProfit = StopLevel;
4.Don’t forget to refresh the current market rates with
before adding the stop-loss/take-profits levels to the actual market rates.
That should help in the majority of the cases.
//(snippit from
http://www.earnforex.com/blog/ordersend ... hat-to-do/ )
...