Discussion of article "Processing of trade events in Expert Advisor using the OnTrade() function" - page 2

 
Automated-Trading:

The OnChartEvent is used in the article Creating Active Control Panels in MQL5 for Trading.

 

I mean : OnTrade()  

should  be OnTrade( id,  para1,para2.....) 

 

Could someone please improve the code given in the article to process the event of closing a position by stop loss or take profit?

Has it turned out to be unnecessary for the last 2.5 years since the publication of the article?

 
  • Positions
    1. Open
    2. Add
    3. Modify (change "Stop Loss" and "Take Profit")
    4. Reverse
    5. Close entire position
    6. Close part of position
  • Pending Order
    1. Place
    2. Modify

It is recommended to translate https://www.mql5.com/en/articles/211 Orders, Positions and Deals in MetaTrader 5.

Firstly, you need to find out which of the 6+2 above corresponds to Orders, Positions and Deals!

Orders, Positions and Deals in MetaTrader 5
Orders, Positions and Deals in MetaTrader 5
  • 2011.02.01
  • MetaQuotes Software Corp.
  • www.mql5.com
Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.
 
for MQL4, what can you think of that would be similar to OnTrade?
 
Serhiy Dotsenko:
for MQL4, what can you think of that would be similar to OnTrade?

Check on each tick OrdersTotal() and OrdersHistoryTotal() - if the figure has changed - call OnTrade().

 
thanks, I also came to something similar myself ) I thought there is something exactly event-driven ) as it will be possible to react to manual ontrade only on the 2nd tick )
 

Hi ,


thanks for writhing this aritce... I played a litte around with your code. But at first I have the basic problem, that I am worling with positions. That means:

My EA is setting a buyorder in the backtest  and the Ontrade function is called several times as described. But your code is only checken OrdersTotal. The strange thing is: the result of this function is always 0. After placing my Order I only have a Buy position, which is not handled of your code, isnt it ?

Whats wrong here?

 
Serhiy Dotsenko:
for MQL4, what can you think of that would be similar to OnTrade?
Generate OnChartEvent() before making a trade operation, and in it try to get the result of the trade operation.... And you can think of a type, according to which OnChartEvent() should be called the necessary number of times...
 
Denis Kirichenko:
Generate OnChartEvent() before making a trade operation, and in it try to get the result of the trade operation.... And you can think of a type, according to which OnChartEvent() should be called the necessary number of times...

If there are no graphic elements, why do we need such a variant? In my opinion, it's unnecessary...

 
Thanks for the article, of course. Saved me some time. Because I didn't have to search somewhere about these events. There is zero information in the help, and to write to the support constantly is also time. That's why the article is relevant. But the code is cramped, to be honest. I had to transfer it to myself and bring it to a normal form. And then I had to think it over.