//+------------------------------------------------------------------+
//|                                          CandleSpread_modern.mq4 |
//|                                                         derMitay |
//|                                       www.forum.tradelikeapro.ru |
//+------------------------------------------------------------------+
#property copyright "derMitay"
#property link      "www.forum.tradelikeapro.ru"
#property version   "1.00"
#property description   "Especially for Pavel888";
#property indicator_separate_window
extern double SepCurSpread = 0.4;
extern color TextColor1 = clrLime;
extern color TextColor2 = clrRed;
extern ENUM_BASE_CORNER Corner = 0;
extern int XPosition = 10;
extern int YPosition = 50;
extern string Font = "Lucida Console";
extern int SizeFont = 10;
string sText = "";
string sName;
double MyPoint;
int iDivider = 1;
color TextColor;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   if (Point == 0.00001) MyPoint = 0.0001;
    else if (Point == 0.001) MyPoint = 0.01;
      else MyPoint = Point;
   
   iDivider = MyPoint / Point;
   
   for (int i = 0; i < 2; i++) 
   {
      sName = "TRS" + i;
      if (ObjectFind(0,sName) < 0) 
      {
         ObjectCreate(0,sName, OBJ_LABEL, ChartWindowOnDropped(), 0, 0);
         ObjectSet(sName, OBJPROP_XDISTANCE, XPosition);
         ObjectSet(sName, OBJPROP_YDISTANCE, YPosition + 17 * i);
         ObjectSet(sName, OBJPROP_CORNER, Corner);
      }
   }         
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   for (int i = 0; i < 4; i++) 
   {
      sName = "TRS" + i;
      ObjectDelete(sName);
   }
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   //TextColor = clrBlack;
   if (MarketInfo(Symbol(),MODE_SPREAD) >= SepCurSpread * iDivider) TextColor = TextColor2;
   else TextColor = TextColor1;
   sText = "";
   int iSecconds = Time[0] + 60 * Period() - TimeCurrent();
   int iMinutes = (iSecconds - iSecconds % 60) / 60;
   if (iMinutes > 0) sText = iMinutes + " MIN " + (iSecconds % 60) + " Sec left to candle close";
   else sText = (iSecconds % 60) + " Sec left to candle close";
   ObjectSetText("TRS0", sText, SizeFont, Font, TextColor1);
   sText = "Spread: " + DoubleToStr(MarketInfo(Symbol(), MODE_SPREAD) / iDivider, 1) + " pips";
   ObjectSetText("TRS1", sText, SizeFont, Font, TextColor);
   
   return(0);
  }
//+------------------------------------------------------------------+