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

分形指标 Fractals+3.mq4

Fractals+3 指标是Fractals分形的一种优化。

图表:Fractals+3 指标

源码:

//+------------------------------------------------------------------+
//|                                                   Fractals+3.mq4 |
//|                       Copyright  2005, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright  2005, MetaQuotes Software Corp."
#property link      "http://www.125808047.com/"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue

extern int otstup=3;

double dUpFractalsBuffer[];
double dDownFractalsBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{ 
    SetIndexBuffer(0,dUpFractalsBuffer);
    SetIndexBuffer(1,dDownFractalsBuffer);   

    SetIndexStyle(0,DRAW_ARROW);
    SetIndexArrow(0,119);
    SetIndexStyle(1,DRAW_ARROW);
    SetIndexArrow(1,119);

    SetIndexEmptyValue(0,0.0);
    SetIndexEmptyValue(1,0.0);

    SetIndexLabel(0,"Fractal Up");
    SetIndexLabel(1,"Fractal Down");
   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 i,nCountedBars;
    nCountedBars=IndicatorCounted();

    if(nCountedBars<0) return(-1);

    if(nCountedBars<=2)
       i=Bars-nCountedBars-3;
    if(nCountedBars>2)
      {
       nCountedBars--;
       i=Bars-nCountedBars-1;
      }
    while(i>=2)
     {
      if(High[i]>High[i+1] && High[i]>High[i+2] && High[i]>High[i-1] && High[i]>High[i-2])
          dUpFractalsBuffer[i]= High[i]+otstup*Point;
      if(Low[i]<Low[i+1] && Low[i]<Low[i+2] && Low[i]<Low[i-1] && Low[i]<Low[i-2])
        {
          dDownFractalsBuffer[i]= Low[i]-otstup*Point;
          i--;
          continue;
        }
      if((Bars-i-1)>=3)
        {
          if(High[i]==High[i+1] && High[i]>High[i+2] && High[i]>High[i+3] && High[i]>High[i-1] && High[i]>High[i-2])
             dUpFractalsBuffer[i]= High[i]+otstup*Point;
          if(Low[i]==Low[i+1] && Low[i]<Low[i+2] && Low[i]<Low[i+3] && Low[i]<Low[i-1] && Low[i]<Low[i-2])
            {
              dDownFractalsBuffer[i]= Low[i]-otstup*Point;
              i--;
              continue;
            }                      
        }         
      if((Bars-i-1)>=4)
        {   
         if(High[i]>=High[i+1] && High[i]==High[i+2] && High[i]>High[i+3] && High[i]>High[i+4] && High[i]>High[i-1] && 
            High[i]>High[i-2])
             dUpFractalsBuffer[i]= High[i]+otstup*Point;
         if(Low[i]<=Low[i+1] && Low[i]==Low[i+2] && Low[i]<Low[i+3] && Low[i]<Low[i+4] && Low[i]<Low[i-1] && 
            Low[i]<Low[i-2])
           {
             dDownFractalsBuffer[i]= Low[i]-otstup*Point;
             i--;
             continue;
           }                  
        }  
      if((Bars-i-1)>=5)
        {   
         if(High[i]>=High[i+1] && High[i]==High[i+2] && High[i]==High[i+3] && High[i]>High[i+4] && High[i]>High[i+5] && 
            High[i]>High[i-1] && High[i]>High[i-2])
             dUpFractalsBuffer[i]= High[i]+otstup*Point;
         if(Low[i]<=Low[i+1] && Low[i]==Low[i+2] && Low[i]==Low[i+3] && Low[i]<Low[i+4] && Low[i]<Low[i+5] && 
            Low[i]<Low[i-1] && Low[i]<Low[i-2])
           {
             dDownFractalsBuffer[i]= Low[i]-otstup*Point;
             i--;
             continue;
           }                              
        } 
      if((Bars-i-1)>=6)
        {   
         if(High[i]>=High[i+1] && High[i]==High[i+2] && High[i]>=High[i+3] && High[i]==High[i+4] && High[i]>High[i+5] && 
            High[i]>High[i+6] && High[i]>High[i-1] && High[i]>High[i-2])
             dUpFractalsBuffer[i]= High[i]+otstup*Point;
         if(Low[i]<=Low[i+1] && Low[i]==Low[i+2] && Low[i]<=Low[i+3] && Low[i]==Low[i+4] && Low[i]<Low[i+5] && 
            Low[i]<Low[i+6] && Low[i]<Low[i-1] && Low[i]<Low[i-2])
           {
             dDownFractalsBuffer[i]= Low[i]-otstup*Point;
             i--;
             continue;
           }                        
        }                                    
      i--;
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 分形指标 Fractals+3.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏