Download MetaTrader 5

Examples: Events in МetaТrader 4

To add comments, please log in or register
MetaQuotes Software Corp.
Moderator
187122
MetaQuotes Software Corp.  

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

MQL4 Comments
16319
MQL4 Comments  
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.
Maria Sountsova
81
Maria Sountsova  
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.
MQL4 Comments
16319
MQL4 Comments  

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.

Andrey Khatimlianskii
136
Andrey Khatimlianskii  
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
Eric Pedron
241
Eric Pedron  
How can I add and alert when I open a buy or sell position? Is it possible? Thanks
MQL4 Comments
16319
MQL4 Comments  

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)

}


To add comments, please log in or register