Discussion of article "Step-by-Step Guide to Writing an Expert Advisor in MQL5 for Beginners" - page 6

 

Good afternoon!

I am currently learning how to write Expert Advisors on the example of this article and I have encountered the following problem - when trying to send a request for a trade I get error 10014 - wrong volume. I checked the maximum allowable volume for the transaction SYMBOL_VOLUME_MAX - I get back 0. But at the same time manually deals are opened normally.

Can you tell me what I'm doing wrong or where to look? I use the code of the Expert Advisor, which is attached in the article.

Thank you.

Документация по MQL5: Стандартные константы, перечисления и структуры / Состояние окружения / Информация об инструменте
Документация по MQL5: Стандартные константы, перечисления и структуры / Состояние окружения / Информация об инструменте
  • www.mql5.com
Стандартные константы, перечисления и структуры / Состояние окружения / Информация об инструменте - Документация по MQL5
 
thanks ur artical.
 

Hi,

code looks great but when i try it I get this error

 2011.11.13 23:39:58 2011.11.01 14:20:00   Alert: The Sell order request could not be completed -error:4756
 2011.11.13 23:39:58 2011.11.01 14:20:00   failed instant sell 1.00 EURUSD at 1.36833 sl: 1.37133 tp: 1.35833 [Invalid request]

 

No trades are executed.

Could someone help fixing?

Thanks

 
Financialabs:

Hi,

code looks great but when i try it I get this error

 2011.11.13 23:39:58 2011.11.01 14:20:00   Alert: The Sell order request could not be completed -error:4756
 2011.11.13 23:39:58 2011.11.01 14:20:00   failed instant sell 1.00 EURUSD at 1.36833 sl: 1.37133 tp: 1.35833 [Invalid request]

 

No trades are executed.

Could someone help fixing?

Thanks

 

I asked the same question and no one replied.

I have found it.

It is a bug. You have to add a line of code 

ZeroMemory(mrequest); 

that line should be before the mrequest.action=...  mrequest.price=... etc. lines.

 

Hello.

Thank you very much for the detailed and clear guide.

I have a problem. The programme compiles, but at the first attempt to create a request the following error appears: "Request to set Sell order failed - error code:4756"

I could not find anything in the documentation. Can you tell me what I can do about it or where I can find information?

Документация по MQL5: Стандартные константы, перечисления и структуры / Коды ошибок и предупреждений
Документация по MQL5: Стандартные константы, перечисления и структуры / Коды ошибок и предупреждений
  • www.mql5.com
Стандартные константы, перечисления и структуры / Коды ошибок и предупреждений - Документация по MQL5
 
Alfff:

I have a problem. The programme compiles, but at the first attempt to create a request the following error appears: "Request to set Sell order failed - error code:4756"

I could not find anything in the documentation. Can you tell me what can be done about this or where to find information?

Fixed, download the updated version of the Expert Advisor.

The problem was in the mrequest structure, it should be zeroed beforehand using the ZeroMemory function. Before the lines with "mrequest.action=TRADE_ACTION_DEAL;" (p. 199 and 245) you should add "ZeroMemory(mrequest);".

 
senerzen:

I asked the same question and no one replied.

I have found it.

It is a bug. You have to add a line of code 

ZeroMemory(mrequest); 

that line should be before the mrequest.action=...  mrequest.price=... etc. lines.

Thank you, the bug is fixed.
Get in touch with developers using Service Desk!
  • www.mql5.com
We therefore attach great importance to all user reports about issues in our programs and try to answer each one of them.
 
papaklass:
Is it always necessary to do this, i.e. to zeroise the request structure before the request?
Before sending a request, all fields of the structure must be initialised (in this case it is done using the ZeroMemory function, although you can do it element by element), initialisation must be done after the structure is declared.
 
Automated-Trading:
Before sending a request, all fields of the structure must be initialised (in this case it is done using the ZeroMemory function, although you can do it element by element), initialisation must be done after the structure is declared.

Does it say so in the Reference Manual? (I don't have a chance to check it now).

It turns out that it is enough to declare a structure type variable once at the global level of the program, initialise it once and not to return to the question of using the ZeroMemory function again?

 
Yedelkin:

Does the Handbook say anything about this? (I don't have a chance to check it now)

Any variable is not forced to be zeroed when it is declared. It is the programmer who needs to clean/assign all variables himself before using them.

Using uninitialised (or incompletely) variables (especially structures) is a very common mistake in programming.

It turns out that it is enough to declare a variable of structure type once at the global level of the program, initialise it once and not to return to the question of using ZeroMemory function again?

It is better to initialise variables correctly instead of fighting (uselessly and more dangerous) with initialisation by bringing it to the global level.

It's so easy to ask yourself the question "why do I think someone will initialise variables and especially complex structures for me"?

It is very convenient to zero out structures without inconvenient ZeroMemory when declaring so:

   MqlTick my={0};