诚信为本
量力而为
当前位置:首页MetaTrader 4MT4指标指标 Hans Indicator3

指标 Hans Indicator3

Hans Indicator3指标是Hans Indicator的另一优化。

Hans Indicator3指标图表:Hans Indicator3指标

Hans Indicator3指标源码:

//+------------------------------------------------------------------+
//|                                               Hans Indicator3.mq4|
//|                                                         Shimodax |
//+------------------------------------------------------------------+
#property copyright "Copyright Shimodax"
#property link      "http://www.125808047.com/"

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Green
#property indicator_color2 Green
#property indicator_color3 LightGray
#property indicator_color4 LightGray
#property indicator_color5 Blue

extern int LocalTimeZone= 2;
extern int DestTimeZone= 6;
extern int PipsForEntry= 5;

double Zone1Upper[];
double Zone2Upper[];
double Zone1Lower[];
double Zone2Lower[];
double SignalsBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit(void)
  {
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Zone1Upper);
   SetIndexEmptyValue(0, 0.0);

   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Zone1Lower);
   SetIndexEmptyValue(1, 0.0);

   SetIndexStyle(2,DRAW_NONE);
   SetIndexBuffer(2,Zone2Upper);
   SetIndexEmptyValue(2, 0.0);

   SetIndexStyle(3,DRAW_NONE);
   SetIndexBuffer(3,Zone2Lower);
   SetIndexEmptyValue(3, 0.0);

   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4, 156);
   SetIndexBuffer(4, SignalsBuffer);
}

   void OnDeinit(const int reason)
     {
     Comment("www.125808047.com");
     }
//+------------------------------------------------------------------+
//| 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[])
  {
   int counted_bars= IndicatorCounted(),
         lastbar;

   if (Bars<=100) 
      return(0);
      
   if (counted_bars>0)
      counted_bars--;
      
   lastbar= Bars - counted_bars;
   
   BreakoutRanges(0, lastbar, LocalTimeZone, DestTimeZone);
   
   return(rates_total);
}
//+------------------------------------------------------------------+
//| Compute index of first/last bar of yesterday and today           |
//+------------------------------------------------------------------+
int BreakoutRanges(int offset, int lastbar, int tzlocal, int tzdest)
{     
   int i, j, k,
       tzdiff= tzlocal - tzdest,
       tzdiffsec= tzdiff*3600, 
       tidxstart[2]= { 0, 0}, 
       tidxend[2]= { 0, 0 };
   double thigh[2]= { 0.0, 0.0 }, 
           tlow[2]= { 99999.9, 99999.9 };
   string tfrom[3]= { "04:00", "08:00" ,  /*rest of day: */ "12:00"},
          tto[3]=   { "08:00", "12:00",   /*rest of day: */ "24:00" },
          tday;
   bool inperiod= -1;
   datetime timet;

   tday= TimeToStr(Time[lastbar]-tzdiffsec, TIME_DATE);   
   for (  ; lastbar<Bars; lastbar++) {
      if (TimeToStr(Time[lastbar] - tzdiffsec, TIME_DATE)!=tday) {
         lastbar--;
         break;      
      }
   }   

   tday= "XXX";
   for (i= lastbar; i>=offset; i--) {
   
      timet= Time[i] - tzdiffsec;  
      
      string timestr= TimeToStr(timet, TIME_MINUTES),   
             thisday= TimeToStr(timet, TIME_DATE);      

      for (j= 0; j<3; j++) {
      
         if (tfrom[j]<=timestr && timestr<tto[j]) {  
      
            if (inperiod!=j) { 
                                 
               if (j>0) {      
               
                  for (k= tidxstart[j-1]; k>=tidxend[j-1]; k--) {
                     if (j-1==0) {
                        Zone1Upper[k]= thigh[j-1];
                        Zone1Lower[k]= tlow[j-1];
                     }

                     if (j-1==1) {
                        Zone2Upper[k]= thigh[j-1];
                        Zone2Lower[k]= tlow[j-1];
                     }
                  }
               }
               
               inperiod= j;  
            }
            
            if (inperiod==2) 
               break;

            if (tidxstart[j]==0) {
               tidxstart[j]= i;
               tday= thisday;
            }
         
            tidxend[j]= i;
      
            thigh[j]= MathMax(thigh[j], High[i]);
            tlow[j]= MathMin(tlow[j], Low[i]);
         }
      }

      if (inperiod>=1 && tday==thisday) { 
         Zone1Upper[i]= thigh[0] + (MathAbs(thigh[0]-tlow[0])) + PipsForEntry*Point;
         Zone1Lower[i]= tlow[0] - (MathAbs(thigh[0]-tlow[0])) - PipsForEntry*Point;
         
         if (inperiod>=2) {   
            Zone2Upper[i]= thigh[1] + PipsForEntry*Point;
            Zone2Lower[i]= tlow[1] - PipsForEntry*Point;
         }
      }
      else {   
         Zone1Upper[i]= 0;
         Zone1Lower[i]= 0;
         Zone2Upper[i]= 0;
         Zone2Lower[i]= 0;
      }

      if (tday!="XXX" && tday!=thisday) {
         Print("#", i, "new day ", thisday, "/", tday);
      
         tday= "XXX";
         
         inperiod= -1;
         
         for (j= 0; j<2; j++) {
            tidxstart[j]= 0;
            tidxend[j]= 0;
         
            thigh[j]= 0;
            tlow[j]= 99999;
         }
      }
   }
   return (0);       
}
版权所有转载请注明标题及链接:峰汇在线 » 指标 Hans Indicator3
上一篇:
下一篇:
分享到: 更多 (0)