诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

自定义指标 DIBSv1.0.mq4

DIBSv1.0指标在主图标识特定K线,并绘制线段为分析行情提供参考。

图表:DIBSv1.0指标

源码:

//+------------------------------------------------------------------+
//|                                                     DIBSv1.0.mq4 |
//|                       Copyright @free84, Midnite and NuckingFuts |
//+------------------------------------------------------------------+
#property copyright "Copyright @free84, Midnite and NuckingFuts"
#property link      "http://www.125808047.com"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 RoyalBlue
#property indicator_width1 2
#property indicator_color2 RoyalBlue
#property indicator_width2 2
#property indicator_color3 FireBrick
#property indicator_style3 2
#property indicator_width3 1

extern bool   Show_IB              = true;
extern bool   Show_Daily_Open_Line = true;
extern bool   Show_Remain_Bar_Time = true;
extern int    Timezone_Offset      = 0;

double ib1[];
double ib2[];
double OpenBuf[];
string IndName = "DIBS v1.0";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{  
   IndicatorShortName(IndName);
   SetIndexStyle(0, DRAW_HISTOGRAM, 0);
   SetIndexStyle(1, DRAW_HISTOGRAM, 0);
   SetIndexBuffer(0, ib1);
   SetIndexBuffer(1, ib2);
   SetIndexLabel(0, "IB");
   SetIndexLabel(1, "IB");
   SetIndexStyle(2, DRAW_LINE);
	SetIndexBuffer(2, OpenBuf);
	SetIndexLabel(2, "OpenLine");
	SetIndexEmptyValue(2, 0.0);
    Comment("www.125808047.com");
    return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 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[])
  {
   string Cmnt = IndName;
   if (Show_Remain_Bar_Time) Cmnt = Cmnt+"\n"+GetRemainingBarTime();
   Comment(Cmnt);

   static datetime prevtime = 0;
   int shift;
   int shift1;
   int shift2;
   double L, L1, H, H1;
   
   if (Show_Daily_Open_Line)
   {
      int counted_bars = IndicatorCounted();
      if (counted_bars > 0) counted_bars--;
      int last_bar = Bars - counted_bars;	
      DrawDailyOpen(0, last_bar);
   } 
   if (prevtime == Time[0]) return(0);
   
   prevtime = Time[0];
   
   for (shift = 0; shift < Bars; shift++) 
   {
      shift1 = shift;
      shift2 = shift + 1;
      
      H = High[shift1];
      H1 = High[shift2];
      L = Low[shift1];
      L1 = Low[shift2];
      
      if ((H <= H1) && (L >= L1)) 
      {
         if (Show_IB)
         {
            ib1[shift] = High[shift]; 
            ib2[shift] = Low[shift];
         }
      }
   }
   return(rates_total);
}
//+------------------------------------------------------------------+
//| Draw daily open line                                             |
//+------------------------------------------------------------------+
int DrawDailyOpen(int offset, int lastbar)
{
   int shift;
   int tzdiffsec = Timezone_Offset * 3600;
   double barsper30 = 1.0*PERIOD_M30/Period();
   bool ShowDailyOpenLevel = true; 
   lastbar = MathMin(Bars-20*barsper30-1, lastbar);

	for (shift = lastbar; shift >= offset; shift--)
	{
	  OpenBuf[shift] = 0;
     if (ShowDailyOpenLevel)
     {
       if (TimeDay(Time[shift]-tzdiffsec) != TimeDay(Time[shift+1]-tzdiffsec))
       {
         OpenBuf[shift] = Open[shift];         
         OpenBuf[shift+1] = 0;
       }
       else
       {
         OpenBuf[shift] = OpenBuf[shift+1];
       }
	  }
   }
   return(0);
}
//+------------------------------------------------------------------+
// Show bar remaining time                                           |
//+------------------------------------------------------------------+
string GetRemainingBarTime()
{
   int min, sec, hr;
   min = Time[0]+Period()*60-CurTime();
   sec = min%60;
   min = (min-min%60)/60;
   string Com = "";
   if (min > 59)
   {
      hr = min/60;
      min = min%60;
      Com = hr+" hour";
      if (hr > 1) Com = Com + "s";
      Com = Com+", ";
   }
   if (min > 0)
   {
      Com = Com+min + " minute";
      if (min > 1 || min == 0) Com = Com + "s";
      Com = Com +" and ";
    }
   Com = Com + sec + " second";
   if (sec > 1) Com = Com + "s";
   Com = Com +" remaining until bar close";
   return(Com);
}
打赏
版权所有转载请注明标题及链接:峰汇在线 » 自定义指标 DIBSv1.0.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏