Download MetaTrader 5

Problems with placing market orders - Invalid stops

To add comments, please log in or register
Dobromir Petrov
123
Dobromir Petrov  

Hello,

I have a problem with execution of market orders - they always return error "Invalid stops", though I provide all the necessary data according to https://www.mql5.com/en/docs/constants/structures/mqltraderequest. I use MetaQuates-Demo and I succeed in submitting order of type Instant Execution in the terminal. Here are the screenshots from 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

Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
  • www.mql5.com
Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure - Documentation on MQL5
Achmad Hidayat
15895
Achmad Hidayat  
dspetrov:

Hello,

I have a problem with execution of market orders - they always return error "Invalid stops", though I provide all the necessary data according to https://www.mql5.com/en/docs/constants/structures/mqltraderequest. I use MetaQuates-Demo and I succeed in submitting order of type Instant Execution in the terminal. Here are the screenshots from 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:

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

You need to add request.price, request.tp and request.sl like this :

      request.price = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
      request.tp = request.price+TP*_Point;
      request.sl = request.price-SL*_Point;
JMRodMartins
238
JMRodMartins  

You need to read the documentation from MQL5 and to see the examples. 

Dobromir Petrov
123
Dobromir Petrov  

achidayat, I know that it is going to work in the way you propose, but I think this is something different. In a market order I am not required to provide a price and SL/TP values. This is written in the documentation (the link I included in my post).

JMRodMartins, I wouldn't have asked if I haven't read the documentation and tried a number of times, including examples from there. However, I may have missed something useful. Can you be more concrete about what part of the documentation with what examples to see?

Slava
Moderator
7026
Slava  

And how your problem corresponds with Trading Systems branch? Why no General or Experts Advisors and Automated Trading?


Dobromir Petrov
123
Dobromir Petrov  
stringo:

And how your problem corresponds with Trading Systems branch? Why no General or Experts Advisors and Automated Trading?


A have already asked in General and over a week later there's still no answer...
Rogerio Figurelli
Moderator
45002
Rogerio Figurelli  
Hi Petrov, insert and test achidayat sl/tp posted code, I suggest you use normalizedouble function for prices too.
If this don't work, just post the final code here again to we double check.
Documentation on MQL5: Conversion Functions / NormalizeDouble
Documentation on MQL5: Conversion Functions / NormalizeDouble
  • www.mql5.com
Conversion Functions / NormalizeDouble - Documentation on MQL5
Dobromir Petrov
123
Dobromir Petrov  
figurelli:
Hi Petrov, insert and test achidayat sl/tp posted code, I suggest you use normalizedouble function for prices too.
If this don't work, just post the final code here again to we double check.

Hi figurelli,

I have tried adding the price, sl and tp and as expected the order was sent successfully. This is my 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; 

   request.price = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits);
   request.tp = NormalizeDouble(request.price + 100 * _Point, _Digits);
   request.sl = NormalizeDouble(request.price - 100 * _Point, _Digits);

   MqlTradeResult result;
   OrderSend(request, result);
}

 However, I want to send a simple market order without specifying the price, sl and tp. According to the documentation https://www.mql5.com/en/docs/constants/structures/mqltraderequest this is possible. There it says:

Market Execution

This is a trade order to open a position in the Market Execution mode. It requires to specify the following 5 fields:

  • action
  • symbol
  • volume
  • type
  • type_filling

Also it is possible to specify the "magic" and "comment" field values. 

So I send a request with exactly the same 5 required fields:

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);
}

 As a result it says "Invalid stops". This doesn't make sense! It looks that either the documentation is wrong or there is some bug in the platform... Or I miss something. Do you have any explanation about what happens?

Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
  • www.mql5.com
Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure - Documentation on MQL5
Andrey Barinov
39486
Andrey Barinov  

Hi,

You should always specify the buy/sell price.

You can get it using MqlTick structure and SymolTick function to copy the last quotes inot the structure.

Invalid stops error might be caused by the execution type of your broker. Some brokers (ECN) do not allow placing SL/TP together with the opening order. In this case you should perform your deal in 2 steps.

1. You open a position WITHOUT sl and tp

2. You put your SL and TP using another order send request. (TRADE_ACTION_SLTP)


Hope it helps.

Andrey.

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
Achmad Hidayat
15895
Achmad Hidayat  

In this documentation : https://www.mql5.com/en/docs/constants/structures/mqltraderequest

Do You mean in "Market Execution" section ?

Market Execution

This is a trade order to open a position in the Market Execution mode. It requires to specify the following 5 fields:

  • action
  • symbol
  • volume
  • type
  • type_filling


So the problem is what different of Request Execution mode, Instant Execution mode, Exchange Execution mode, and Market Execution mode? It need explanation.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
  • www.mql5.com
Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure - Documentation on MQL5
Dobromir Petrov
123
Dobromir Petrov  
achidayat:

In this documentation : https://www.mql5.com/en/docs/constants/structures/mqltraderequest

Do You mean in "Market Execution" section ?

Market Execution

This is a trade order to open a position in the Market Execution mode. It requires to specify the following 5 fields:

  • action
  • symbol
  • volume
  • type
  • type_filling


So the problem is what different of Request Execution mode, Instant Execution mode, Exchange Execution mode, and Market Execution mode? It need explanation.

Yes, I mean Market Execution section.

So it looks that I am not in Market Execution mode and that's why I need more fields filled (price, sl and tp) - is this correct?

If this is the case, then how can I change the execution mode to Market Execution?

To add comments, please log in or register