jumpa kat website jiran...entah boleh guna ke tak
//+------------------------------------------------------------------+
//| MailAlertOnOrderClose.mq4 |
//|
[email protected] |
//| |
//+------------------------------------------------------------------+
//Based on Nicholishen's original alerter EA at
//http://www.forex-tsd.com/metatrader-4/1125-code-send-email-alerts-when-closed-trades.html
//
int k;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
for(int i=0;i<1000;i++){
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){
if(OrderSymbol()==Symbol() ){
k++;
**
**else{
break;
**
**
Comment("Init() Trades Count = ",k);
return(0);
**
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
**
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int f =0;
for(int i=0;i<10000;i++){
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){
if(OrderSymbol()==Symbol() /*&& OrderMagicNumber()==MAGICMA && OrderComment() ==Cmt(Period())*/ ){
f++;
**
**else{
break;
**
**
Comment(" Trades in History ",f," Init cnt ",k );
if(k < f){
string ordertyp;
OrderSelect(f,SELECT_BY_POS,MODE_HISTORY);
double x=OrderOpenPrice(),y=OrderClosePrice(),pips;
pips =y - x;
pips =pips * 10000;
if(pips < 0)pips = - pips;
if(OrderType()==0)ordertyp="BUY";
if(OrderType()==1)ordertyp="SELL";
SendMail("CLOSE pr: "+DoubleToStr(OrderProfit(),2)+", bal: "+DoubleToStr(AccountBalance(),2)+", eq: "+DoubleToStr(AccountEquity(),2)+"",
"Symbol: "+Symbol()+" "+ordertyp+" "+OrderMagicNumber()+" \n"+
"Comment: "+OrderComment()+" \n"+
"Ticket#: "+OrderTicket()+" \n"+
"Size: "+DoubleToStr(OrderLots(),2)+" \n"+
"OpenTime: "+TimeToStr(OrderOpenTime())+" \n"+
"Close Time: "+TimeToStr(OrderCloseTime())+" \n"+
"Open: "+DoubleToStr(OrderOpenPrice(),5)+" \n"+
"Close: "+DoubleToStr(OrderClosePrice(),5)+" \n"+
"Profit: "+DoubleToStr(OrderProfit(),2)+" \n"+
"Pips: "+DoubleToStr(pips,1)+" \n\n"+
"Balance: "+DoubleToStr(AccountBalance(),2)+" \n"+
"Used Margin: "+DoubleToStr(AccountMargin(),2)+" \n"+
"Free Margin: "+DoubleToStr(AccountFreeMargin(),2)+" \n"+
"Equity: "+DoubleToStr(AccountEquity(),2)+" \n"+
"Open Orders: "+DoubleToStr(OrdersTotal(),0)+" \n\n"+
"Broker: "+AccountCompany()+" \n"+
"Leverage: "+AccountLeverage()+"" );
k++;
**
return;
**
//----
//+------------------------------------------------------------------+