Discussion of article "Library for easy and quick development of MetaTrader programs MetaTrader (part XXXII): Pending trading requests - placing orders under certain conditions"

To add comments, please log in or register
MetaQuotes
Moderator
218924
MetaQuotes  

New article Library for easy and quick development of MetaTrader programs MetaTrader (part XXXII): Pending trading requests - placing orders under certain conditions has been published:

We continue the development of the functionality allowing users to trade using pending requests. In this article, we are going to implement the ability to place pending orders under certain conditions.

The pending request object features the array storing all of its activation conditions. The trading management class (namely, its timer) allows constant viewing of the list of pending trading requests. When it is time to activate a pending trading request (all predefined activation conditions are met), a trading order is sent to the server. Its parameters are set in the triggered pending request.

To open positions, you just need to control the occurrence of specified conditions. As soon as they occur, the trading order to open a position is sent to the server.
However, there is one complication regarding placing pending orders using pending request objects: an order is placed at a distance from the price, while a position is set at the appropriate current price.
Therefore, in order to work with placing pending orders under certain conditions, we also need to consider the distance of placing the pending order. This entails a question: when creating a pending request, we specify the distance of a future pending order. BUT... from which price? From the price present at the moment of a pending request? Or from the price present when fulfilling all conditions set in the request object for its activation? After all, at the moment all conditions are met, the price may move far from the level the pending request was created at, while we are able to know the future price only in one case — when the only activation condition of a pending request is a specified price value. In other cases, the future price we need to set an order from is unknown.

Author: Artyom Trishkin

Laurent Soudron
1436
Laurent Soudron  

I deleted the previous DoEasy directory in Include on my computer, then I downloaded the MQL5.zip file of this article.

While compiling TestDoEasyPart32.mq5, I have 61 compilation errors 😱


It's just that a / character is missing at the beginning of line 114 of the Message.mqh file in the CMessage::ToMail function (see pink arrow on the capture above)

Once the slash character is added to define the comment line, no more compilation problems.

I also had to change the read-only flag of the files in the DoEasy directory so that the change could be saved.

Artyom Trishkin
Moderator
56703
Artyom Trishkin  
Laurent Soudron :

I deleted the previous DoEasy directory in Include on my computer, then I downloaded the MQL5.zip file of this article.

While compiling TestDoEasyPart32.mq5, I have 61 compilation errors  😱


It's just that a / character is missing at the beginning of line 114 of the Message.mqh file in the CMessage::ToMail function (see pink arrow on the capture above)

Once the slash character is added to define the comment line, no more compilation problems.

I also had to change the read-only flag of the files in the DoEasy directory so that the change could be saved.

This annoying mistake was made when translating the text of the article and comments in the code from Russian into English.

In the source code attached to the article in the Russian part of the mql5.com resource, there is no such error:


Thank you for your attentiveness and concern.

---------------------------------

Эта досадная ошибка была внесена при переводе текста статьи и комментариев в коде с русского языка на английский.
В исходниках, приложенных к статье в русской части ресурса mql5.com, такой ошибки нету.

Спасибо за вашу внимательность и неравнодушие.
marco
12
marco  

Hello,

there is an error about wrong Order Type Filling Type on my IC Markets Demo Account (MT5).

I debugged your code and found that initialization seems to be ok with ORDER_FILLING_IOC on my account. However, when the line engine.OpenBuy(lot,Symbol(),magic,stoploss,takeprofit); in the EA is called and opening (or closing) a position is tried, then the filling type is not properly set (see below).

I made a quick (and dirty) solution to make it work. You can see the changes by making a diff with your files in the 2 files I attached. Please replace my code with proper code.


Trading.mqh around line 2646:
I changed:
res=trade_obj.OpenPosition(type,this.m_request.volume,this.m_request.sl,this.m_request.tp,magic,comment,deviation,    this.m_request.type_filling    ); //instead of type_filling


TradeObj.mqh

CTradeObj::ClosePosition:
I added:
this.m_request.type_filling=ORDER_FILLING_IOC;

CTradeObj::SetOrder:
I added:
   ENUM_ORDER_TYPE_FILLING order_type_filling=(ENUM_ORDER_TYPE_FILLING)::OrderGetInteger(ORDER_TYPE_FILLING);
   this.m_request.type_filling=  (type_filling==WRONG_VALUE ? order_type_filling : ORDER_FILLING_IOC);

Files:
TradeObj.mqh 253 kb
Trading.mqh 445 kb
Artyom Trishkin
Moderator
56703
Artyom Trishkin  
marco :

Hello,

there is an error about wrong Order Type Filling Type on my IC Markets Demo Account (MT5).

I debugged your code and found that initialization seems to be ok with ORDER_FILLING_IOC on my account. However, when the line engine.OpenBuy(lot,Symbol(),magic,stoploss,takeprofit); in the EA is called and opening (or closing) a position is tried, then the filling type is not properly set (see below).

I made a quick (and dirty) solution to make it work. You can see the changes by making a diff with your files in the 2 files I attached. Please replace my code with proper code.


Trading.mqh around line 2646:
I changed:
res=trade_obj.OpenPosition(type,this.m_request.volume,this.m_request.sl,this.m_request.tp,magic,comment,deviation,    this.m_request.type_filling    ); //instead of type_filling


TradeObj.mqh

CTradeObj::ClosePosition:
I added:
this.m_request.type_filling=ORDER_FILLING_IOC;

CTradeObj::SetOrder:
I added:
    ENUM_ORDER_TYPE_FILLING order_type_filling=(ENUM_ORDER_TYPE_FILLING)::OrderGetInteger(ORDER_TYPE_FILLING);
   this.m_request.type_filling=  (type_filling==WRONG_VALUE ? order_type_filling : ORDER_FILLING_IOC);

Thanks. In subsequent articles, this has already been fixed.

Спасибо. В последующих статьях это уже исправлено.

marco
12
marco  
Artyom Trishkin:

Thanks. In subsequent articles, this has already been fixed.

Спасибо. В последующих статьях это уже исправлено.

I tried the code from part 34 but the error still persists: 


I also tried to use the EA from part 34 with the DoEasy library from your latest article part 43 but this the library part 43 is incompatible with the EA of part 34 (changed engine.OnTimer method etc.). 

What do I make wrong? : ) Spasibo!

Artyom Trishkin
Moderator
56703
Artyom Trishkin  
marco :

I tried the code from part 34 but the error still persists: 


I also tried to use the EA from part 34 with the DoEasy library from your latest article part 43 but this the library part 43 is incompatible with the EA of part 34 (changed engine.OnTimer method etc.). 

What do I make wrong? : ) Spasibo!

What exactly are you doing to get this error? Which EA do you use? Is this test advisor from the article unchanged?

Что именно вы делаете чтобы получить эту ошибку? Какой используете советник? Это тестовый советник из статьи без изменений?

marco
12
marco  
Artyom Trishkin:

What exactly are you doing to get this error? Which EA do you use? Is this test advisor from the article unchanged?

Что именно вы делаете чтобы получить эту ошибку? Какой используете советник? Это тестовый советник из статьи без изменений?

I press "Buy" or "Sell" without "P" or "T" activated.

I used the unchanged EA of part 34.

Artyom Trishkin
Moderator
56703
Artyom Trishkin  
marco :

I press "Buy" or "Sell" without "P" or "T" activated.

I used the unchanged EA of part 34.

Are there any such errors on MetaQuotes-Demo?

marco
12
marco  
Artyom Trishkin:

Are there any such errors on MetaQuotes-Demo?

No errors on MetaQuotes Demo. Interesting...
And now?

Artyom Trishkin
Moderator
56703
Artyom Trishkin  
marco :

No errors on MetaQuotes Demo. Interesting...
And now?

So - I need to connect to the trading server in which you found errors, and find a reason to fix the behavior.

Tell me the details for registering a demo account.

12
To add comments, please log in or register