有您的持续关注
我们会做得更好

MT4自定义指标 全球主要外汇市场开闭市时间指标



全球主要外汇市场开闭市时间指标,可以根据设置的时间在图表上显示各外汇交易市场开闭市的时间。

参数Broker_GMT_Offset = “00:00”;如果你依照GTM标准时间计算,那么这里就是设置时间偏差。

参数  int y = 220, 为Y轴位置调整。

参数 ObjectSet   (Text,OBJPROP_XDISTANCE , 930);为水平位置调整,三个地方同步加减。

调用图表效果如下:

MT4外汇主要市场开闭市时间指标MQL4源码如下:

//+------------------------------------------------------------------+
//|                                                   开闭市时间.mq4 |
//|                                       Copyright @2013, 125808047 |
//+------------------------------------------------------------------+
#property copyright "Copyright @2014, 125808047"
#property link      "http://www.125808047.com"
#property indicator_chart_window

extern string Broker_GMT_Offset = "00:00";


extern int    TradingTimes_NumberOfDays = 1; 
extern string EUROPE_Open       = "10:00 18:00";
extern color  EUROPE_Color      = Purple; 
extern color  EUROPE_TEXT_Color = Violet;
extern bool Show_EUROPE_Open = true;

extern string LONDON_Open      = "10:30 18:30";  
extern color  LONDON_Color      = MidnightBlue;
extern color  LONDON_TEXT_Color = DodgerBlue;
extern bool Show_LONDON_Open  = true;

extern string US_Open       = "15:20 22:00";
extern color  US_Color      = Indigo;
extern color  US_TEXT_Color = MediumPurple;
extern bool Show_US_Open = true;

extern string NZ_Open       = "21:00 05:00";
extern color  NZ_Color      = Tomato;
extern color  NZ_TEXT_Color = Tomato;
extern bool Show_NZ_Open = true;

extern string AU_Open       = "02:00 09:00";
extern color  AU_Color      = Maroon;
extern color  AU_TEXT_Color = Crimson;
extern bool Show_AU_Open = true;

extern string TOKIO_Open       = "00:00 06:00";
extern color  TOKIO_Color      = Maroon;
extern color  TOKIO_TEXT_Color = Crimson;
extern bool Show_TOKIO_Open = true;

extern string STOCK_Open       = "16:30 23:00";
extern color  STOCK_Color      = Maroon;
extern color  STOCK_TEXT_Color = YellowGreen;
extern bool Show_STOCK_Open = false;

extern bool Show_Daily_Trade_TEXT = true;




//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void init() {
  DeleteObjects(); 
}

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
void deinit() {
  DeleteObjects();
  ObjectDelete("TT1");ObjectDelete("TT2");ObjectDelete("TT3");
  ObjectDelete("TT4");ObjectDelete("TT5");ObjectDelete("TT6");
  ObjectDelete("TT7");ObjectDelete("TT8");ObjectDelete("TT9");
  ObjectDelete("TT10");ObjectDelete("TT11");ObjectDelete("TT12");
  ObjectDelete("TT13");ObjectDelete("TT14");ObjectDelete("TT15");
  ObjectDelete("TT16");ObjectDelete("TT17");ObjectDelete("TT18");
  ObjectDelete("TT19");ObjectDelete("TT20");ObjectDelete("TT21");
}

void DeleteObjects() {
  for (int i=0; i<TradingTimes_NumberOfDays; i++) {
    ObjectDelete("DollyTIME1"+i);
    ObjectDelete("DollyTIME2"+i);
    ObjectDelete("DollyTIME3"+i);
    ObjectDelete("DollyTIME4"+i);
   
  }
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void start()
 {  
  DrawTradetimes();
}

void DrawTradetimes()
{

 if (Show_Daily_Trade_TEXT==true)
 {
   int y = 220, ystep = 15;
   datetime dt = TimeCurrent();
   
   
   if(Show_EUROPE_Open)
   {
   ObjectDelete("TT1");
   y = y + ystep;
   TT1( "TT1", y, 12,4);
   ObjectSetText( "TT1","EUROPE Open" , 9, "Arial", EUROPE_TEXT_Color);
    
   ObjectDelete("TT2");
   TT2( "TT2", y, 12,4);
   if(intradetime(dt,EUROPE_Open) )
   ObjectSetText( "TT2",""+ StringSubstr(EUROPE_Open,0,5) +"" , 9, "Arial", Green);
   else
   ObjectSetText( "TT2",""+ StringSubstr(EUROPE_Open,0,5) +"" , 9, "Arial", Silver);
   
   ObjectDelete("TT3");
   TT3( "TT3", y, 12,4);
   ObjectSetText( "TT3",""+ StringSubstr(EUROPE_Open,6)+"" , 9, "Arial", Silver);
   }
   
   if(Show_LONDON_Open)
   {
   y = y + ystep;
   ObjectDelete("TT4");
   TT1( "TT4", y, 12,4);
   ObjectSetText( "TT4","LONDON Open" , 9, "Arial", LONDON_TEXT_Color);
    
   ObjectDelete("TT5");
   TT2( "TT5", y, 12,4);
   if(intradetime(dt,LONDON_Open) )
   ObjectSetText( "TT5",""+ StringSubstr(LONDON_Open,0,5) +"" , 9, "Arial", Green);
   else
   ObjectSetText( "TT5",""+StringSubstr(LONDON_Open,0,5)+"" , 9, "Arial", Silver);
   
   ObjectDelete("TT6");
   TT3( "TT6", y, 12,4);
   ObjectSetText( "TT6",""+ StringSubstr(LONDON_Open,6)+"" , 9, "Arial", Silver);
   }
   
   if(Show_US_Open)
   {
   y = y + ystep;
   ObjectDelete("TT7");
   TT1( "TT7", y, 12,4);
   ObjectSetText( "TT7","US Open" , 9, "Arial", US_TEXT_Color);
    
   ObjectDelete("TT8");
   TT2( "TT8", y, 12,4);
   if(intradetime(dt,US_Open) )
   ObjectSetText( "TT8",""+ StringSubstr(US_Open,0,5) +"" , 9, "Arial", Green);
   else
   ObjectSetText( "TT8",""+StringSubstr(US_Open,0,5)+"" , 9, "Arial", Silver);
   
   ObjectDelete("TT9");
   TT3( "TT9", y, 12,4);
   ObjectSetText( "TT9",""+ StringSubstr(US_Open,6)+"" , 9, "Arial", Silver);
   }
   
   if(Show_STOCK_Open)
   {
   y = y + ystep;
   ObjectDelete("TT10");
   TT1( "TT10", y, 12,4);
   ObjectSetText( "TT10","STOCK OPEN" , 9, "Arial", STOCK_TEXT_Color );
   
   ObjectDelete("TT11");
   TT2( "TT11", y, 12,4);
   if(intradetime(dt,STOCK_Open) )
   ObjectSetText( "TT11",""+ StringSubstr(STOCK_Open,0,5) +"" , 9, "Arial", Green);
   else
   ObjectSetText( "TT11",""+StringSubstr(STOCK_Open,0,5)+"" , 9, "Arial", Silver);
   
   ObjectDelete("TT12");
   TT3( "TT12", y, 12,4);
   ObjectSetText( "TT12",""+ StringSubstr(STOCK_Open,6)+"" , 9, "Arial", Silver);
   }
   
   if(Show_NZ_Open)
   {
   y = y + ystep;
   ObjectDelete("TT19");
   TT1( "TT19", y, 12,4);
   ObjectSetText( "TT19","NZ OPEN" , 9, "Arial", NZ_TEXT_Color );
   
   ObjectDelete("TT20");
   TT2( "TT20", y, 12,4);
   if(intradetime(dt,NZ_Open) )
   ObjectSetText( "TT20",""+ StringSubstr(NZ_Open,0,5) +"" , 9, "Arial", Green);
   else
   ObjectSetText( "TT20",""+StringSubstr(NZ_Open,0,5)+"" , 9, "Arial", Silver);
   
   ObjectDelete("TT21");
   TT3( "TT21", y, 12,4);
   ObjectSetText( "TT21",""+ StringSubstr(NZ_Open,6)+"" , 9, "Arial", Silver);
   }
      
   if(Show_AU_Open)
   {
   y = y + ystep;
   ObjectDelete("TT13");
   TT1( "TT13", y, 12,4);
   ObjectSetText( "TT13","AU OPEN" , 9, "Arial", AU_TEXT_Color );
    
   ObjectDelete("TT14");
   TT2( "TT14", y, 12,4);
   if(intradetime(dt,AU_Open) )
   ObjectSetText( "TT14",""+ StringSubstr(AU_Open,0,5) +"" , 9, "Arial", Green);
   else
   ObjectSetText( "TT14",""+StringSubstr(AU_Open,0,5)+"" , 9, "Arial", Silver);
   
   ObjectDelete("TT15");
   TT3( "TT15", y, 15,4);
   ObjectSetText( "TT15",""+ StringSubstr(AU_Open,6)+"" , 9, "Arial", Silver);
   }
   
   if(Show_TOKIO_Open)
   {
   y = y + ystep;
   ObjectDelete("TT16");
   TT1( "TT16", y, 12,4);
   ObjectSetText( "TT16","TOKIO OPEN" , 9, "Arial", TOKIO_TEXT_Color );
   
   ObjectDelete("TT17");
   TT2( "TT17", y, 12,4);
   if(intradetime(dt,TOKIO_Open) )
   ObjectSetText( "TT17",""+ StringSubstr(TOKIO_Open,0,5) +"" , 9, "Arial", Green);
   else
   ObjectSetText( "TT17",""+StringSubstr(TOKIO_Open,0,5)+"" , 9, "Arial", Silver);
   
   ObjectDelete("TT18");
   TT3( "TT18", y, 15,4);
   ObjectSetText( "TT18",""+ StringSubstr(TOKIO_Open,6)+"" , 9, "Arial", Silver);
   }
  } 
}

bool intradetime(datetime dt, string tradetime)
{
   string tradeb = StringSubstr(tradetime,0,5);
   string tradee = StringSubstr(tradetime,6);
   datetime t1 = StrToTime(TimeToStr(dt,TIME_DATE) + " " + tradeb);
   datetime t2 = StrToTime(TimeToStr(dt,TIME_DATE) + " " + tradee);
   t1 = brokertime(t1);
   t2 = brokertime(t2);
   
   if(t1>t2)
      t1 = t1 - oneday();
   
   if(dt >= t1 && dt<=t2)
      return(true);
   else
      return(false);
}

datetime brokertime(datetime GMTtime)
{
   datetime offset = StrToTime(TimeToStr(GMTtime,TIME_DATE) + " " + Broker_GMT_Offset)
                     -StrToTime(TimeToStr(GMTtime,TIME_DATE));
   return (GMTtime + offset);
}
datetime oneday()
{
   datetime dt = TimeCurrent();
   string span = "23:59:59";
   
   datetime re = StrToTime(TimeToStr(dt,TIME_DATE) + " " + span)
                     -StrToTime(TimeToStr(dt,TIME_DATE)) + 1;
   return (re);
}
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));
}
//+------------------------------------------------------------------+
int TT1( string Text, int xOffset, int yOffset,int iCorner) //TITLE
{  ObjectCreate(Text,OBJ_LABEL         , 0, 0, 0 );
   ObjectSet   (Text,OBJPROP_CORNER    , iCorner);
   ObjectSet   (Text,OBJPROP_XDISTANCE , 930);
   ObjectSet   (Text,OBJPROP_YDISTANCE , xOffset );
   ObjectSet   (Text,OBJPROP_BACK      , True );
 return (0);
}
int TT2( string Text, int xOffset, int yOffset,int iCorner) //TITLE
{  ObjectCreate(Text,OBJ_LABEL         , 0, 0, 0 );
   ObjectSet   (Text,OBJPROP_CORNER    , iCorner);
   ObjectSet   (Text,OBJPROP_XDISTANCE , 1030);
   ObjectSet   (Text,OBJPROP_YDISTANCE , xOffset );
   ObjectSet   (Text,OBJPROP_BACK      , True );
 return (0);
}
int TT3( string Text, int xOffset, int yOffset,int iCorner) //TITLE
{  ObjectCreate(Text,OBJ_LABEL         , 0, 0, 0 );
   ObjectSet   (Text,OBJPROP_CORNER    , iCorner);
   ObjectSet   (Text,OBJPROP_XDISTANCE , 1070);
   ObjectSet   (Text,OBJPROP_YDISTANCE , xOffset );
   ObjectSet   (Text,OBJPROP_BACK      , True );
 return (0);
}

如您喜欢此文章请点下面分享按钮↴峰汇在线 » MT4自定义指标 全球主要外汇市场开闭市时间指标
上一篇:
下一篇:
分享到:更多 ()