Mosamba: I've researched for days, including here, using the term "ordersend/orderclose not working". There are lots of questions/answers but I still cannot figure it out. I appreciate your help. I'm attaching 2 of the many attempts I've tried, with notes on the behavior of each of them...
When backtesting with the above code and...
(a) setting Positions to Long & Short, it places a single SELL but never closes it. The Journal shows OrderClose error 138 = MT4 platform has missed your quoted price for executing an order.
(b) setting Positions to Short Only, has same behavior as above.
(c) setting Positions to Long Only, it operates correctly opening and closing BUY orders as expected.
As such I recoded to the following,
When backtesting with the above code...
(a) when Positions is set to Long & Short it places and closes "n" SELL orders in the same candle and Journal shows OrderSend error 134.
(b) when Positions is set to Long Only it places a single BUY but never closes it. Journal shows OrderSend error 4111.
134
ERR_NOT_ENOUGH_MONEY
Not enough money
138
ERR_REQUOTE
Requote
4111
ERR_SHORTS_NOT_ALLOWED
Shorts are not allowed. Check the Expert Advisor properties
Error 134: You are not properly calculating your volume based on your stop-loss risk and free margin.
Error 138: A re-quote occurred because the account/symbol is using Instant Execution Policy and the deviation/slippage setting is too low or the market price slipped too much and needs to be reevaluated.
Error 4111: Is because you disabled shorts/sells or because the symbol does not support them.
I would offer you links to previous posts of mine referencing these points (as they are common problems for newbies), the but the site's search function is currently not functioning properly. So I will leave the search to you to do, once the site is functioning properly again.

- docs.mql4.com
134
ERR_NOT_ENOUGH_MONEY
Not enough money
138
ERR_REQUOTE
Requote
4111
ERR_SHORTS_NOT_ALLOWED
Shorts are not allowed. Check the Expert Advisor properties
Error 134: You are not properly calculating your volume based on your stop-loss risk and free margin.
Error 138: A re-quote occurred because the account/symbol is using Instant Execution Policy and the deviation/slippage setting is to low or the market price slipped too much and needs to be reevaluated.
Error 4111: Is because you disabled shorts/sells or because the symbol does not support them.
I would offer you links to previous posts of mine referencing these points (as they are common problems for newbies), the but the site's search function is currently not functioning properly. So I will leave the search to you to do, once the site is functioning properly again.
100 points = 10 pips.
In live trading there can actually be slippage of any size. For example, during high volatility of news events, slippage on Forex can easily be in the range of 100 pips = 1000 points.
void ClosingOrders() { // for loop { /// orderselect if(OrderType()< 1) if(OrderType () == OP_BUY) if(OrderMagicNumber() == iMagic) <---- not needed if(OrderSymbol()== Symbol()) if(sma_5 < sma_16 && sma_16 > sma_25) { order = OrderClose(ticket,iLot,Bid,3,clrWhite); } <--- instead of ticket (which i use to do) put OrderClose(OrderTicket(),OrderLots(),OrderOpenPrice(),0,0). //// i know it shows a warning when you dont emphasize on the ordersend, but that is a very minor issue because OrderSelect will select the order for you. // closing SELL else{ if(sma_5 < sma_50 //// using the else if command, you do not have to specify if its AN OP_SELL, ea will recognize what to close if you have 2 types of positions && (sma_16 < sma_50 && (sma_5 > sma_16) order = OrderClose(ticket,iLot,Ask,3,clrMagenta); } } }
This should be working after you do a a for loop and then select the order. I take out the magic number because it is not needed UNLESS, you actually have a compiling problem and the ea cannot find your orders and also because you are really using only one pair. Putting them all into one loop will help this function very well since there is only one output (much easier for the ea to flick through the inputted signals). Read the code carefully, the logic will make sense once you understand the code and what the new commands return.
100 points = 10 pips.
In live trading there can actually be slippage of any size. For example, during high volatility of news events, slippage on Forex can easily be in the range of 100 pips = 1000 points.
This should be working after you do a a for loop and then select the order. I take out the magic number because it is not needed UNLESS, you actually have a compiling problem and the ea cannot find your orders and also because you are really using only one pair. Putting them all into one loop will help this function very well since there is only one output (much easier for the ea to flick through the inputted signals). Read the code carefully, the logic will make sense once you understand the code and what the new commands return.
That depends on your strategy. Surely if the entry price is too far away it could potentially invalidate one or two of your entry rules, right?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone!
I've researched for days, including here, using the term "ordersend/orderclose not working". There are lots of questions/answers but I still cannot figure it out.
I appreciate your help.
I'm attaching 2 of the many attempts I've tried, with notes on the behavior of each of them...
When backtesting with the above code and...
(a) setting Positions to Long & Short, it places a single SELL but never closes it.
The Journal shows OrderClose error 138 = MT4 platform has missed your quoted price for executing an order.
(b) setting Positions to Short Only, has same behavior as above.
(c) setting Positions to Long Only, it operates correctly opening and closing BUY orders as expected.
As such I recoded to the following,
When backtesting with the above code...
(a) when Positions is set to Long & Short it places and closes "n" SELL orders in the same candle and Journal shows OrderSend error 134.
(b) when Positions is set to Long Only it places a single BUY but never closes it. Journal shows OrderSend error 4111.
.