Author: Copyright � 2009, Vladimir Hlystov
Balance

This script functions as a real-time portfolio monitor for MetaTrader 4, designed to give traders a clear, visual overview of their active positions and total profitability across specific currency pairs. Instead of looking at complex charts, it aggregates data and displays it as a clean text dashboard directly on your trading screen.

Core Functionality

The script scans all currently active trades in your account and filters them into five primary categories: EURUSD, USDCHF, USDJPY, GBPUSD, and USDCAD. For each of these specific pairs, the script performs the following actions:

  • Profit Calculation: It automatically calculates the floating profit or loss for each individual currency pair.
  • Trade Details: It lists the specific details for every open trade within that pair, including the trading volume (lots) and whether the position is a "Buy" or a "Sell."
  • Visual Feedback: To make the information easy to read at a glance, it uses dynamic coloring. If a currency pair's total profit is positive, the text appears in Green; if it is in a loss, the text appears in Crimson.

Dashboard Features

The script organizes this information into a structured on-screen display:

  1. Individual Pair Breakdowns: You will see a dedicated line for each of the five supported currencies. If there are no active trades for a specific pair, that line remains empty, keeping the workspace clean.
  2. Total Portfolio Balance: At the bottom of the list, the script calculates a "Balance All" figure. This represents the combined profit or loss of all the tracked pairs simultaneously.
  3. Free Margin: Alongside the total balance, it displays your current "free margin," allowing you to see how much liquidity is available for new trades.
  4. Live Clock: The script includes a time display that updates automatically, showing the current hour and minute in a standardized format.

User Experience

The goal of this tool is to simplify high-level account management. By summarizing various open positions into a consolidated list of totals and active details, it allows a trader to monitor their diverse portfolio's health instantly without having to manually sum up profits across multiple charts.

Price Data Components
Series array that contains open time of each bar
Orders Execution
Checks for the total of open orders
9 Views
0 Downloads
0 Favorites
Balance
//+------------------------------------------------------------------+
//|                                                      Balance.mq4 |
//|                               Copyright © 2009, Õëûñòîâ Âëàäèìèð |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Vladimir Hlystov"
#property link      "cmillion@narod.ru"
 
#property indicator_chart_window
extern int srift = 30;
extern color colorPLUS = Green;
extern color colorMINUS = Crimson;
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   ObjectCreate ("Balance1", OBJ_LABEL, 0, 0, 0);// Ñîçäàíèå îáú.
   ObjectSet    ("Balance1", OBJPROP_XDISTANCE, 10);      
   ObjectSet    ("Balance1", OBJPROP_CORNER, 0); //óãîë_âûâîäà_îðäåðîâ
 
   ObjectCreate ("Balance2", OBJ_LABEL, 0, 0, 0);// Ñîçäàíèå îáú.
   ObjectSet    ("Balance2", OBJPROP_XDISTANCE, 10);      
   ObjectSet    ("Balance2", OBJPROP_CORNER, 0); //óãîë_âûâîäà_îðäåðîâ
 
   ObjectCreate ("Balance3", OBJ_LABEL, 0, 0, 0);// Ñîçäàíèå îáú.
   ObjectSet    ("Balance3", OBJPROP_XDISTANCE, 10);      
   ObjectSet    ("Balance3", OBJPROP_CORNER, 0); //óãîë_âûâîäà_îðäåðîâ
 
   ObjectCreate ("Balance4", OBJ_LABEL, 0, 0, 0);// Ñîçäàíèå îáú.
   ObjectSet    ("Balance4", OBJPROP_XDISTANCE, 10);      
   ObjectSet    ("Balance4", OBJPROP_CORNER, 0); //óãîë_âûâîäà_îðäåðîâ
 
   ObjectCreate ("Balance5", OBJ_LABEL, 0, 0, 0);// Ñîçäàíèå îáú.
   ObjectSet    ("Balance5", OBJPROP_XDISTANCE, 10);      
   ObjectSet    ("Balance5", OBJPROP_CORNER, 0); //óãîë_âûâîäà_îðäåðîâ
 
   ObjectCreate ("Balance all", OBJ_LABEL, 0, 0, 0);// Ñîçäàíèå îáú.
   ObjectSet    ("Balance all", OBJPROP_XDISTANCE, 10);      
   ObjectSet    ("Balance all", OBJPROP_YDISTANCE, 10);
   ObjectSet    ("Balance all", OBJPROP_CORNER, 3); //óãîë_âûâîäà_îðäåðîâ
 
   ObjectCreate ("TIME", OBJ_LABEL, 0, 0, 0);// Ñîçäàíèå îáú.
   ObjectSet    ("TIME", OBJPROP_XDISTANCE, 10);      
   ObjectSet    ("TIME", OBJPROP_YDISTANCE, 0);
   ObjectSet    ("TIME", OBJPROP_CORNER, 1); //óãîë_âûâîäà_îðäåðîâ
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete ("Balance1");
   ObjectDelete ("Balance2");
   ObjectDelete ("Balance3");
   ObjectDelete ("Balance4");
   ObjectDelete ("Balance5");
   ObjectDelete ("Balance all");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   color  color_t;
   string Balance;
   double Balance_USDÑHF,
          Balance_USDJPY,
          Balance_EURUSD,
          Balance_GBPUSD,
          Balance_USDCAD;
   string tip_EURUSD,
          tip_GBPUSD,
          tip_USDCAD,
          tip_USDÑHF,
          tip_USDJPY;
   int    n;
   for (int i=0; i<OrdersTotal(); i++)// Ïî âñåì îðäåðàì òåðìèíàëà
   {
      if((OrderSelect(i, SELECT_BY_POS)==true)) //Åñëè åñòü ñëåäóþù è íàøà âàë.ïàðà
      { 
         if (OrderType()<2)  //Buy èëè Sell
         {
            if (OrderSymbol()=="EURUSD") {Balance_EURUSD = Balance_EURUSD + OrderProfit(); tip_EURUSD = tip_EURUSD + "     "+DoubleToStr(OrderLots(),2); if (OrderType()==0) tip_EURUSD = tip_EURUSD + "  Buy  "; else tip_EURUSD = tip_EURUSD + "  Sell ";}
            if (OrderSymbol()=="GBPUSD") {Balance_GBPUSD = Balance_GBPUSD + OrderProfit(); tip_GBPUSD = tip_GBPUSD + "     "+DoubleToStr(OrderLots(),2); if (OrderType()==0) tip_GBPUSD = tip_GBPUSD + "  Buy  "; else tip_GBPUSD = tip_GBPUSD + "  Sell ";}
            if (OrderSymbol()=="USDCAD") {Balance_USDCAD = Balance_USDCAD + OrderProfit(); tip_USDCAD = tip_USDCAD + "     "+DoubleToStr(OrderLots(),2); if (OrderType()==0) tip_USDCAD = tip_USDCAD + "  Buy  "; else tip_USDCAD = tip_USDCAD + "  Sell ";}
            if (OrderSymbol()=="USDCHF") {Balance_USDÑHF = Balance_USDÑHF + OrderProfit(); tip_USDÑHF = tip_USDÑHF + "     "+DoubleToStr(OrderLots(),2); if (OrderType()==0) tip_USDÑHF = tip_USDÑHF + "  Buy  "; else tip_USDÑHF = tip_USDÑHF + "  Sell ";}
            if (OrderSymbol()=="USDJPY") {Balance_USDJPY = Balance_USDJPY + OrderProfit(); tip_USDJPY = tip_USDJPY + "     "+DoubleToStr(OrderLots(),2); if (OrderType()==0) tip_USDJPY = tip_USDJPY + "  Buy  "; else tip_USDJPY = tip_USDJPY + "  Sell ";}
         }
      }
   }
   n = 0;
   if (StringLen(tip_EURUSD)>1) {
      if (Balance_EURUSD>=0) color_t = colorPLUS; else color_t = colorMINUS;
      ObjectSetText("Balance1","EURUSD  "+DoubleToStr(Balance_EURUSD,2)+" "+tip_EURUSD,srift,"Arial",color_t);
      ObjectSet    ("Balance1", OBJPROP_YDISTANCE, n*(srift+srift/5));
      n = n + 1;}
   else ObjectSetText("Balance1"," ",0,"Arial",0);
   if (StringLen(tip_USDÑHF)>1) {
      if (Balance_USDÑHF>=0) color_t = colorPLUS; else color_t = colorMINUS;
      ObjectSetText("Balance2","USDCHF  "+DoubleToStr(Balance_USDÑHF,2)+" "+tip_USDÑHF,srift,"Arial",color_t);
      ObjectSet    ("Balance2", OBJPROP_YDISTANCE, n*(srift+srift/5));
      n = n + 1;}
   else ObjectSetText("Balance2"," ",0,"Arial",0);
   if (StringLen(tip_USDJPY)>1){
      if (Balance_USDJPY>=0) color_t = colorPLUS; else color_t = colorMINUS;
      ObjectSetText("Balance3","USDJPY   "+DoubleToStr(Balance_USDJPY,2)+" "+tip_USDJPY,srift,"Arial",color_t);
      ObjectSet    ("Balance3", OBJPROP_YDISTANCE, n*(srift+srift/5));
      n = n + 1;}
   else ObjectSetText("Balance3"," ",0,"Arial",0);
   if (StringLen(tip_GBPUSD)>1){
      if (Balance_GBPUSD>=0) color_t = colorPLUS; else color_t = colorMINUS;
      ObjectSetText("Balance4","GBPUSD  "+DoubleToStr(Balance_GBPUSD,2)+" "+tip_GBPUSD,srift,"Arial",color_t);
      ObjectSet    ("Balance4", OBJPROP_YDISTANCE, n*(srift+srift/5));
      n = n + 1;}
   else ObjectSetText("Balance4"," ",0,"Arial",0);
   if (StringLen(tip_USDCAD)>1){
      if (Balance_USDCAD>=0) color_t = colorPLUS; else color_t = colorMINUS;
      ObjectSetText("Balance5","USDCAD  "+DoubleToStr(Balance_USDCAD,2)+" "+tip_USDCAD,srift,"Arial",color_t);
      ObjectSet    ("Balance5", OBJPROP_YDISTANCE, n*(srift+srift/5));
      n = n + 1;}   
   else ObjectSetText("Balance5"," ",0,"Arial",0);
   if (Balance_USDCAD+Balance_GBPUSD+Balance_USDJPY+Balance_USDÑHF+Balance_EURUSD>=0) color_t = colorPLUS; else color_t = colorMINUS;
   ObjectSetText("Balance all","Balance  "+DoubleToStr(Balance_USDCAD+Balance_GBPUSD+Balance_USDJPY+Balance_USDÑHF+Balance_EURUSD,2)+"    free "+DoubleToStr(AccountFreeMargin(),2),srift*2,"Arial",color_t);   
   ObjectSetText("TIME",TimeW(CurTime()),srift*2,"Arial",color_t);   
return(0);
}
//+------------------------------------------------------------------+
string TimeW(int taim)
{
   string sTime;
   int HH=TimeHour(taim);   // Hour                  
   int MM=TimeMinute(taim); // Minute   
 
   if (HH<10) sTime = sTime+"0"+DoubleToStr(HH,0);
   else sTime = sTime+DoubleToStr(HH,0);
   if (MM<10) sTime = sTime+":0"+DoubleToStr(MM,0);
   else sTime = sTime+":"+DoubleToStr(MM,0);
   return(sTime);
}
//+------------------------------------------------------------------+

Comments