//+------------------------------------------------------------------+
//|                                                         TLSS.mq4 |
//|                               Copyright 2014, Andriy Ostafiychuk |
//|                       https://login.mql5.com/ru/users/geoscience |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Andriy Ostafiychuk"
#property link      "https://login.mql5.com/ru/users/geoscience"
#property version   "1.00"
#property indicator_chart_window

extern bool   Clock      = true;  //Show Clock?
extern bool   Leverage   = true;  //Show Leverage?
extern bool   Swap       = true;  //Show Swap?
extern bool   Spread     = true;  //Show Spread?
extern bool   Background = true;  //Show Background?
extern string FontType        = "Verdana";
extern int    FontSize        = 10;
extern color  Clock_Color     = Yellow;
extern color  General_text    = White;
extern color  Swap_Buy_Color  = Red;
extern color  Swap_Sell_Color = Gainsboro;
extern color  Background_Color = DarkSlateGray;
extern color  Background_Frame = Gainsboro;

int i;
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorShortName("TLSS "+Symbol());
   if(Background)
     {
      ObjectCreate(0,"TLSS_bg",OBJ_RECTANGLE_LABEL,0,0,0);
      ObjectSetInteger(0,"TLSS_bg",OBJPROP_XDISTANCE,5);
      ObjectSetInteger(0,"TLSS_bg",OBJPROP_YDISTANCE,20);
      ObjectSetInteger(0,"TLSS_bg",OBJPROP_YSIZE,90);
      ObjectSetInteger(0,"TLSS_bg",OBJPROP_XSIZE,150);
      ObjectSetInteger(0,"TLSS_bg",OBJPROP_BGCOLOR,Background_Color);
      ObjectSetInteger(0,"TLSS_bg",OBJPROP_BORDER_TYPE,BORDER_FLAT);
      ObjectSetInteger(0,"TLSS_bg",OBJPROP_COLOR,Background_Frame);
      ObjectSetInteger(0,"TLSS_bg",OBJPROP_STYLE,STYLE_SOLID);
      ObjectSetInteger(0,"TLSS_bg",OBJPROP_WIDTH,1);
     }
   Sleep(100);
   EventSetTimer(1); // Corrected function call
   if(Clock) comment(0,Clock_Color,"",TimeToStr(TimeLocal(),TIME_SECONDS));
   if(Swap)
     {
      comment(2,Swap_Buy_Color,"Buy Swap: ",DoubleToStr(MarketInfo(Symbol(),MODE_SWAPLONG),2));
      comment(3,Swap_Sell_Color,"Sell Swap: ",DoubleToStr(MarketInfo(Symbol(),MODE_SWAPSHORT),2));
     }
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   int obj_total=ObjectsTotal();
   for(int obj=obj_total-1; obj>=0; obj--)
     {
      string objname=ObjectName(obj);
      if(StringFind(objname,"TLSS")>=0)ObjectDelete(objname);
     }
   EventKillTimer();
  }
//+------------------------------------------------------------------+
//|  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[])
  {
   if(Leverage) comment(1,General_text,"Leverage:  1:",IntegerToString(AccountLeverage()));
   if(Spread) comment(4,General_text,"Current spread: ",DoubleToStr(MarketInfo(Symbol(),MODE_SPREAD),0));
   return(rates_total);
  }
//+------------------------------------------------------------------+
void OnTimer()
  {
   if(Clock) comment(0,Clock_Color,"",TimeToStr(TimeLocal(),TIME_SECONDS));
   return;
  }
//+------------------------------------------------------------------+
//|  Output parameters in objects                                    |
//+------------------------------------------------------------------+
void comment(int n,color c,string s0="",string s1="")
  {
   string r=s0+s1;
   string name="TLSS_"+IntegerToString(n);
   int y=25+n*15;
   int x=10;
   if(ObjectFind(name)<0) ObjectCreate(name,OBJ_LABEL,0,0,0);
   ObjectSet(name,OBJPROP_XDISTANCE,x);
   ObjectSet(name,OBJPROP_YDISTANCE,y);
   ObjectSetText(name,r,FontSize,FontType,c);
  }
//+------------------------------------------------------------------+
