DTS-Dolly_Trading Times #3

Author: Copyright � 2006, MetaQuotes Software Corp.
DTS-Dolly_Trading Times #3
0 Views
0 Downloads
0 Favorites
DTS-Dolly_Trading Times #3
//+------------------------------------------------------------------+
//|                                       Dolly_Trading Times #3.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property link      " Code used from  i-ParamonWorkTime.mq4 " 
#property indicator_chart_window

//    corner    - 0 = top left, 1 = top right, 2 = bottom left, 3 = bottom right
extern int          corner=3;

extern string Broker_GMT_Offset = "00:00";

extern int     TradingTimes_NumberOfDays = 2; 
extern string  EUROPE_Open       = "06:00";
extern color   EUROPE_Color      = Purple; 
extern color   EUROPE_TEXT_Color = Purple;
extern bool    Show_EUROPE_Open = true;

extern string  LONDON_Open      = "7:00";  
extern color   LONDON_Color      = MidnightBlue;
extern color   LONDON_TEXT_Color = MidnightBlue;
extern bool    Show_LONDON_Open  = true;

extern string  US_Open       = "12:00";
extern color   US_Color      = Indigo;
extern color   US_TEXT_Color = Indigo;
extern bool    Show_US_Open = true;

extern string  EUROPE1_Close       = "16:00";
extern color   EUROPE1_Color      = Maroon;
extern color   EUROPE1_TEXT_Color =Maroon;
extern bool    Show_EUROPE1_Close = true;

extern bool Show_Daily_Trade_TEXT = true;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void init() 
{
   DeleteObjects();
   for (int i=0; i<TradingTimes_NumberOfDays; i++) 
   {
    CreateObjects("DollyTIME1"+i, EUROPE_Color);
    CreateObjects("DollyTIME2"+i, LONDON_Color);
    CreateObjects("DollyTIME3"+i, US_Color);
    CreateObjects("DollyTIME4"+i, EUROPE1_Color); 
   }
   
   int top = 200;//topOff;
   int left = 60;
   ObjectMakeLabel( "TT1", left, top );
   ObjectMakeLabel( "TT2", 13, top );
   ObjectMakeLabel( "TT3", left, top-15 );
   ObjectMakeLabel( "TT4", 13, top-15 );
   ObjectMakeLabel( "TT5", left, top-30 );
   ObjectMakeLabel( "TT6", 13, top-30 );
   ObjectMakeLabel( "TT7", left, top-45 );
   ObjectMakeLabel( "TT8", 13, top-45 );

}


//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
void deinit() 
{
   DeleteObjects();
   ObjectDelete("TT1");ObjectDelete("TT2");ObjectDelete("TT3");
   ObjectDelete("TT4");ObjectDelete("TT5");ObjectDelete("TT6");
   ObjectDelete("TT7");ObjectDelete("TT8");
}

//+------------------------------------------------------------------+
void CreateObjects(string TRADETIMES, color cl) 
{
  ObjectCreate(TRADETIMES, OBJ_TREND, 0, 0,0, 0,0);
  ObjectSet(TRADETIMES, OBJPROP_STYLE, STYLE_DOT);
  ObjectSet(TRADETIMES, OBJPROP_WIDTH,1);
  ObjectSet(TRADETIMES, OBJPROP_COLOR, cl);
  ObjectSet(TRADETIMES, OBJPROP_BACK, True);
}

//+------------------------------------------------------------------+
void DeleteObjects() 
{
  for (int i=0; i<TradingTimes_NumberOfDays; i++) {
    ObjectDelete("DollyTIME"+i);
    ObjectDelete("DollyTIME"+i);
    ObjectDelete("DollyTIME"+i);
    ObjectDelete("DollyTIME"+i);   
  }
}


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void start()
 {  
 
  datetime dt=CurTime();

  for (int i=0; i<TradingTimes_NumberOfDays; i++) {
  if (Show_EUROPE_Open==true)
  {
    DrawObjects(dt, "DollyTIME1"+i, EUROPE_Open, EUROPE_Open);}
   if (Show_LONDON_Open==true)
   {
    DrawObjects(dt, "DollyTIME2"+i, LONDON_Open, LONDON_Open);}
   if (Show_US_Open==true)
   { 
    DrawObjects(dt, "DollyTIME3"+i, US_Open, US_Open);}
   if (Show_EUROPE1_Close==true)
   { 
    DrawObjects(dt, "DollyTIME4"+i, EUROPE1_Close, EUROPE1_Close);}
    
    dt=decDateTradeDay(dt);
    while (TimeDayOfWeek(dt)>5) dt=decDateTradeDay(dt);
  }
}


//+------------------------------------------------------------------+
void DrawObjects(datetime dt, string TRADETIMES, string tb, string te) 
{
   datetime t1, t2;
   double   p1, p2;
   int      b1, b2;

   t1=StrToTime(TimeToStr(dt, TIME_DATE)+" "+tb);
   t2=StrToTime(TimeToStr(dt, TIME_DATE)+" "+te);
   b1=iBarShift(NULL, 0, t1);
   b2=iBarShift(NULL, 0, t2);
   p1=High[Highest(NULL, 0, MODE_HIGH, b1-b2, b2)];
   p2=Low [Lowest (NULL, 0, MODE_LOW , b1-b2, b2)];
  
   ObjectSet(TRADETIMES, OBJPROP_TIME1 , t1);
   ObjectSet(TRADETIMES, OBJPROP_PRICE1, p1);
   ObjectSet(TRADETIMES, OBJPROP_TIME2 , t2);
   ObjectSet(TRADETIMES, OBJPROP_PRICE2, p2);  

   if (Show_Daily_Trade_TEXT==true)
   {
      ObjectSetText( "TT1", "EUROPE Open", 8, "Arial", EUROPE_TEXT_Color );
      ObjectSetText( "TT2", ""+EUROPE_Open+"", 8, "Arial", Silver );

      ObjectSetText( "TT3", "LONDON Open", 8, "Arial", LONDON_TEXT_Color );
      ObjectSetText( "TT4", ""+LONDON_Open+"", 8, "Arial", Silver );

      ObjectSetText( "TT5", "US Open", 8, "Arial", US_TEXT_Color );
      ObjectSetText( "TT6", ""+US_Open+"", 8, "Arial", Silver );

      ObjectSetText( "TT7", "EUROPE Open", 8, "Arial", EUROPE_TEXT_Color );
      ObjectSetText( "TT8", ""+EUROPE1_Close+"", 8, "Arial", Silver );
   } 
}


//+------------------------------------------------------------------+
datetime decDateTradeDay (datetime dt) {
  int ty=TimeYear(dt);
  int tm=TimeMonth(dt);
  int td=TimeDay(dt);
  int th=TimeHour(dt);
  int ti=TimeMinute(dt);

  td--;
  if (td==0) {
    tm--;
    if (tm==0) {
      ty--;
      tm=12;
    }
    if (tm==1 || tm==3 || tm==5 || tm==7 || tm==8 || tm==10 || tm==12) td=31;
    if (tm==2) if (MathMod(ty, 4)==0) td=29; else td=28;
    if (tm==4 || tm==6 || tm==9 || tm==11) td=30;
  }
  return(StrToTime(ty+"."+tm+"."+td+" "+th+":"+ti));
}

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int ObjectMakeLabel( string n, int xoff, int yoff ) {
   ObjectCreate( n, OBJ_LABEL, 0, 0, 0 );
   ObjectSet( n, OBJPROP_CORNER, corner );
   ObjectSet( n, OBJPROP_XDISTANCE, xoff );
   ObjectSet( n, OBJPROP_YDISTANCE, yoff );
   ObjectSet( n, OBJPROP_BACK, true );
}

Comments