An indicator which can calculate total open order's profit loss by shifting of line on one chart where orders are open.

 
hi, i am trying to edit the code to make it beneficial for my MT5, it is an MT4 indicator,
 which i am trying to edit and rewrite it in MQL5, 

kindly help me with codes, as it is simple to look but is very difficult for me to understand.


#property strict; 
extern string _Parameters_Trade="-------------"; 
extern int MAGIC=1000;   // MagicNumber for calculate, -1 any Magic
extern string NL="LP";   // Name of Line
extern int fs=16;        // FontSize
extern color cm=clrRed;  // Color prof/loss
double dt,ss;
string pl="";
//+------------------------------------------------------------------+
//| Expert start function                                            |
//+------------------------------------------------------------------+
void start()
  {
   for(int cnt=ObjectsTotal()-1; cnt>=0; cnt--)
     {
      string name=ObjectName(cnt);
      if(ObjectType(name)==OBJ_HLINE)
        {
         if(name==NL)
           {
            dt=ObjectGet(name,OBJPROP_PRICE1);
           }
        }
     }
//---
   if(dt>0)
     {
      ss=ProfitIFTakeInCurrency(MAGIC);
      if(ss>0){pl="+";}
      else{pl="";}
      string LM="Profit/Loss = "+pl+DoubleToStr(ss,2)+" "+AccountCurrency();
      Title(LM);
     }
  }
//+------------------------------------------------------------------+
//|   Show Profit/Loss                                               |
//+------------------------------------------------------------------+
void Title(string Show)
  {
   string name_0="L_1";
   if(ObjectFind(name_0)==-1)
     {
      ObjectCreate(name_0,OBJ_LABEL,0,0,0);
      ObjectSet(name_0,OBJPROP_CORNER,0);
      ObjectSet(name_0,OBJPROP_XDISTANCE,390);
      ObjectSet(name_0,OBJPROP_YDISTANCE,50);
     }
   ObjectSetText(name_0,Show,fs,"Arial",cm);
  }
//+----------------------------------------------------------------------------+
//| Calculation:                                                               |
//+----------------------------------------------------------------------------+
double ProfitIFTakeInCurrency(int mn)
  {
   int    i, k=OrdersTotal(); 
   double m;                 
   double l;                  
   double p;                  
   double t;                  
   double v;                  
   double s=0;                
//---
   l=MarketInfo(Symbol(), MODE_LOTSIZE);
   m=MarketInfo(Symbol(), MODE_PROFITCALCMODE);
   p=MarketInfo(Symbol(), MODE_POINT);
   t=MarketInfo(Symbol(), MODE_TICKSIZE);
   v=MarketInfo(Symbol(), MODE_TICKVALUE);
//---
   for(i=0; i<k; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && (mn<0 || OrderMagicNumber()==mn))
           {
            if(OrderType()==OP_BUY || OrderType()==OP_SELL)
              {
               if(OrderType()==OP_BUY)
                 {
                  if(m==0) s+=(dt-OrderOpenPrice())/p*v*OrderLots();
                  if(m==1) s+=(dt-OrderOpenPrice())/p*v/t/l*OrderLots();
                  if(m==2) s+=(dt-OrderOpenPrice())/p*v*OrderLots();
                  s+=OrderCommission()+OrderSwap();
                 }
               if(OrderType()==OP_SELL)
                 {
                  if(m==0) s+=(OrderOpenPrice()-dt)/p*v*OrderLots();
                  if(m==1) s+=(OrderOpenPrice()-dt)/p*v/t/l*OrderLots();
                  if(m==2) s+=(OrderOpenPrice()-dt)/p*v*OrderLots();
                  s+=OrderCommission()+OrderSwap();
                 }
              }
           }
        }
     }
   return(s);
  }
//+----------------------------------------------------------------------------+
 

Example: Calculation Net Price Indicator

The indicator displays three lines: netting price for BUY, for SELL and total for BUY and SELL.

An example of work when first four BUY positions are opened, and then another BUY position is added:

Calculation Net Price Indicator

Calculation Net Price Indicator
Calculation Net Price Indicator
  • www.mql5.com
Индикатор отображает три линии: неттинговую цену для BUY, для SELL и общую для BUY и SELL. Пример работы, когда сначала открыты четыре позиции BUY, а потом добавляется ещё одна позиция BUY: iMACD iSAR...
 
Vladimir Karputov:

Example: Calculation Net Price Indicator

The indicator displays three lines: netting price for BUY, for SELL and total for BUY and SELL.

An example of work when first four BUY positions are opened, and then another BUY position is added:

Sir, that is beautiful, may i ask if we wanted to change the value of break even, how should we change it? 
for example, suppose:


criteria 1:: if i wish to set break even value to a "fix pips" (like 50 pips)

criteria 2:: if i wish to set breakeven value to a "percentage pips" (like with every trade that is opened in one direction a certain pips would be increased in target price, meaning more the market goes negative and more one direction open trades are open then, the target price will have more profits than just fix 50 pips over the same trading method.) 
here i assume to add for every new trade that is opened i want a 0.5 pips to be added gradually so target price does not go way beyond the limit and it is also achieved.

how do you find it sir? i feel it's brilliant.

Reason: