//+------------------------------------------------------------------+
//|                                                     mathLots.mq4 |
//|                                                          f999145 |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "f999145"
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//--- input parameters
input int      obCorner=3;
input int      fsize=10;
input color    FColors=clrBlack;

int tmp, sec, min, hor, per;
int barTime, curTime;
string cTime, sHor, sMin, sSec, sper;

string SMB;
double b1, b2, k, N, Lot, d, BazCours, itog, proc;
int kOr, Ti;
string SMB1;
bool Fut;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
ObjectCreate("TimeLable12",OBJ_LABEL,0,0,0);   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   //------------------------------------------------------------------------------------------------------
   // -----------  Начальные операции  ------------
   kOr = OrdersTotal();
   itog = 0;
   // ------------   Начало Цикла  ----------------
   for(int i=0;i<kOr;i++)
     {
   Fut=false;
   OrderSelect(i,SELECT_BY_POS);
   SMB=OrderSymbol();
   
   
   b2 = OrderOpenPrice();
   b1 = OrderStopLoss();
   Lot = OrderLots();

// поиск золота и пар с пунктом больше 0.01    
   if(StringFind( SMB,"XAU",0)==0){ 
   N=100*Lot;
   }
   else if(MarketInfo(SMB,MODE_POINT)<0.01)
          {
           N=100000*Lot; 
          } else
     {
     N=1000*Lot; 
     }   
   
// поиск Фьючерсов и Фондов
    if (StringFind( SMB,"#",0)==-1 && StringFind( SMB,"_",0)==-1) Fut=true;


if(Fut){
// --------- вычисляем какая пара (прямая, обратная, кросс) --------------
   Ti=StringFind( SMB,"USD",0);
//------ извлекаем имя первой валютной пары ------------
   SMB1=StringSubstr(SMB,0,3); //базовая валюта
// ------- текущая котировка базовой валюты к доллару США -------------
   BazCours=MarketInfo(SMB1+"USD",MODE_BID);
   //Alert("Tекущая котировка базовой валюты к доллару США = ",BazCours);

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   // --------- рассчитываем стоимость пункта -------------------------
   if(Ti==3){//пара прямая, напр. EurUsd
    k=1;
   }
   if(Ti==0){//пара обратная, напр. UsdJpy
     k=1/MarketInfo(SMB,MODE_BID);
   }
   if(Ti==-1){//Кросс-пара, напр EurJpy
     k=BazCours/MarketInfo(SMB,MODE_BID);
   }
}
else k=1;
//***********************************************************************************
   if(OrderType()== OP_BUY || OrderType()== OP_BUYLIMIT || OrderType()== OP_BUYSTOP)d=N*k*(b2-b1);
   else d=N*k*(b1-b2);

//***********************************************************************************
   itog=itog+d;
 }
proc=100*itog/AccountBalance( );

  
//------------------------------------------------------------------------------------------------------
  
per=Period();  
   
 
barTime=Time[0]; //Время открытия последней свечи
curTime=TimeCurrent(); //Текущее время
tmp=curTime-barTime; //секунды с момента открытия свечи
tmp=per*60-tmp; //секунды до окончания свечи


//   {
     min=tmp/60;
     hor=min/60;
     min=min-hor*60;
     sec=tmp-min*60-hor*60*60;
//   }


if (min<10){sMin="0"+min;}
else {sMin=""+min;}

if (sec==60) {sec=59;}
if (sec<10){sSec="0"+sec;}
else {sSec=""+sec;}
if(hor>0)
{
   if (hor<10){sHor="0"+hor;}
   else {sHor=""+hor;}
}

if (hor==0) {
cTime=sMin+":"+sSec;
}
else {cTime=sHor+":"+sMin+":"+sSec;}

//----
proc=NormalizeDouble(proc,2);
itog=NormalizeDouble(itog,2);


ObjectSet("TimeLable12",OBJPROP_CORNER,obCorner);
ObjectSetText("TimeLable12",cTime+"//  SL $ "+itog+";  Риск= "+proc+"%",fsize,"Microsoft Sans Serif",FColors);
ObjectSet("TimeLable12",OBJPROP_XDISTANCE,5);
ObjectSet("TimeLable12",OBJPROP_YDISTANCE,3);
   

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
//void OnTimer()
//  {
//---
   
//  }
//+------------------------------------------------------------------+
