Examples: Events in МetaТrader 4

 

New article Events in МetaТrader 4 has been published:

The article deals with programmed tracking of events in the МetaТrader 4 Client Terminal, such as opening/closing/modifying orders, and is targeted at a user who has basic skills in working with the terminal and in programming in MQL 4.

Author: Andrey Khatimlianskii

 
Great article but...How does the following line apply to using this code?:

Warning: All rights on these materials are reserved by MetaQuotes Software Corp. Copying or reprinting of these materials in whole or in part is prohibited.
 
wheel_of_fire:
Great article but...How does the following line apply to using this code?:

Warning: All rights on these materials are reserved by MetaQuotes Software Corp. Copying or reprinting of these materials in whole or in part is prohibited.

Please don't worry. You can freely use all codes attached to articles. Otherwise, authors wouldn't attach them. But, if you're going to mention this article anywhere, you must make a proper reference to it. That's all.
Sincerely.
 

Interesting article Andre. Your method of obtaining closed reason is by inspection of order comment.

Is this 100% generic solution that will apply to brokers where I can trade using EA's?

This is important to know otherwise failure is likely.

If cannot warranty that order comment will be modified and thus your method is used then is there method which uses closed order data fields: profit, openPrice,closePrice, TP,SL,closeTime,expiryTime... ?

Thank you Andre.

 
ukt:

Interesting article Andre. Your method of obtaining closed reason is by inspection of order comment.

Is this 100% generic solution that will apply to brokers where I can trade using EA's?

It is better to analyse a OrderClosePrice():

if ( MathAbs( OrderClosePrice() - OrderStopLoss() ) < Point ) // closed by SL
if ( MathAbs( OrderClosePrice() - OrderTakeProfit() ) < Point ) // closed by TP
 
How can I add and alert when I open a buy or sell position? Is it possible? Thanks
 

Hi, is it possible to retrieve the Order information (i.e. ticket number, closed price ...) when an event is triggered?

int start()
{
    CheckEvents( MagicNumber );
    OrderInfoObj orderInfo;
    if ( (orderInfo = eventBuyClosed_SL) > 0 )
        Alert( Symbol(), ": Buy position was closed by StopLoss!", orderInfo.ticket, orderInfo.closedPrice ... );
    ....
return(0)

}


 

Awsome article, Thank you sir!

 
Very good article.  But I noticed when I tried to use it inside a code that if I open a Sell Stop and then the Sell Stop is activated and becomes a Sell and there is a Stop Loss there is no event triggered.
Reason: