Author: ��� ����� �. aka KimIV
i-BalEq

This tool is a specialized financial tracking indicator designed to provide a visual representation of your account's monetary health over time. Rather than just showing current prices, it reconstructs your trading history to map out how your actual capital has fluctuated based on real market actions.

Core Functionality

The script works by scanning your entire trading history—including both completed and currently open positions. It identifies every trade you have made and extracts critical data points such as the entry price, exit price, volume (lots), swap fees, and profit/loss results.

How it Calculates Your Data

To ensure accuracy, the logic processes your data in two distinct ways:

  • Completed Trades: For any position that has already been closed, the script treats the result as a finalized transaction. It adds the net profit (including swaps) to your balance at the specific moment the trade was closed.
  • Active Positions: For trades that are still currently open, the script performs a real-time calculation. It looks at the current market price and compares it against your entry price to determine your "floating" profit or loss at every point in time.

Visual Outputs

The indicator produces two distinct lines on your chart to help you distinguish between different types of capital:

  1. Balance Line: This represents your "hard" capital. It updates only when a trade is fully closed, showing the actual realized funds available in your account.
  2. Equity Line: This represents your "real-time" account value. It includes your hard balance plus the floating profit or loss from all currently open positions. This provides a more fluid view of your account's health as market prices move up and down.

Key Features for Users

  • Customizable Starting Point: You can manually define your initial deposit amount, which serves as the baseline for all calculations.
  • Flexible Scope: You can choose to view the performance of your entire trading history across all instruments or filter the data to see the performance of only the specific currency pair currently visible on your chart.
  • Historical Accuracy: By mapping these values back to specific dates and times on the chart, it allows you to see exactly how your account grew (or contracted) in response to historical market events.
Price Data Components
Series array that contains close prices for each bar
Orders Execution
Checks for the total of open orders
13 Views
0 Downloads
0 Favorites
i-BalEq
//+------------------------------------------------------------------+
//|                                                     i-BalEq.mq4  |
//|                                          Êèì Èãîðü Â. aka KimIV  |
//|                                             http://www.kimiv.ru  |
//|  01.10.2006  Ãðàôèê áàëàíñà è ýêâèòè.                            |
//+------------------------------------------------------------------+
#property copyright "Êèì Èãîðü Â. aka KimIV"
#property link      "http://www.kimiv.ru"
//----
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_width1 2
#property indicator_color2 Red
#property indicator_width2 1
//------- Âíåøíèå ïàðàìåòðû èíäèêàòîðà
extern double Deposit       = 5000;    // Íà÷àëüíûé äåïîçèò
// Ó÷èòûâàòü òîëüêî òåêóùèé èíñòðóìåíò
extern bool   CurSymbolOnly = True;    
//------- Áóôåðû èíäèêàòîðà
double dBuf0[], dBuf1[];
//------- Ãëîáàëüíûå ïåðåìåííûå èíäèêàòîðà
int    oob[];      // íîìåð áàðà îòêðûòèÿ
int    oty[];      // òèï
double olo[];      // ëîò
string osy[];      // èíñòðóìåíò
double oop[];      // öåíà îòêðûòèÿ
int    ocb[];      // íîìåð áàðà çàêðûòèÿ
double ocp[];      // öåíà çàêðûòèÿ
double osw[];      // ñâîï
double opr[];      // ïðèáûëü
//+------------------------------------------------------------------+
//|  Custom indicator initialization function                        |
//+------------------------------------------------------------------+
void init()
  {
   IndicatorDigits(2);
//----
   SetIndexBuffer(0, dBuf0);
   SetIndexLabel (0, "Balance");
   SetIndexStyle (0, DRAW_LINE);
//----
   SetIndexBuffer(1, dBuf1);
   SetIndexLabel (1, "Equity");
   SetIndexStyle (1, DRAW_LINE);
  }
//+------------------------------------------------------------------+
//|  Custom indicator iteration function                             |
//+------------------------------------------------------------------+
void start()
  {
   double b, e, p, t;
   int    i, j, k;
//----
   ReadDeals();
 	 if(oob[0] < 0) 
 	     return;
 	 k = ArraySize(oob);
//----
   for(i = Bars; i >= oob[0]; i--)
     {
       dBuf0[i] = EMPTY_VALUE;
       dBuf1[i] = EMPTY_VALUE;
     }
   for(i = oob[0]; i >= 0; i--)
     {
       b = Deposit; 
       e = 0;
       for(j = 0; j < k; j++)
         {
           if(i <= oob[j] && i >= ocb[j])
             {
               p = MarketInfo(osy[j], MODE_POINT);
               t = MarketInfo(osy[j], MODE_TICKVALUE);
               if(t == 0) 
                   t = 10;
               if(p == 0) 
                   if(StringFind(osy[j], "JPY") < 0) 
                       p = 0.0001; 
                   else 
                       p=0.01;
               if(oty[j] == OP_BUY) 
                   e += (iClose(osy[j], 0, i) - oop[j]) / p*olo[j]*t;
               else 
                   e += (oop[j] - iClose(osy[j], 0, i)) / p*olo[j]*t;
             } 
           else 
               if(i <= ocb[j]) 
                   b += osw[j] + opr[j];
         }
       dBuf0[i] = b;
       dBuf1[i] = b + e;
     }
  }
//+------------------------------------------------------------------+
//|  ×òåíèå ñäåëîê                                                   |
//+------------------------------------------------------------------+
void ReadDeals()
  {
   ArrayResize(oob, 0);
   ArrayResize(oty, 0);
   ArrayResize(olo, 0);
   ArrayResize(osy, 0);
   ArrayResize(oop, 0);
   ArrayResize(ocb, 0);
   ArrayResize(ocp, 0);
   ArrayResize(osw, 0);
   ArrayResize(opr, 0);
   int h = HistoryTotal(), i, k;
//----
   for(i = 0; i < h; i++)
     {
       if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
         {
           if(!CurSymbolOnly || OrderSymbol() == Symbol())
             {
               if(OrderType() == OP_BUY || OrderType() == OP_SELL)
                 {
                   k = ArraySize(oob);
                   ArrayResize(oob, k + 1);
                   ArrayResize(oty, k + 1);
                   ArrayResize(olo, k + 1);
                   ArrayResize(osy, k + 1);
                   ArrayResize(oop, k + 1);
                   ArrayResize(ocb, k + 1);
                   ArrayResize(ocp, k + 1);
                   ArrayResize(osw, k + 1);
                   ArrayResize(opr, k + 1);
                   // íîìåð áàðà îòêðûòèÿ
                   oob[k] = iBarShift(NULL, 0, OrderOpenTime()); 
                   oty[k] = OrderType();       // òèï
                   olo[k] = OrderLots();       // ëîò
                   osy[k] = OrderSymbol();     // èíñòðóìåíò
                   oop[k] = OrderOpenPrice();  // öåíà îòêðûòèÿ
                   // íîìåð áàðà çàêðûòèÿ
                   ocb[k] = iBarShift(NULL, 0, OrderCloseTime());
                   ocp[k]=OrderClosePrice();   // öåíà çàêðûòèÿ
                   osw[k]=OrderSwap();         // ñâîï
                   opr[k]=OrderProfit();       // ïðèáûëü
                 }
             }
         }
     }
   h = OrdersTotal();
//----
   for(i = 0; i < h; i++)
     {
       if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         {
           if(!CurSymbolOnly || OrderSymbol() == Symbol())
             {
               if(OrderType() == OP_BUY || OrderType() == OP_SELL)
                 {
                   k = ArraySize(oob);
                   ArrayResize(oob, k + 1);
                   ArrayResize(oty, k + 1);
                   ArrayResize(olo, k + 1);
                   ArrayResize(osy, k + 1);
                   ArrayResize(oop, k + 1);
                   ArrayResize(ocb, k + 1);
                   ArrayResize(ocp, k + 1);
                   ArrayResize(osw, k + 1);
                   ArrayResize(opr, k + 1);
                   // íîìåð áàðà îòêðûòèÿ
                   oob[k] = iBarShift(NULL, 0, OrderOpenTime()); 
                   oty[k] = OrderType();       // òèï
                   olo[k] = OrderLots();       // ëîò
                   osy[k] = OrderSymbol();     // èíñòðóìåíò
                   oop[k] = OrderOpenPrice();  // öåíà îòêðûòèÿ
                   ocb[k] = 0;                 // íîìåð áàðà çàêðûòèÿ
                   ocp[k] = 0;                 // öåíà çàêðûòèÿ
                   osw[k] = OrderSwap();       // ñâîï
                   opr[k] = OrderProfit();     // ïðèáûëü
                 }
             }
         }
     }
  }
//+------------------------------------------------------------------+

Comments