2
//+------------------------------------------------------------------+ //| TradingReport.mq4 | //| Relentless Trader | //| | //+------------------------------------------------------------------+ #property copyright "Relentless Trader" #property link "https://twitter.com/rlentlesstrader" #property version "1.00" #property strict extern string Remark = "== Trading Report Frequency =="; extern ENUM_TIMEFRAMES ReportFrequency = PERIOD_M15; datetime CandleTime; string MailSubject; string MailText; double OpenOrdersProfit = 0.0; int i; string PositionType; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- CandleTime = iTime(NULL,ReportFrequency,0); Comment("TradingReport_01"); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- Comment(""); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- if (CandleTime != iTime(NULL,ReportFrequency,0)) //We have a new candle. Sending a new Trading Report { CandleTime = iTime(NULL,ReportFrequency,0);

Metatrader Expert Advisor - eMail Trading Report

Embed Size (px)

Citation preview

Page 1: Metatrader Expert Advisor - eMail Trading Report

//+------------------------------------------------------------------+

//| TradingReport.mq4 |

//| Relentless Trader |

//| |

//+------------------------------------------------------------------+

#property copyright "Relentless Trader"

#property link "https://twitter.com/rlentlesstrader"

#property version "1.00"

#property strict

extern string Remark = "== Trading Report Frequency ==";

extern ENUM_TIMEFRAMES ReportFrequency = PERIOD_M15;

datetime CandleTime;

string MailSubject;

string MailText;

double OpenOrdersProfit = 0.0;

int i;

string PositionType;

//+------------------------------------------------------------------+

//| Expert initialization function |

//+------------------------------------------------------------------+

int OnInit()

{

//---

CandleTime = iTime(NULL,ReportFrequency,0);

Comment("TradingReport_01");

//---

return(INIT_SUCCEEDED);

}

//+------------------------------------------------------------------+

//| Expert deinitialization function |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{

//---

Comment("");

}

//+------------------------------------------------------------------+

//| Expert tick function |

//+------------------------------------------------------------------+

void OnTick()

{

//---

if (CandleTime != iTime(NULL,ReportFrequency,0)) //We have a new candle. Sending a new Trading Report

{

CandleTime = iTime(NULL,ReportFrequency,0);

Page 2: Metatrader Expert Advisor - eMail Trading Report

MailSubject = "Account: "+IntegerToString(AccountNumber())+" - Trading Report "+TimeToString(CandleTime,TIME_DATE)+"

"+TimeToString(CandleTime,TIME_MINUTES);

MailText = "\n\nTrading Report for Account: "+IntegerToString(AccountNumber())+" \n\n";

MailText = MailText+"Balance:\t"+DoubleToStr(AccountBalance(),2)+" \n";

MailText = MailText+"Equity:\t\t"+DoubleToStr(AccountEquity(),2)+" \n";

MailText = MailText+"Used Margin:\t"+DoubleToStr(AccountMargin(),2)+" \n";

MailText = MailText+"Free Margin:\t"+DoubleToStr(AccountFreeMargin(),2)+" \n";

MailText = MailText+"Open Orders:\t"+IntegerToString(OrdersTotal())+" \n\n";

MailText = MailText+"Order\t\t\tOpen Time\t Type Size Symbol\tProfit\tOpen Price\n";

OpenOrdersProfit = 0.0;

for(i=0;i<OrdersTotal();i++)

{

if(OrderSelect(i,SELECT_BY_POS)==false) continue;

MailText = MailText+IntegerToString(OrderTicket())+"\t";

MailText = MailText+TimeToString(OrderOpenTime(),TIME_DATE)+" "+TimeToString(OrderOpenTime(),TIME_MINUTES)+"\t";

switch(OrderType())

{

case OP_BUY: PositionType = "Buy";break;

case OP_SELL: PositionType = "Sell";break;

case OP_BUYLIMIT: PositionType = "BuyLimit";break;

case OP_BUYSTOP: PositionType = "BuyStop";break;

case OP_SELLLIMIT: PositionType = "SellLimit";break;

case OP_SELLSTOP: PositionType = "SellStop";break;

default: PositionType = "Unknown";break;

}

MailText = MailText+PositionType+"\t";

MailText = MailText+DoubleToStr(OrderLots(),2)+"\t";

MailText = MailText+OrderSymbol()+"\t";

MailText = MailText+DoubleToStr(OrderProfit(),2)+"\t";

MailText = MailText+DoubleToStr(OrderOpenPrice(),5)+"\n";

OpenOrdersProfit = OpenOrdersProfit + OrderProfit();

}

MailText = MailText+"\n\nCurrent Open Positions P/L: "+DoubleToStr(OpenOrdersProfit,2)+"\n";

SendMail(MailSubject,MailText);

}

}

//+------------------------------------------------------------------+