Hello,
I tried to send market order on a MT5 demo account (alpari)? I put the following code:
void OnStart()
{
MqlTradeRequest request;
request.action = TRADE_ACTION_DEAL;
request.symbol = _Symbol;
request.volume = 0.1;
request.type = ORDER_TYPE_SELL;
request.type_filling = ORDER_FILLING_FOK;
MqlTradeResult result;
OrderSend(request, result);
}
and I receive the following error message:
2013.01.18 23:27:38 Trades '20043872': failed exchange sell 0.10 EURUSD at 0.00000 sl: 0.00000 tp: 0.00000 [Invalid request]
Do not understand what is the reason I receive "[Invalid request]"
1. In the future, please use SRC button when posting some codes, it will make the code much easier to read
2. When did you run the script ? Market close on weekend, so you can't open anything.
3. Always check the return value of mql5 function you use. In your case, you should check the return value of OrderSend, MqlTradeResult, and GetLastError.
4. The reason you receive "Invalid Request" error because you try to open position at price 0.00000, with non ECN broker.
Now, can you correct your code ?
Thank you for your sugestions.
My live account is ECN. I belive that the demo account is also ECN . If it is not than how to code to open a market order? The order was send yesterday wnen the masrket was open.
Any other sugestions?
- www.mql5.com
3. Always check the return value of mql5 function you use. In your case, you should check the return value of OrderSend, MqlTradeResult, and GetLastError.
I am biginner in coding. Please tell me how to do the check.
Hello,
I tried to send market order on a MT5 demo account (alpari)? I put the following code:
void OnStart()
{
MqlTradeRequest request;
request.action = TRADE_ACTION_DEAL;
request.symbol = _Symbol;
request.volume = 0.1;
request.type = ORDER_TYPE_SELL;
request.type_filling = ORDER_FILLING_FOK;
MqlTradeResult result;
OrderSend(request, result);
}
and I receive the following error message:
2013.01.18 23:27:38 Trades '20043872': failed exchange sell 0.10 EURUSD at 0.00000 sl: 0.00000 tp: 0.00000 [Invalid request]
Do not understand what is the reason I receive "[Invalid request]"
Wahoo:
There is price field missing. You should add request.price field into your Trade Request Structure.
Well I want to send a market order. So a price is not necessary, I think!
tenlau:
Well I want to send a market order. So a price is not necessary, I think!
I think firstly you try what Wahoo suggest ...
I am sure that is not necessary. From MQL5 documentation :
The Trade Request Structure (MqlTradeRequest)
Field description
price |
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. |
So I am sure is something in coding that is wrong.....
@tenlau
1. I would be appreciate if you're not double posting in the forum again !. In the forum, you should be patient for the answer, coz not everyone is login all the time. And please appreciate your fellow forumer, you get help from a lot of users here, and yet in your other topic you said that you get no result (yet) from this topic. You are not get the result (yet) because you're not follow the given advice.
2. You said this :
...
My live account is ECN. I belive that the demo account is also ECN . ...
Yet you have exchange error :
tenlau:
...
and I receive the following error message:
2013.01.18 23:27:38 Trades '20043872': failed exchange sell 0.10 EURUSD at 0.00000 sl: 0.00000 tp: 0.00000 [Invalid request]
Do not understand what is the reason I receive "[Invalid request]"
Don't do believe in programming and trading. ECN is market order, not an exchange but you get exchange error, so I check AlpariUK with this code
void OnStart() { switch ( (ENUM_SYMBOL_TRADE_EXECUTION) SymbolInfoInteger(_Symbol, SYMBOL_TRADE_EXEMODE) ) { case SYMBOL_TRADE_EXECUTION_REQUEST : {Print ("Request"); break;} case SYMBOL_TRADE_EXECUTION_INSTANT : {Print ("Instant"); break;} case SYMBOL_TRADE_EXECUTION_MARKET : {Print ("Market"); break;} case SYMBOL_TRADE_EXECUTION_EXCHANGE : {Print ("Exchange"); break;} } return; }
And it print "Exchange".
3. I said this
...
3. Always check the return value of mql5 function you use. In your case, you should check the return value of OrderSend, MqlTradeResult, and GetLastError.
...
So you should code it this way,
void OnStart() { PlaySound("wait.wav"); MqlTick latest_price; if (SymbolInfoTick(_Symbol, latest_price)) //--- get the latest price { MqlTradeRequest request; MqlTradeResult result; MqlTradeCheckResult check; request.action = TRADE_ACTION_DEAL; request.symbol = _Symbol; request.volume = 0.1; request.type = ORDER_TYPE_SELL; request.type_filling = ORDER_FILLING_FOK; request.price = latest_price.bid; //--- get the bid price (did Wahoo, achidayat, and tuoitrecuoi tell you so ?) ResetLastError(); if (OrderCheck (request,check) ) { if (!OrderSend(request, result)) //--- if order send fail you know what causing it { Print ("error ",GetLastError()," return code ",result.retcode," broker comments ", result.comment); } else { if (result.retcode != (0 || TRADE_RETCODE_PLACED || TRADE_RETCODE_DONE) ) { Print ("error ",GetLastError()," return code ",result.retcode," broker comments ", result.comment); } } } else { Print ("error ",GetLastError()," check code ",check.retcode); } } return; }
@tenlau
1. I would be appreciate if you're not double posting in the forum again !. In the forum, you should be patient for the answer, coz not everyone is login all the time. And please appreciate your fellow forumer, you get help from a lot of users here, and yet in your other topic you said that you get no result (yet) from this topic. You are not get the result (yet) because you're not follow the given advice.
2. You said this :
Yet you have exchange error :
Don't do believe in programming and trading. ECN is market order, not an exchange but you get exchange error, so I check AlpariUK with this code
And it print "Exchange".
3. I said this
So you should code it this way,
- www.mql5.com
- 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,
I tried to send market order on a MT5 demo account (alpari)? I put the following code:
void OnStart()
{
MqlTradeRequest request;
request.action = TRADE_ACTION_DEAL;
request.symbol = _Symbol;
request.volume = 0.1;
request.type = ORDER_TYPE_SELL;
request.type_filling = ORDER_FILLING_FOK;
MqlTradeResult result;
OrderSend(request, result);
}
and I receive the following error message:
2013.01.18 23:27:38 Trades '20043872': failed exchange sell 0.10 EURUSD at 0.00000 sl: 0.00000 tp: 0.00000 [Invalid request]
Do not understand what is the reason I receive "[Invalid request]"