I have a similar problem when I try to modify SLTP of a position. (Position is opened manually, without setting any SL or TP) Code is:
int OnInit() { PositionSelect(Symbol()); Print(PositionGetDouble(POSITION_PRICE_CURRENT)); MqlTradeRequest request; request.action = TRADE_ACTION_MODIFY; request.symbol = Symbol(); request.sl = NormalizeDouble(PositionGetDouble(POSITION_PRICE_CURRENT)+0.01, 4); request.tp = NormalizeDouble(PositionGetDouble(POSITION_PRICE_CURRENT)-0.01, 4); MqlTradeResult result; OrderSend(request,result); return(0); }
Output:
2011.07.21 21:06:07 xyz (EURUSD,M1) 1.43822 2011.07.21 21:06:07 Trades '912850' : failed modify order #0 buy 0.00 EURUSD at 0.00000 sl: 0.00000 tp: 0.00000 -> 0.00000, sl: 1.44820 tp: 1.42820 [Invalid request]
Documentation says:
SL & TP Modification
Trade order to modify the StopLoss and/or TakeProfit price levels. It requires to specify the following 5 fields:
action
symbol
sl
tp
...but what is the 5th field?
If I add the following two lines then it magically works:
request.price = 1.5; request.deviation = 10000;
Howver in the documentation, it is said that it's not needed:
Price, reaching which the order must be executed. Market orders of symbols, whose execution type is "Market Execution" (SYMBOL_TRADE_EXECUTION_MARKET), of TRADE_ACTION_DEAL type, do not require specification of price.
I realized that instead of
request.action = TRADE_ACTION_MODIFY;
the value
request.action=TRADE_ACTION_SLTP;
should be used. And the SL and TP prices were swapped.
But I still can't get the market execution working in the way it is stated in the documentation.
- www.mql5.com
Are you able to send market order for this symbol manually (look at list of values in combo Type of new order form)?
Are you connected to MetaQuotes-Demo?
Are you able to send market order for this symbol manually (look at list of values in combo Type of new order form)?
Yes.
Yes, of course!Are you connected to MetaQuotes-Demo?
Hello,
I also have problem with market execution and it looks to be connected with what is explained above. However, I could not actually understand what is going on. I do use MetaQuates-Demo and I succeed in submitting order of type Instant Execution. Here are the screenshots from the terminal and afterwards is the code that I use to send order from MQL5. The OrderSend method results with code 10016 and message "Invalid stops".
There is the source code:
void OnInit() { MqlTradeRequest request; request.action = TRADE_ACTION_DEAL; request.symbol = _Symbol; request.volume = 0.1; request.type = ORDER_TYPE_BUY; request.type_filling = ORDER_FILLING_FOK; MqlTradeResult result; OrderSend(request, result); }
Could you please explain me what happens and what I can do to execute market orders from my EAs with the demo account? Thank you in advance!
Kind Regards,
Petrov
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
But it fails because of:
The MQL5 documentation clearly states that:
Sorry if it's a novice question, but I really do not understand the logic behind this (again).