Profitstat
Download scriptThis tool is designed as an on-screen dashboard for traders using the MetaTrader platform. Its primary purpose is to provide a real-time summary of trading performance by automatically calculating and displaying your profits and trade counts for the current day and the previous day.
How it Works
The script functions by performing three main actions:
1. Time Tracking The tool starts by identifying the exact boundaries of "today" and "yesterday" based on the current server time. It calculates when yesterday ended and when today began to ensure that every trade is categorized correctly into one of those two specific windows.
2. History Analysis The script automatically scans through your entire trading history. It looks at every closed order and evaluates the closing time:
- If a trade was closed during the current day's timeframe, it adds that profit to the "Today" total and increments the "Today" trade count.
- If a trade was closed during yesterday’s timeframe, it adds that profit to the "Yesterday" total and increments the "Yesterday" trade count.
3. Visual Display Once the calculations are finished, the script updates five text labels on your trading chart. These labels provide a clear, organized list of information:
- Tool Name: Identifies the indicator on your screen.
- Yesterday's Activity: Shows the total number of trades closed yesterday and the total profit/loss achieved (changing color to green for profit or red for loss).
- Today's Activity: Shows the total number of trades closed today and the total profit/loss achieved (similarly changing colors based on performance).
User Experience
Instead of manually calculating your gains or scrolling through your history logs, this script provides an instant "snapshot" of your performance. It sits neatly in the corner of your chart, giving you a constant visual cue of your daily progress and helping you monitor your trading consistency at a glance. When you remove the indicator from your chart, it automatically cleans up the workspace by deleting the labels.
//+------------------------------------------------------------------+
//| Profitstat.mq4 |
//| Copyright © 2012, www.FxAutomated.com |
//| http://www.FxAutomated.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, www.FxAutomated.com"
#property link "http://www.FxAutomated.com"
#property indicator_chart_window
extern color DayIdColor=DodgerBlue;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
ObjectCreate("Label_eaname", OBJ_LABEL, 0, 0, 0); // Creating obj.
ObjectSet("Label_eaname", OBJPROP_CORNER, 0); // Reference corner
ObjectSet("Label_eaname", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("Label_eaname", OBJPROP_YDISTANCE, 20);// Y coordinate
ObjectCreate("Label_yt", OBJ_LABEL, 0, 0, 0); // Creating obj.
ObjectSet("Label_yt", OBJPROP_CORNER, 0); // Reference corner
ObjectSet("Label_yt", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("Label_yt", OBJPROP_YDISTANCE, 45);// Y coordinate
ObjectCreate("Label_yp", OBJ_LABEL, 0, 0, 0); // Creating obj.
ObjectSet("Label_yp", OBJPROP_CORNER, 0); // Reference corner
ObjectSet("Label_yp", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("Label_yp", OBJPROP_YDISTANCE, 60);// Y coordinate
ObjectCreate("Label_tt", OBJ_LABEL, 0, 0, 0); // Creating obj.
ObjectSet("Label_tt", OBJPROP_CORNER, 0); // Reference corner
ObjectSet("Label_tt", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("Label_tt", OBJPROP_YDISTANCE, 75);// Y coordinate
ObjectCreate("Label_tp", OBJ_LABEL, 0, 0, 0); // Creating obj.
ObjectSet("Label_tp", OBJPROP_CORNER, 0); // Reference corner
ObjectSet("Label_tp", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("Label_tp", OBJPROP_YDISTANCE, 90);// Y coordinate
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//------------------------Time calculations----------------------------
int TodaySeconds=(Hour()*3600)+(Minute()*60)+Seconds();
int YesterdayEnd=TimeCurrent()-TodaySeconds;
int YesterdayStart=YesterdayEnd-86400;
//--------------------Analyze trade history------------------------------------
double ProfitToday=0,ProfitYesterday=0;
int YesterdayTrades=0,TodayTrades=0,FirstOnly=0;
for(int h=OrdersHistoryTotal()-1;h>=0;h--) // cycle
{
if(OrderSelect(h,SELECT_BY_POS,MODE_HISTORY)==true) // select next
{
// operations
if(OrderCloseTime()>YesterdayStart){ // trade is young
if(OrderCloseTime()>YesterdayEnd){ ProfitToday=ProfitToday+OrderProfit(); TodayTrades++; }
if(OrderCloseTime()<YesterdayEnd&&OrderCloseTime()>YesterdayStart){ ProfitYesterday=ProfitYesterday+OrderProfit(); YesterdayTrades++; }
} // trade is young
}// select
}// cycle
//----------------------------------Set values-----------------------
color CpColor,CpColor2;
string eanameParameters="Profitstat v1 data";
ObjectSetText("Label_eaname",eanameParameters,15,"Arial",DodgerBlue);
string ytParameters=StringConcatenate("Trades closed yesterday: ",YesterdayTrades);
ObjectSetText("Label_yt",ytParameters,10,"Arial",DayIdColor);
if(ProfitYesterday>0)CpColor=Lime; else CpColor=Red;
string ypParameters=StringConcatenate("Profit yesterday: ",ProfitYesterday," ",AccountCurrency());
ObjectSetText("Label_yp",ypParameters,8,"Arial",CpColor);
string ttParameters=StringConcatenate("Trades closed today: ",TodayTrades);
ObjectSetText("Label_tt",ttParameters,10,"Arial",DayIdColor);
if(ProfitToday>=0)CpColor2=Lime; else CpColor2=Red;
string tpParameters=StringConcatenate("Profit today: ",ProfitToday," ",AccountCurrency());
ObjectSetText("Label_tp",tpParameters,8,"Arial",CpColor2);
//-------------------------------------------------------------------
return(0);
}
//+------------------------------END------------------------------------+
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("Label_eaname"); // Object deletion
ObjectDelete("Label_yt");
ObjectDelete("Label_yp");
ObjectDelete("Label_tt");
ObjectDelete("Label_tp");
Alert("Visit www.fxautomated.com for more forex stuff!");
//----
return(0);
}
Comments