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

分形指标的优化 FractalBestAll.mq4

FractalBestAll 指标是分形的一种优化。

图表:FractalBestAll 指标

源码:

//+------------------------------------------------------------------+
//|                                               FractalBestAll.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

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

    SetIndexStyle(0,DRAW_ARROW);
    SetIndexArrow(0,241);
    SetIndexStyle(1,DRAW_ARROW);
    SetIndexArrow(1,242);

    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;
    double up,dw,nul=0.0001;
    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+3]>High[i+4] && High[i+3]>High[i+5] && High[i+3]>High[i+2] && High[i+3]>High[i+1])
        { 
         up=Low[i]-3*Point;
         dUpFractalsBuffer[i]=up;
        }
       else {dUpFractalsBuffer[i]=nul;} 
       if(Low[i+3]<Low[i+4] && Low[i+3]<Low[i+5] && Low[i+3]<Low[i+2] && Low[i+3]<Low[i+1])
        { 
         dw=High[i]+3*Point;
         dDownFractalsBuffer[i]=dw;
           i--;
           continue;
         }
        else {dDownFractalsBuffer[i]=nul;}                                    
      i--;
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 分形指标的优化 FractalBestAll.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏