Download MetaTrader 5

Examples: Events in МetaТrader 4

To add comments, please log in or register
Deposit to your account in any convenient way. There are 4 of them here!
MetaQuotes Software Corp.
Moderator
181197
MetaQuotes Software Corp. 2007.04.12 13:30 

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 2007.04.16 19:26  
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 2007.04.17 06:14  
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 2007.08.05 19:15  

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 2008.11.18 06:06  
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 2010.04.08 11:09  
How can I add and alert when I open a buy or sell position? Is it possible? Thanks
MQL4 Comments
16319
MQL4 Comments 2010.08.17 17:07  

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