Navigation:Home > Content >

cstime_edit.mq4

Time: 2018-06-25 | Download file:cstime_edit.mq4

#property copyright "Copyright © 2008, BlueDreamFx"
#property link      "http://www.BlueDreamFX.Blogspot.Com"

#property indicator_chart_window

#include 

//extern int RefCandleHiLoSL=240;
extern int Win_Signal=0;
extern color clrText=DimGray;
extern int y=175;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

   IndicatorShortName("");

   InitLabelTimer();
   
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   DeleteLabelTimer();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
      PaintCandleTime(PERIOD_M5);
      PaintCandleTime(PERIOD_M15);
      PaintCandleTime(PERIOD_M30);
      PaintCandleTime(PERIOD_H1);
      PaintCandleTime(PERIOD_H4);
      PaintCandleTime(PERIOD_D1);
      PaintCandleTime(PERIOD_W1);
      //PaintCandleTime(PERIOD_MN1);
}
//+------------------------------------------------------------------+

void CreateLabel(string name, string text,
                   int x,int y,
                   int Corner=1,int winF=0, 
                   string font="Arial Narrow",int size=10,color colour=CLR_NONE)
  {
   winF=Win_Signal;

   if(colour==CLR_NONE)colour=clrText;
  
   ObjectCreate(name,OBJ_LABEL,winF,0,0);
   ObjectSet(name,OBJPROP_CORNER,Corner);
   ObjectSet(name,OBJPROP_XDISTANCE,x);
   ObjectSet(name,OBJPROP_YDISTANCE,y);
   ObjectSetText(name,text,size,font,colour);
  }

string GetTFName(int TF)
{
switch(TF)
   {
   case PERIOD_M1 :
      return ("M1");
      break;
   case PERIOD_M5 :
      return ("M5");
      break;
   case PERIOD_M15 :
      return ("M15");
      break;
   case PERIOD_M30 :
      return ("M30");
      break;
   case PERIOD_H1 :
      return ("H1");
      break;
   case PERIOD_H4 :
      return ("H4");
      break;
   case PERIOD_D1 :
      return ("D1");
      break;
   case PERIOD_W1 :
      return ("W1");
      break;
   //case PERIOD_MN1 :
   //   return ("MN1");
   //   break;
   default :
      return ("Invalid TF");
      break;
   }
}
//********************************************************************************

void InitLabelTimer()
{
   CreateLabel("lblTimeComplete","Complete"  ,75,y+10,1,Win_Signal,"Arial Narrow",10);
   CreateLabel("lblTimeCompleteM5","..."     ,75,y+25);
   CreateLabel("lblTimeCompleteM15","..."    ,75,y+40);
   CreateLabel("lblTimeCompleteM30","..."    ,75,y+55);
   CreateLabel("lblTimeCompleteH1","..."     ,75,y+70);
   CreateLabel("lblTimeCompleteH4","..."     ,75,y+85);
   CreateLabel("lblTimeCompleteD1","..."     ,75,y+100);
   CreateLabel("lblTimeCompleteW1","..."     ,75,y+115);
   //CreateLabel("lblTimeCompleteMN1","..."    ,75,y+90);

   CreateLabel("lblTimeLeft","Time Left"     ,10,y+10,1,Win_Signal,"Arial Narrow",10);
   CreateLabel("lblTimeLeftM5","..."         ,10,y+25);
   CreateLabel("lblTimeLeftM15","..."        ,10,y+40);
   CreateLabel("lblTimeLeftM30","..."        ,10,y+55);
   CreateLabel("lblTimeLeftH1","..."         ,10,y+70);
   CreateLabel("lblTimeLeftH4","..."         ,10,y+85);
   CreateLabel("lblTimeLeftD1","..."         ,10,y+100);
   CreateLabel("lblTimeLeftW1","..."         ,10,y+115);
   //CreateLabel("lblTimeLeftMN1","..."        ,10,y+90);

   CreateLabel("lbltimer","TF"    ,130,y+10,1,Win_Signal,"Arial Narrow",10);
   CreateLabel("lblM5timer","M5"  ,130,y+25,1,Win_Signal,"Arial Narrow",10);
   CreateLabel("lblM15timer","M15",130,y+40,1,Win_Signal,"Arial Narrow",10);
   CreateLabel("lblM30timer","M30",130,y+55,1,Win_Signal,"Arial Narrow",10);
   CreateLabel("lblH1timer","H1"  ,130,y+70,1,Win_Signal,"Arial Narrow",10);
   CreateLabel("lblH4timer","H4"  ,130,y+85,1,Win_Signal,"Arial Narrow",10);
   CreateLabel("lblD1timer","D1"  ,130,y+100,1,Win_Signal,"Arial Narrow",10);
   CreateLabel("lblW1timer","W1"  ,130,y+115,1,Win_Signal,"Arial Narrow",10);
   //CreateLabel("lblMN1timer","MN1",130,y+90,1,Win_Signal,"Arial",8);

   CreateLabel("lblHL3","------------------------------------",10,y+0,1,Win_Signal,"Arial",9);
   CreateLabel("lblHL4","------------------------------------",10,y+2,1,Win_Signal,"Arial",9);
   //CreateLabel("lblTitleTimer","Candle Time © BlueDreamFx",10,y+110,1,Win_Signal,"Arial",7);
   CreateLabel("lblHL5","------------------------------------",10,y+122,1,Win_Signal,"Arial",9);
   CreateLabel("lblHL6","------------------------------------",10,y+124,1,Win_Signal,"Arial",9);
}

void DeleteLabelTimer()
{
   ObjectDelete("lblTimeComplete");
   ObjectDelete("lblTimeCompleteM5");
   ObjectDelete("lblTimeCompleteM15");
   ObjectDelete("lblTimeCompleteM30");
   ObjectDelete("lblTimeCompleteH1");
   ObjectDelete("lblTimeCompleteH4");
   ObjectDelete("lblTimeCompleteD1");
   ObjectDelete("lblTimeCompleteW1");
   //ObjectDelete("lblTimeCompleteMN1");

   ObjectDelete("lblTimeLeft");
   ObjectDelete("lblTimeLeftM5");
   ObjectDelete("lblTimeLeftM15");
   ObjectDelete("lblTimeLeftM30");
   ObjectDelete("lblTimeLeftH1");
   ObjectDelete("lblTimeLeftH4");
   ObjectDelete("lblTimeLeftD1");
   ObjectDelete("lblTimeLeftW1");
   //ObjectDelete("lblTimeLeftMN1");

   ObjectDelete("lbltimer");
   ObjectDelete("lblM5timer");
   ObjectDelete("lblM15timer");
   ObjectDelete("lblM30timer");
   ObjectDelete("lblH1timer");
   ObjectDelete("lblH4timer");
   ObjectDelete("lblD1timer");
   ObjectDelete("lblW1timer");
   //ObjectDelete("lblMN1timer");

   ObjectDelete("lblHL6");
   ObjectDelete("lblHL4");
   ObjectDelete("lblTitleTimer");
   ObjectDelete("lblHL5");
}

void PaintCandleTime(int TF)
{
   color Clr;
   int TimeComplete;

   TimeComplete=TimeCompletePercent(TF);

   if (TimeComplete >=75) Clr = Lime;
   else if (TimeComplete >=25) Clr = Yellow;
   else Clr = White;

   ObjectSetText("lblTimeLeft"+GetTFName(TF),TimeLeft(TF), 10,"Arial Narrow", Clr);
   ObjectSetText("lblTimeComplete"+GetTFName(TF),StringConcatenate(TimeComplete, " %"), 10,"Arial Narrow", Clr);
}  

int TimeCompletePercent(int TF)
{   
   return(100 * ((TF*60)-(iTime(Symbol(),TF,0)+TF*60-CurTime()))  /(TF*60));
}  

string TimeLeft(int TF)
{
   int Hr=0,Min,Sec;
   int TheTime;

   TheTime=iTime(Symbol(),TF,0)+TF*60-CurTime();
   
   Min = TheTime / 60;
   if (Min>=60)
      {
      Hr=Min/60;
      Min=Min%60;
      }
   Sec = TheTime % 60;

   return(StringConcatenate(XNo(Hr),":",XNo(Min),":", XNo(Sec)));
}  

string XNo(int no)
{
   if(no<10)return(StringConcatenate("0",no));
   else return(DoubleToStr(no,0));
}

Recommend