iBalans_v2

This script is designed as a comprehensive financial dashboard and performance tracker for MetaTrader users. Instead of showing standard price charts, it focuses on your account's equity health, profit margins, and trade history. It serves as a visual summary of how your capital is growing or shrinking over time.

Core Functionality

1. Dynamic Balance Tracking The tool monitors your account balance in real-time. It specifically calculates the "net" results of your closed trades—accounting for gross profit, commissions, and swaps (overnight fees). By processing this data, it creates a visual representation of your balance history, allowing you to see the trajectory of your account's growth.

2. Performance Analytics & Statistics The script performs an automated audit of your trading history based on a timeframe you define (the "Days" parameter). It categorizes your trades into several key metrics:

  • Total Trades: A count of every closed position within the specified period.
  • Win/Loss Breakdown: It separates profitable trades from losing trades, providing a clear picture of your success rate.
  • Gross vs. Net: It distinguishes between "Gross Profit" (the raw gain from trades) and "Net Profit" (the actual money remaining after all costs and fees are deducted).

3. Symbol-Specific Filtering One of the tool's sophisticated features is its ability to distinguish between your general account performance and your performance on a specific currency pair or asset. It isolates trades made on the current chart's symbol, showing you exactly how much profit or loss that specific asset has contributed compared to your overall portfolio.

4. Visual Dashboard (On-Screen Information) Rather than requiring you to dig through complex account menus, the script projects a clean, color-coded information panel directly onto your trading screen. This display updates automatically to show:

  • Current Total Balance.
  • Profit and Loss summaries for the entire account.
  • Specific performance stats for the current asset (number of trades, win/loss count, and net totals).

5. High-Level Milestone Tracking The script identifies and tracks your historical peaks and valleys—the maximum and minimum balances reached during your trading period. It uses these milestones to help you visualize your "trading range," providing a sense of the highest highs and lowest lows your account has experienced within your chosen timeframe.

Summary for the User

In simple terms, this tool acts as an automated accounting assistant. It takes all the messy data from your trade history, filters it by time and asset type, calculates the real profit after fees, and displays a summarized dashboard of your success, losses, and growth trends in one easy-to-read window.

Orders Execution
Checks for the total of closed orders
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
iBalans_v2
//+------------------------------------------------------------------+
//|                           iBalans_v2.mq4                         |
//+------------------------------------------------------------------+
#property  copyright "Yurich"
#property  link      ""
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Green
#property  indicator_color2  Gold
#property  indicator_width1  2
#property  indicator_width2  2
//---- indicator parameters
extern int Days=0;
extern bool Show_info=true;
//---- indicator buffers
double     iB[];
double     iS[];
double     iT[];
//---- indicator var
int wh;
datetime prevtime;
double prevbalans, midlevel, minlevel, maxlevel;
#define names "iBalans_"
//+------------------------------------------------------------------+
int init()
{
   SetIndexBuffer(0,iB);
   SetIndexBuffer(1,iS);
   SetIndexBuffer(2,iT);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_NONE);
   IndicatorDigits(2);
   IndicatorShortName(names+"("+Days+")");
   SetIndexLabel(0,"Total balans");
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
//----
   prevbalans=0;
   midlevel=0;
   minlevel=0;
   maxlevel=0;
   if(Days<0) Days=0;
   return(0);
}
//+------------------------------------------------------------------+
int start()
{
   int i, j, cnt=0, pt=0, lt=0, st=0, spt=0, slt=0;
   int htm[][2];
   double cp, mnl, mxl;
   double sb=0.0, gp=0.0, gl=0.0, sgp=0.0, sgl=0.0;
   datetime now=iTime(NULL,0,0);
   if(now!=prevtime)
   {
      prevtime=now;
      prevbalans=0;
   }
   double sbalans=AccountBalance();
   if(prevbalans==sbalans)return(0);
   prevbalans=sbalans;
   datetime stday=iTime(Symbol(), PERIOD_D1,0)-Days*PERIOD_D1*60;
//----
   int oht=OrdersHistoryTotal();
   ArrayResize(htm,oht);
   for(i=0; i<oht; i++)
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
         if(OrderType()<=OP_SELL && (OrderCloseTime()>stday || Days==0))
         {
            htm[cnt][0]=OrderCloseTime();
            htm[cnt][1]=OrderTicket();
            cnt++;
         }
   ArrayResize(htm,cnt);
   ArraySort(htm);
   mxl=sbalans;
   mnl=sbalans;
   iB[0]=sbalans;
   int limit=Bars/2;
   if(cnt<limit) limit=cnt;
   j=2;
   for(i=1; i<=limit; i++)
   {
      OrderSelect(htm[cnt-i][1],SELECT_BY_TICKET);
      cp=OrderProfit()+OrderCommission()+OrderSwap();
      iB[j]=iB[j-2]-cp;
      iB[j-1]=(iB[j-2]+iB[j])/2;
      if(cp>=0) { pt++; gp+=cp;} else { lt++; gl+=-cp;}
      if(iB[j]>mxl) mxl=iB[j];
      if(iB[j]<mnl) mnl=iB[j];
      if(OrderSymbol()==Symbol())
      {
         iS[j-1]=iB[j-1];
         iS[j-2]=iB[j-2];
         iS[j]=iB[j];
         sb+=cp;
         if(cp>=0) { spt++; sgp+=cp;} else { slt++; sgl+=-cp;}
         st++;
      } else { iS[j]=EMPTY_VALUE; iS[j-1]=EMPTY_VALUE;}
      j+=2;
   }
   sbalans=iB[j-2];   
   if(sbalans!=midlevel)
   {
      midlevel=sbalans;
      SetLevelValue(0,midlevel);
   }
   if(mxl!=maxlevel)
   {
      maxlevel=MathMax(mxl,midlevel);
      SetLevelValue(1,maxlevel);
      iT[0]=maxlevel+0.1*(maxlevel-minlevel);
   }
   if(mnl!=minlevel)
   {
      minlevel=MathMin(mnl,midlevel);
      SetLevelValue(2,minlevel);
      iT[1]=minlevel-0.1*(maxlevel-minlevel);
   }
//----
   if(!Show_info) return(0);
   wh=WindowFind(names+"("+Days+")");
   show(0, Lime, "Total Balans "+DoubleToStr(AccountBalance(),2));
   show(1, Lime, "Gross Profit "+DoubleToStr(gp,2)
            +"  Gross Loss "+DoubleToStr(gl,2)
            +"  Net Profit "+DoubleToStr(gp-gl,2));
   show(2, Lime, "Total Trades "+cnt+"     Profit Trades "+pt+"     Loss Trades "+lt);
   show(3, Gold, "Net Profit "+Symbol()+" "+DoubleToStr(sb,2));
   show(4, Gold, "Gross Profit "+DoubleToStr(sgp,2)
            +"  Gross Loss "+DoubleToStr(sgl,2));
   show(5, Gold, Symbol()+" Trades "+st+"     Profit Trades "+spt+"    Loss Trades "+slt);
//----
   return(0);
}
//+------------------------------------------------------------------+ 
void show(int line, color col, string str)
{
   string sobj=names+line;
   int cw=ObjectFind(sobj);
   if(cw!=wh)
   {
      if(cw>=0) ObjectDelete(sobj);
      ObjectCreate(sobj,OBJ_LABEL,wh,0,0);
      ObjectSet(sobj,OBJPROP_CORNER,0);
      ObjectSet(sobj,OBJPROP_XDISTANCE,3);
      ObjectSet(sobj,OBJPROP_YDISTANCE,25+line*12);
   }
   ObjectSetText(sobj,str,8,"",col);
}
//+------------------------------------------------------------------+ 
int deinit()
{
   for(int i=0; i<=5; i++) ObjectDelete(names+i);
   return(0);
}
//+------------------------------------------------------------------+ 
 

Comments