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

Fractals分形通道 FractalLevels.mq4

FractalLevels 指标创建分形通道。

图表:FractalLevels 指标

源码:

//+------------------------------------------------------------------+
//|                                                FractalLevels.mq4 |
//|                                          Copyright 2008, lotos4u |
//+------------------------------------------------------------------+
#property copyright "Copyright 2008, lotos4u"
#property link      "http://www.125808047.com"

#property indicator_chart_window
#property indicator_buffers 6

#property indicator_width1 4
#property indicator_width2 4
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 2
#property indicator_width6 2

#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Gold
#property indicator_color4 Gold
#property indicator_color5 White
#property indicator_color6 White

extern int LeftBars  = 3;
extern int RightBars = 3;

double LineUpBuffer1[];
double LineDownBuffer2[];
double ArrowUpBuffer3[];
double ArrowDownBuffer4[];
double ArrowBreakUpBuffer5[];
double ArrowBreakDownBuffer6[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{ 
   SetIndexStyle(0, DRAW_LINE);
   SetIndexArrow(0, 158);
   SetIndexBuffer(0, LineUpBuffer1);
   SetIndexEmptyValue(0, 0.0);
   
   SetIndexStyle(1, DRAW_LINE);
   SetIndexArrow(1, 158);
   SetIndexBuffer(1, LineDownBuffer2);
   SetIndexEmptyValue(1, 0.0);

   SetIndexStyle(2, DRAW_ARROW);
   SetIndexArrow(2, 119);
   SetIndexBuffer(2, ArrowUpBuffer3);
   SetIndexEmptyValue(2, 0.0);
   
   SetIndexStyle(3, DRAW_ARROW);
   SetIndexArrow(3, 119);
   SetIndexBuffer(3, ArrowDownBuffer4);
   SetIndexEmptyValue(3, 0.0);

   SetIndexStyle(4, DRAW_ARROW);
   SetIndexArrow(4, 119);
   SetIndexBuffer(4, ArrowBreakUpBuffer5);
   SetIndexEmptyValue(4, 0.0);
   
   SetIndexStyle(5, DRAW_ARROW);
   SetIndexArrow(5, 119);
   SetIndexBuffer(5, ArrowBreakDownBuffer6);
   SetIndexEmptyValue(5, 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[])
  {
   int counted_bars = IndicatorCounted(), limit;
   if(counted_bars > 0) 
       counted_bars--;
   limit = Bars - counted_bars;

   for(int i = limit-1; i >= 0; i--)
   {
      LineUpBuffer1[i] = isFractalUp(i, LeftBars, RightBars);
      if(LineUpBuffer1[i] == 0)
         LineUpBuffer1[i] = LineUpBuffer1[i+1];
      else
         ArrowUpBuffer3[i] = LineUpBuffer1[i];
      
      LineDownBuffer2[i] = isFractalDown(i, LeftBars, RightBars);
      if(LineDownBuffer2[i] == 0)
         LineDownBuffer2[i] = LineDownBuffer2[i+1];
      else
         ArrowDownBuffer4[i] = LineDownBuffer2[i];
         
      if(Close[i] < LineDownBuffer2[i] && Close[i+1] >= LineDownBuffer2[i+1])
         ArrowBreakDownBuffer6[i] = Close[i];
   }
   LineUpBuffer1[-1] = LineUpBuffer1[0];
   LineDownBuffer2[-1] = LineDownBuffer2[0];
   return(rates_total);
}

double isFractalUp(int index, int lBars, int rBars)
{
   int left = lBars, right = rBars;
   double max = High[index];
   for(int i = index - right; i <= (index + left); i++)
   {
      if(!(High[i] > 0.0))return(0);
      if(max <= High[i] && i != index)
      {
         if(max < High[i])
            return(0);
         if(MathAbs(i - index) > 1)
            return(0);
      }
   }
   return(max);
}

double isFractalDown(int index, int lBars, int rBars)
{
   int left = lBars, right = rBars;
   double min = Low[index];
   for(int i = index - right; i <= (index + left); i++)
   {
      if(!(Low[i] > 0.0))return(0);
      if(min >= Low[i] && i != index)
      {
         if(min > Low[i])
            return(0);

         if(MathAbs(i - index) > 1)
            return(0);
      }
   }
   return(min);
}
打赏
版权所有转载请注明标题及链接:峰汇在线 » Fractals分形通道 FractalLevels.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏