/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*  из коллекции  |                    RM-INFO                      */
/*    RoboMAKS    |                                                 */
/*________________|_________________________________________________*/
/*   автор: Maks Shukurov                                           */
/*   источник:                                                      */
/*__________________________________________________________________*/
/* maksshukurov@mail.ru  Baku,Azerbaijan,tel.+994503408530          */
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
#property copyright "Из коллекции  RoboMAKS"
#property link ""

//   Для использования в тестере добавить в советник
//   строку  iCustom(NULL,0,"RM-INFO",0,0);
#property indicator_chart_window

 input bool    ПРОСАДКА       = true;     /* Информация просадки */
 input bool    ИСТОРИЯ        = true;     /* Инф. кол-ва закр. ордеров и прибыли за выбр. период */
 input bool    ПОСЛ_РЕЗ       = true;     /* Инф. о последнем закр. ордере */
 input bool    ОБЩ_ЛОТ        = true;     /* Инф. о суммарном лоте ордеров - рыночных и отложенников */
 input bool    РАЗРЫВ         = true;     /* Инф. о разрывах открытия (гэп) */
 input bool    ПОСЛ_МИНУТА    = true;     /* Инф. о посл. минуте часа или Н4 */
 input bool    ВРЕМЯ          = true;     /* Инф. времени и спрэда */
 input bool    ИНФО_СЧЁТА     = false;    /* Инф. о счёте (stop-out,margin call) */
 //            ____________________
 input string  ___ГРАФИК___   = "параметры графика";
 input bool    Автоустановка  = false;           /* Автоустановка параметров графика, (false - по умолчанию) */
 input int     Тип_Графика    = 1;               /* Тип графика 0- бары, 1 - свечи, 2 - линия */
 input int     Сжатие         = 1;               /* Сжатие графика 0-5 */
 input color   Цвет_фона      = clrBlack;        /* Цвет фона */
 input color   Цвет_линии     = clrLime;         /* Цвет линии и доджи */
 input color   Цвет_сетки     = clrMidnightBlue; /* Цвет сетки */
 input color   Цвет_свечи_UP  = clrWhite;        /* Цвет бычьей свечи (бара) */
 input color   Цвет_свечи_DN  = clrDeepSkyBlue;  /* Цвет медвежьей свечи (бара) */
 
 string        ______         = "параметры отображения строки просадки";
 int           Xdist          = 250;      /* Отступ строки времени по горизонтали */
 int           Ydist          = 1;        /* Отступ строки по вертикали */
 int           Corn           = 0;        /* Угол привязки */
 string        TmFont         = "Tahoma"; /* Шрифт */
 int           TmSize         = 10;       /* Размер шрифта */
 color         TmCol          = clrLime;  /* Цвет строки */
 
 int           Min_Lev,Spread,ordsell,ordsell_1,ordsellst,ordsellLm,ordbuy,ordbuy_1,ordbuyst,ordbuyLm;
 double        ask,bid,MaxLot,Max_Lot,Min_Lot,One_Lot,Free,Step,Balance,Credit,Equity,prsell,prsell_1,smsell_1,
               smbuy_1,prbuy,prbuy_1,smlotsell,smlotsellst,smlotsellLm,smlotbuy,smlotbuyst,smlotbuyLm,SMLOT;
 string        name="INF";
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
int OnInit(){
   if(Автоустановка){ChartSetInteger(0,CHART_MODE,Тип_Графика);ChartSetInteger(0,CHART_COLOR_BACKGROUND,Цвет_фона);
   ChartSetInteger(0,CHART_SCALE,Сжатие);ChartSetInteger(0,CHART_COLOR_GRID,Цвет_сетки);ChartSetInteger(0,CHART_COLOR_CHART_LINE,Цвет_линии);
   ChartSetInteger(0,CHART_COLOR_CHART_UP,Цвет_свечи_UP);ChartSetInteger(0,CHART_COLOR_CANDLE_BULL,Цвет_свечи_UP);
   ChartSetInteger(0,CHART_COLOR_CHART_DOWN,Цвет_свечи_DN);ChartSetInteger(0,CHART_COLOR_CANDLE_BEAR,Цвет_свечи_DN);
   ChartSetInteger(0,CHART_FOREGROUND,1);ChartSetInteger(0,CHART_SHOW_PERIOD_SEP,1);ChartSetInteger(0,CHART_SHIFT,1);}
   EventSetTimer(1);return(INIT_SUCCEEDED);}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
void OnDeinit(const int reason){ObjectsDelete(0,-1,name);Comment("");EventKillTimer();}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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[]){
   Balance=NormalizeDouble(AccountBalance(),2);
   Equity=NormalizeDouble(AccountEquity(),2);
   Free=NormalizeDouble(AccountFreeMargin(),2);
   Min_Lot=MarketInfo(_Symbol,MODE_MINLOT);
   Max_Lot=MarketInfo(_Symbol,MODE_MAXLOT);
   Min_Lev=MarketInfo(_Symbol,MODE_STOPLEVEL);
   Step=MarketInfo(_Symbol,MODE_LOTSTEP);
   Credit=NormalizeDouble(AccountCredit(),2);
   bid=NormalizeDouble(MarketInfo(_Symbol,MODE_BID),_Digits);
   ask=NormalizeDouble(MarketInfo(_Symbol,MODE_ASK),_Digits);
   One_Lot=NormalizeDouble(MarketInfo(_Symbol,MODE_MARGINREQUIRED),_Digits);
   if(AccountInfoDouble(ACCOUNT_MARGIN_SO_SO)>=40||AccountInfoDouble(ACCOUNT_MARGIN_SO_CALL)>=40)double Mrg=0.8; else Mrg=1;
   if(One_Lot>0)MaxLot=MathFloor((Free/One_Lot)/Step)*Step*Mrg;
   if(MaxLot<Min_Lot)MaxLot=0;if(MaxLot>=Max_Lot)MaxLot=Max_Lot;
   Spread=MarketInfo(_Symbol,MODE_SPREAD);
   ordsell=0;ordsell_1=0;ordsellst=0;ordsellLm=0;ordbuy=0;ordbuy_1=0;ordbuyst=0;ordbuyLm=0;prsell=0;prsell_1=0;prbuy=0;prbuy_1=0;
   smlotsell=0;smlotsellst=0;smlotsellLm=0;smlotbuy=0;smlotbuyst=0;smlotbuyLm=0;smsell_1=0;smbuy_1=0;SMLOT=0;int i;
   for(i=OrdersTotal();i>=0;i--){if(OrderSelect(i,SELECT_BY_POS)){
   if(OrderType()==OP_SELL)ordsell++;
   if(OrderSymbol()==_Symbol&&OrderType()==OP_SELL)ordsell_1++;
   if(OrderType()==OP_SELLSTOP)ordsellst++;
   if(OrderType()==OP_SELLLIMIT)ordsellLm++;
   if(OrderType()==OP_BUY)ordbuy++;
   if(OrderSymbol()==_Symbol&&OrderType()==OP_BUY)ordbuy_1++;
   if(OrderType()==OP_BUYSTOP)ordbuyst++;
   if(OrderType()==OP_BUYLIMIT)ordbuyLm++;
   if(OrderType()==OP_SELL)smlotsell=smlotsell+OrderLots();
   if(OrderSymbol()==_Symbol&&OrderType()==OP_SELL)smsell_1=smsell_1+OrderLots();
   if(OrderType()==OP_SELLSTOP)smlotsellst=smlotsellst+OrderLots();
   if(OrderType()==OP_SELLLIMIT)smlotsellLm=smlotsellLm+OrderLots();
   if(OrderType()==OP_BUY)smlotbuy=smlotbuy+OrderLots();
   if(OrderSymbol()==_Symbol&&OrderType()==OP_BUY)smbuy_1=smbuy_1+OrderLots();
   if(OrderType()==OP_BUYSTOP)smlotbuyst=smlotbuyst+OrderLots();
   if(OrderType()==OP_BUYLIMIT)smlotbuyLm=smlotbuyLm+OrderLots();
   if(OrderType()==OP_SELL)prsell=prsell+(OrderProfit()+OrderSwap()+OrderCommission());
   if(OrderSymbol()==_Symbol&&OrderType()==OP_SELL)prsell_1=prsell_1+(OrderProfit()+OrderSwap()+OrderCommission());
   if(OrderType()==OP_BUY)prbuy=prbuy+(OrderProfit()+OrderSwap()+OrderCommission());
   if(OrderSymbol()==_Symbol&&OrderType()==OP_BUY)prbuy_1=prbuy_1+(OrderProfit()+OrderSwap()+OrderCommission());}}
   SMLOT=smlotsell+smlotsellst+smlotsellLm+smlotbuy+smlotbuyst+smlotbuyLm;
  //xxxxxxxxxxx
   int ih=0,sm=0,ticket=0,l1=0,l2=0,ly=0,ly1=0,Rz=0;double Drdn;string AcInf="",res="",Lst="",Ord="",smpr="",ordsym="",SLM="",BLM="";color clRz;
   double openH=0,closeH=0,lot_hH=0,profit_hH=0,smprofH=0;double smlotH=0;
   for(;ih<=OrdersHistoryTotal();ih++){if(OrderSelect(ih,SELECT_BY_POS,MODE_HISTORY)){
   if(OrderType()==OP_SELL||OrderType()==OP_BUY){sm++;
   if(OrderType()==OP_SELL)Ord="SELL";if(OrderType()==OP_BUY)Ord="BUY";
   ticket=OrderTicket();openH=OrderOpenPrice();closeH=OrderClosePrice();lot_hH=OrderLots();smlotH=smlotH+OrderLots();ordsym=OrderSymbol();
   profit_hH=OrderProfit()+OrderSwap()+OrderCommission();smprofH=smprofH+(OrderProfit()+OrderSwap()+OrderCommission());}}}
   if(profit_hH<0.0)string ProfitH="\n Убыток    "; else ProfitH="\n Прибыль  ";
   if(smprofH<0.0)smpr="\n Убыток              "; else smpr="\n Прибыль             ";if(sm==0)smpr="\n Прибыль             ";
   if(ticket==0)string smbord=""; else smbord="\n          "+ordsym;
   if(ИСТОРИЯ)res="\n -------------------------------\n Kол-во закр. орд.\n за выбр. период   "+sm+
   "\n Объём                "+DoubleToString(smlotH,2)+smpr+DoubleToString(smprofH,2);
   if(ПОСЛ_РЕЗ)Lst="\n -------------------------------\n    Посл. результат:"+smbord+"\n Ордер  "+Ord+"   # "+ticket+"\n Лот         "+
   DoubleToString(lot_hH,2)+"\n Откр       "+openH+"\n Закр        "+closeH+ProfitH+DoubleToString(profit_hH,2);
   if(One_Lot>0)string MxL="\n Макс. ЛОТ        "+DoubleToString(MaxLot,2); else MxL="";
   if((Equity-(Balance+Credit))<0.0)string sProfit="\n ПРОСАДКА     "; else sProfit="\n ПРОФИТ          ";
   if(smlotsell>0)string SLS="   Lot  "+DoubleToString(smlotsell,2); else SLS="";
   if(smlotsellst>0)string SST="   Lot  "+DoubleToString(smlotsellst,2); else SST="";
   if(smlotbuy>0)string SLB="   Lot  "+DoubleToString(smlotbuy,2); else SLB="";
   if(smlotbuyst>0)string BST="   Lot  "+DoubleToString(smlotbuyst,2); else BST="";
   if(ordsellLm>0)SLM="\n SELL LIMIT      "+ordsellLm+"   Lot  "+DoubleToString(smlotsellLm,2);
   if(ordbuyLm>0)BLM="\n BUY LIMIT      "+ordbuyLm+"   Lot  "+DoubleToString(smlotbuyLm,2);
   if(prsell_1<0)string ProfitS_1=" Просадка       "; else ProfitS_1=" Профит        ";
   if(prbuy_1<0)string ProfitB_1=" Просадка       "; else ProfitB_1=" Профит         ";
   if(ordsell_1>0||ordbuy_1>0){
   if(ordsell_1>0)string SDS="\n Сумма лотов SELL    "+DoubleToString(smsell_1,2),SDS1="\n"+ProfitS_1+"SELL    "+DoubleToString(prsell_1,2); else {SDS="";SDS1="";}
   if(ordbuy_1>0)string SDB="\n Сумма лотов BUY    "+DoubleToString(smbuy_1,2),SDB1="\n"+ProfitB_1+"BUY    "+DoubleToString(prbuy_1,2); else {SDB="";SDB1="";}
   if(ordsell_1<ordsell||ordbuy_1<ordbuy)string SD="\n\n ===  по  "+_Symbol+"  ==="+SDS+SDB+SDS1+SDB1;} else SD="";
   string ST="\n -------------------------------\n SELL                "+ordsell+SLS+"\n SELL STOP      "+ordsellst+SST+SLM,
   BT="\n BUY                "+ordbuy+SLB+"\n BUY STOP      "+ordbuyst+BST+BLM;
   if(Credit>0)string Cr="\n КРЕДИТ           "+DoubleToString(Credit,2); else Cr="";
   if(prsell<0)string ProfitS=" Просадка        "; else ProfitS=" Профит         ";
   if(prbuy<0)string ProfitB=" Просадка        "; else ProfitB=" Профит         ";
   if(ИНФО_СЧЁТА)AcInf="\n Кред. плечо      "+AccountLeverage()+"\n StopLevel          "+Min_Lev+" п."
   "\n Stop Out           "+AccountInfoDouble(ACCOUNT_MARGIN_SO_SO)+" %"+"\n Margin Call        "+AccountInfoDouble(ACCOUNT_MARGIN_SO_CALL)+" %";
   if(AccountInfoDouble(ACCOUNT_MARGIN_SO_SO)>=40||AccountInfoDouble(ACCOUNT_MARGIN_SO_CALL)>=40)string Prc="  80%"; else Prc="";
   Comment("\n БАЛАНС          "+DoubleToString(Balance,2),Cr,"\n СРЕДСТВА      "+DoubleToString(Equity,2),
   "\n СВОБОДНО     "+DoubleToString(Free,2),sProfit+DoubleToString(Equity-(Balance+Credit),2),AcInf,MxL+Prc,ST,BT,
   "\n -------------------------------\n",ProfitS,"SELL   ",DoubleToString(prsell,2),"\n",
   ProfitB,"BUY   ",DoubleToString(prbuy,2),SD,res,Lst);
   //xxxxxxxxxxx
   if(ПРОСАДКА){if(!(Balance+Credit)==0){Drdn=(Equity-(Balance+Credit))/(Balance+Credit)*100;}if(Drdn>=0)Drdn=0;static double maxDrdn;if(Drdn<maxDrdn)maxDrdn=Drdn;
   if(Drdn<0)string drn=""; else drn=" ";if(maxDrdn<0)string maxdrn=""; else maxdrn=" ";
   string DRDN="Просадка  "+drn+DoubleToString(Drdn,2)+" %    Макс. просадка  "+maxdrn+DoubleToString(maxDrdn,2)+" %";
   SetATL(name+"Inf",23,DRDN,TmSize,TmFont,TmCol,Xdist,Ydist,Corn,0);}
   //xxxxxxxxxxx
   if(ПОСЛ_МИНУТА){if(TimeCurrent()>=iTime(_Symbol,PERIOD_H4,0)+14340){
   SetATL(name+"Tcl",23,"Последняя минута H4",11,"Arial Black",clrRed,465,11,1,0);l1=1;
   if(ObjectGet(name+"Tcl",OBJPROP_SELECTED)>0)ObjectSet(name+"Tcl",OBJPROP_SELECTED,0);}
   if(!(TimeCurrent()>=iTime(_Symbol,PERIOD_H4,0)+14340)){if(TimeCurrent()>=iTime(_Symbol,PERIOD_H1,0)+3540){
   SetATL(name+"Tcl",23,"Последняя минута часа",11,"Arial Black",clrRed,458,11,1,0);l1=1;
   if(ObjectGet(name+"Tcl",OBJPROP_SELECTED)>0)ObjectSet(name+"Tcl",OBJPROP_SELECTED,0);}}
   if(TimeCurrent()>=iTime(_Symbol,PERIOD_H1,0)&&TimeCurrent()<iTime(_Symbol,PERIOD_H1,0)+3540){ObjectDelete(name+"Tcl");l1=0;}}
   //xxxxxxxxxxx
   if(ОБЩ_ЛОТ){double ML=NormalizeDouble(MaxLot/4.0,2);
   if(SMLOT>ML)color smcl=clrRed; else smcl=clrLime;
   SetATL(name+"SML",23,"SumLOT  "+DoubleToStr(SMLOT,2),10,"Arial Black",smcl,6,11,0,0);}
   //xxxxxxxxxxx
   if(РАЗРЫВ){if(_Digits==5||_Digits==3)int spr=50; else spr=5;
   if(Period()<=PERIOD_M15&&Spread<spr){
   if(iOpen(_Symbol,PERIOD_CURRENT,0)>iClose(_Symbol,PERIOD_CURRENT,1)){Rz=(iOpen(_Symbol,PERIOD_CURRENT,0)-iClose(_Symbol,PERIOD_CURRENT,1))/_Point;clRz=clrLime;}
   if(iOpen(_Symbol,PERIOD_CURRENT,0)<iClose(_Symbol,PERIOD_CURRENT,1)){Rz=(iClose(_Symbol,PERIOD_CURRENT,1)-iOpen(_Symbol,PERIOD_CURRENT,0))/_Point;clRz=clrRed;}
   if(_Digits==5||_Digits==3)int rzr=10; else rzr=1;if(Rz>rzr){if(l1==0){ly=11;l1=1;} else {ly=25;l2=1;}
   if(ObjectGet(name+"Rz",OBJPROP_SELECTED)>0)ObjectSet(name+"Rz",OBJPROP_SELECTED,0);
   SetATL(name+"Rz",23,"Открытие с разрывом  "+Rz,11,"Arial Black",clRz,455,ly,1,0);}
   if(TimeCurrent()==iOpen(_Symbol,PERIOD_CURRENT,0)||iVolume(_Symbol,PERIOD_CURRENT,0)<5){
   if(ObjectFind(name+"Rz")==0)ObjectDelete(name+"Rz");}}}
   //xxxxxxxxxxx
   ChartRedraw();return(rates_total);}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
void OnTimer(){
   if(ВРЕМЯ){string min1,min2,sec1,sec2,p1="",_time="",beg="",end="",line=":...:...:...:...:";
   int d,pc,base=StringLen(line),T=_Period*60-TimeCurrent()+iTime(_Symbol,PERIOD_CURRENT,0);
   datetime GMT=TimeGMT(),brokers=TimeCurrent(),localTime=TimeLocal();
   if(!IsTesting()){string GMTst=StringConcatenate("GMT ",TimeToString(GMT,TIME_MINUTES)),
   BRst=StringConcatenate("    Broker ",TimeToString(brokers,TIME_MINUTES)),
   Lcst=StringConcatenate("    Local ",TimeToString(localTime,TIME_SECONDS));} else{
   BRst=StringConcatenate("Broker ",TimeToString(brokers,TIME_MINUTES));GMTst="";Lcst="";}
   int tmm=MathFloor(T/60),tms=T-tmm*60;min2=tmm;sec2=tms;
   if(StringLen(sec2)==1)sec2="0"+sec2;int tmp2=TimeCurrent()-iTime(_Symbol,PERIOD_CURRENT,0);
   int tmm2=MathFloor(tmp2/60),tms2=tmp2-tmm2*60;min1=tmm2;sec1=tms2;
   if(StringLen(sec1)==1)sec1="0"+sec1;d=(base-1)*tmp2/(_Period*60);
   pc=100*tmp2/(_Period*60);if(pc>=100)pc=100;if(pc<10)p1="  ";if(d>base-1)d=base-1;
   if(d>0) beg=StringSubstr(line,0,d);if(d<base-1)end=StringSubstr(line,d+1,base-d-1);
   _time=StringConcatenate(beg,"|",end,"  ",p1,pc,"%");if(sec2<0){min2="00";sec2="00";}
   if(ObjectGet(name+"TIME",OBJPROP_SELECTED)>0)ObjectSet(name+"TIME",OBJPROP_SELECTED,0);
   if(ObjectGet(name+"RMT",OBJPROP_SELECTED)>0)ObjectSet(name+"RMT",OBJPROP_SELECTED,0);
   if(ObjectGet(name+"Spr",OBJPROP_SELECTED)>0)ObjectSet(name+"Spr",OBJPROP_SELECTED,0);
   SetATL(name+"Spr",23," SPREAD = "+Spread,8,"Arial",clrLime,1,12,2,0);
   SetATL(name+"TIME",23,GMTst+BRst+Lcst,8,"Tahoma",clrLime,5,1,2,0);if(_Period<PERIOD_W1){
   if(_Period<=PERIOD_H1)SetATL(name+"RMT",23,min1+":"+sec1+"....."+min2+":"+sec2+"   "+_time,11,"Arial",clrLime,200,2,1,0); else
   SetATL(name+"RMT",23,TimeToString(tmp2,TIME_SECONDS)+"....."+TimeToString(T,TIME_SECONDS)+"   "+_time,11,"Arial",clrLime,180,2,1,0);}}}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
void SetATL(string nm,int type,string txt,int fontsize,string font,color clr,int x,int y,int corn,bool back){
   ObjectCreate(nm,type,0,0,0);
   ObjectSet(nm,OBJPROP_CORNER,corn);
   ObjectSet(nm,OBJPROP_COLOR,clr);
   ObjectSet(nm,OBJPROP_BACK,back);
   ObjectSet(nm,OBJPROP_XDISTANCE,x);
   ObjectSet(nm,OBJPROP_YDISTANCE,y);
   ObjectSet(nm,OBJPROP_HIDDEN,1);
   ObjectSetText(nm,txt,fontsize,font,clr);}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
void ObjectsDelete(int wnd=-1,int type=-1,string pref=""){
   string names[];int n=ObjectsTotal();ArrayResize(names,n);
   for(int i=0;i<n;i++)names[i]=ObjectName(i);for(i=0;i<n;i++){
   if(wnd>=0)if(ObjectFind(names[i])!=wnd)continue;
   if(type>=0)if(ObjectType(names[i])!=type)continue;
   if(pref!="")if(StringSubstr(names[i],0,StringLen(pref))!=pref)continue;
   ObjectDelete(names[i]);}}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX THE END XXXXXXXXXXXXXXXXXXXXXXXXXXXXX