Download MetaTrader 5

can not open market order on MT5 demo account

To add comments, please log in or register
Laurentiu Sorin Tene
692
Laurentiu Sorin Tene 2013.01.19 09:26 

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]"

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Trade Operation Types - Documentation on MQL5
phi nuts
2184
phi nuts 2013.01.19 10:46  
tenlau:

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 ?

Laurentiu Sorin Tene
692
Laurentiu Sorin Tene 2013.01.19 12:46  

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? 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Account Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Account Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Account Properties - Documentation on MQL5
Laurentiu Sorin Tene
692
Laurentiu Sorin Tene 2013.01.19 12:58  
phi.nuts:
 

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. 

Andrey Barinov
39275
Andrey Barinov 2013.01.19 13:22  
tenlau:

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]"

There is price field missing. You should add request.price field into your Trade Request Structure.
Laurentiu Sorin Tene
692
Laurentiu Sorin Tene 2013.01.19 13:50  

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! 

Achmad Hidayat
14766
Achmad Hidayat 2013.01.19 14:24  

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 ..
Laurentiu Sorin Tene
692
Laurentiu Sorin Tene 2013.01.19 14:48  
achidayat:
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.....

Trinh Dat
37584
Trinh Dat 2013.01.19 15:31  

need add:

request.price = SymbolInfoDouble(_Symbol,SYMBOL_BID)

phi nuts
2184
phi nuts 2013.01.19 16:46  

@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 OrderSendMqlTradeResult, 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;
  }

 

Laurentiu Sorin Tene
692
Laurentiu Sorin Tene 2013.01.19 18:40  
phi.nuts:

@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, 

 

Sorry for double posting. I thought I was not elected the right Category. Thank you very much for your code and explanations. Now I am not so confused as I was at first. I will keep everybody informed when the market will open on monday.
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Documentation on MQL5
12
To add comments, please log in or register