Author: ������ ��������
risk

This script is designed as an automated analytical tool for MetaTrader users to manage and monitor portfolio risk in real-time. Its primary function is to calculate your current trading exposure, determine how much additional volume you can safely open based on your account balance, and provide a comprehensive performance summary directly on your chart.

Key Functional Components

Dynamic Lot Size Calculation The script automatically calculates the appropriate number of "Lots" (trading units) you should be using based on your current account balance. It ensures these figures align with the specific rules of your broker by rounding the numbers to the nearest valid increment, ensuring that your trades are always executed correctly without manual adjustment.

Risk-Based Position Management The tool takes your defined risk percentage and compares it against your currently active trades. By totaling the volume of all open "Buy" and "Sell" positions, the script calculates exactly how much "room" you have left in your portfolio. It then provides a specific recommendation on how many more units you can add to your current positions without exceeding your desired risk threshold.

Historical Performance Analysis Beyond just looking at what is currently happening, the script scans your entire trading history to perform a comprehensive review of your performance. It distinguishes between winning and losing trades (including swaps) to provide a clear picture of your overall success rate.

Real-Time Dashboard Display The logic concludes by generating a live information display on your screen. This dashboard provides a quick glance at several critical metrics:

  • Current Status: Your calculated base lot size and the current volume you have open.
  • Capacity: The exact amount of volume you are still permitted to add.
  • Profit Overview: Your current floating profit in both currency and percentage.
  • Historical Summary: Your total historical profit and a calculation of your profit relative to your account growth.

Essentially, this script acts as an automated "Risk Officer," constantly monitoring your balance and history to tell you exactly how much you should be trading at any given moment.

Orders Execution
Checks for the total of open orders
9 Views
0 Downloads
0 Favorites
risk
//+------------------------------------------------------------------+
//|                                                 Âèêòîð ×åáîòàð¸â |
//|                                    http://www.chebotariov.co.ua/ |
//+------------------------------------------------------------------+
#property copyright "Âèêòîð ×åáîòàð¸â"
#property link      "http://www.chebotariov.co.ua/"
extern double risk = 10;
   
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  
   int trade, cnt, cnt2, ticket;
   int total=OrdersTotal();
   double OpenLots=0;

//----
    for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()==OP_SELL || OrderType()==OP_BUY)
        {
         OpenLots += OrderLots();
        }
     }
//----

      
   double Lots=NormalizeDouble(AccountBalance()/1000,1);
   double raznica = MathMod(Lots,MarketInfo(Symbol(),MODE_LOTSTEP));
   if(raznica>0.1){Lots-=raznica;}

   double Lots2=NormalizeDouble(Lots*risk/100.0,1);
   if(raznica>0.1){Lots2-=raznica;}
   

   double Lots3=MathAbs(Lots2)-MathAbs(OpenLots);
   if(Lots3<0 && Lots3>(raznica*(-1))){Lots3=0;}
   
   int i,ks;
   double op,ou;
   for(i=0;i<HistoryTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderType()==OP_BUY || OrderType()==OP_SELL)
           {
            if(OrderProfit()>0)
              {
               op+=OrderProfit();
              }
               else
              {
               ou+=OrderProfit();
              }
            op+=OrderSwap();
            ks++;
           }
        }
     }
   double totalprofit=NormalizeDouble(op+ou,2);
   double totalprofitpersent=NormalizeDouble(100/(AccountBalance()-totalprofit)*totalprofit,2);
   
   Comment("Äîñòóïíî: ",Lots,"   Ðàçðåøåíî: ",Lots2,"   Èñïîëüçóåòñÿ: ",OpenLots,"   Ìîæíî äîáàâèòü: ",Lots3,"\n","Ðèñê: ",risk,"%   Ïðèáûëü: ",AccountProfit()," (",NormalizeDouble(100/AccountBalance()*AccountProfit(),2),"%)   Îáùàÿ ïðèáûëü: ",totalprofit," (",totalprofitpersent,"%)");
   
   return(0);
  }
//+------------------------------------------------------------------+

Comments