分形信号的另类优化 olyakish_fractals_06.mq4-MT4指标-峰汇在线
诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

分形信号的另类优化 olyakish_fractals_06.mq4

olyakish_fractals_06 指标创建分析信号及绘制支撑阻力线。

图表:olyakish_fractals_06 指标

源码:

//+------------------------------------------------------------------+
//|                                         olyakish_fractals_06.mq4 |
//+------------------------------------------------------------------+
#property copyright "by olyakish"
#property link      "http://www.125808047.com"
//----
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 SaddleBrown
#property indicator_color4 Blue

extern int			Pips		= 15;
extern int			ShiftBars	= 1000;
extern int			BarsInFractal	= 11;
extern int Percent=110;
extern bool UseOldLine=true;
extern int FractalLines=1;

double ExtLimeBuffer[];
double ExtRedBuffer[];
double ExtSaddleBrownBuffer[];
double ExtBlueBuffer[];
int i,j,z;
double a_Fractal[2];
double a_MFI[2];
double a_Volume[2];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
{ 
   int test;
   test=BarsInFractal/2;
   SetIndexShift(0,0);
   SetIndexShift(1,0);
   SetIndexShift(2,0);
   SetIndexShift(3,0);
   SetIndexBuffer(0, ExtLimeBuffer);
   SetIndexBuffer(1, ExtRedBuffer);
   SetIndexBuffer(2, ExtSaddleBrownBuffer);
   SetIndexBuffer(3, ExtBlueBuffer);
   SetIndexStyle(0, DRAW_ARROW );
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexStyle(2, DRAW_ARROW);
   SetIndexStyle(3, DRAW_ARROW);
   SetIndexArrow(0,177);
   SetIndexArrow(1,177);
   SetIndexArrow(2,177);
   SetIndexArrow(3,177);               
     ObjectCreate("Up",OBJ_TREND,0,iTime(NULL, 0, 2),High[2],iTime(NULL, 0, 1),High[1],0,0);
     ObjectSet("Up",OBJPROP_COLOR,Aqua);
     ObjectSet("Up",OBJPROP_RAY,true);
     ObjectSet("Up",OBJPROP_BACK,1);
     
     ObjectCreate("Down",OBJ_TREND,0,iTime(NULL, 0, 2),Low[2],iTime(NULL, 0, 1),Low[1],0,0);
     ObjectSet("Down",OBJPROP_COLOR,Tomato);
     ObjectSet("Down",OBJPROP_RAY,true);
     ObjectSet("Down",OBJPROP_BACK,1);
     if (UseOldLine)
      {
         ObjectCreate("Up_Prev",OBJ_TREND,0,iTime(NULL, 0, 2),High[2],iTime(NULL, 0, 1),High[1],0,0);
         ObjectSet("Up_Prev",OBJPROP_COLOR,Aqua);
         ObjectSet("Up_Prev",OBJPROP_RAY,true);
         ObjectSet("Up_Prev",OBJPROP_STYLE,STYLE_DASH);
         ObjectSet("Up_Prev",OBJPROP_BACK,1);
     
         ObjectCreate("Down_Prev",OBJ_TREND,0,iTime(NULL, 0, 2),Low[2],iTime(NULL, 0, 1),Low[1],0,0);
         ObjectSet("Down_Prev",OBJPROP_COLOR,Tomato);
         ObjectSet("Down_Prev",OBJPROP_RAY,true);         
         ObjectSet("Down_Prev",OBJPROP_STYLE,STYLE_DASH);
         ObjectSet("Down_Prev",OBJPROP_BACK,1);
      }
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
  }
  
   void OnDeinit(const int reason)
   {
      ObjectDelete("Up");
      ObjectDelete("Down");
      if (UseOldLine)
         {
            ObjectDelete("Up_Prev");
            ObjectDelete("Down_Prev");
         }
  }   
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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 n=BarsInFractal;
   while (ExtLimeBuffer[n]!=NULL || ExtRedBuffer[n]!=NULL || ExtSaddleBrownBuffer[n]!=NULL || ExtBlueBuffer[n]!=NULL)
      {
         if (n>ShiftBars) {n=ShiftBars;break;}
         n++;
      }
   for(i=n+20; i>=(BarsInFractal/2+1); i--)
     {
         ArrayInitialize(a_Fractal,0);
         ArrayInitialize(a_MFI,0);
         ArrayInitialize(a_Volume,0);         
         if (High[i]==High[iHighest(Symbol(),0,MODE_HIGH,BarsInFractal,i-BarsInFractal/2)]) 
            {               
               a_Fractal[0]=High[i];        
               for (z=i-BarsInFractal/2;z<=i-BarsInFractal/2+BarsInFractal;z++){a_Volume[0]+=Volume[z];}
               for (z=i-BarsInFractal/2;z<=i-BarsInFractal/2+BarsInFractal;z++){a_MFI[0]+=High[z]-Low[z];}
               a_MFI[0]=a_MFI[0]/a_Volume[0];               
               j=i+1;
               while (a_Fractal[1]==0 && j<Bars)
                  {
                     if (High[j]==High[iHighest(Symbol(),0,MODE_HIGH,BarsInFractal,j-BarsInFractal/2)]) {break;}
                     if (Low[j]==Low[iLowest(Symbol(),0,MODE_LOW,BarsInFractal,j-BarsInFractal/2)])
                        {
                           a_Fractal[1]=Low[j];
                           for (z=j-BarsInFractal/2;z<=j-BarsInFractal/2+BarsInFractal;z++){a_Volume[1]+=Volume[z];} 
                           for (z=j-BarsInFractal/2;z<=j-BarsInFractal/2+BarsInFractal;z++){a_MFI[1]+=High[z]-Low[z];}
                           a_MFI[1]=a_MFI[1]/a_Volume[1];                              

                           if (a_Volume[0]>a_Volume[1]*Percent/100 && a_MFI[0]<a_MFI[1]){ExtRedBuffer[i]=High[i]+Pips*Point;break;} 
                           if (a_Volume[0]>a_Volume[1]*Percent/100 && a_MFI[0]>a_MFI[1]){ExtLimeBuffer[i]=High[i]+Pips*Point;break;}
                           if (a_Volume[0]*Percent/100<a_Volume[1] && a_MFI[0]>a_MFI[1]){ExtBlueBuffer[i]=High[i]+Pips*Point;break;} 
                           if (a_Volume[0]*Percent/100<a_Volume[1] && a_MFI[0]<a_MFI[1]){ExtSaddleBrownBuffer[i]=High[i]+Pips*Point;break;}
                        }                          
                        j++;                                         
                  }
            }
         ArrayInitialize(a_Fractal,0);
         ArrayInitialize(a_MFI,0);
         ArrayInitialize(a_Volume,0);
         if (Low[i]==Low[iLowest(Symbol(),0,MODE_LOW,BarsInFractal,i-BarsInFractal/2)])
            {
               a_Fractal[0]=Low[i];             
               for (z=i-BarsInFractal/2;z<=i-BarsInFractal/2+BarsInFractal;z++){a_Volume[0]+=Volume[z];}
               for (z=i-BarsInFractal/2;z<=i-BarsInFractal/2+BarsInFractal;z++){a_MFI[0]+=High[z]-Low[z];}
               a_MFI[0]=a_MFI[0]/a_Volume[0];   
               j=i+1;
               while (a_Fractal[1]==0 && j<Bars)
                  {
                     if (Low[j]==Low[iLowest(Symbol(),0,MODE_LOW,BarsInFractal,j-BarsInFractal/2)]) {break;}
                     if (High[j]==High[iHighest(Symbol(),0,MODE_HIGH,BarsInFractal,j-BarsInFractal/2)])
                        {
                           a_Fractal[1]=High[j];
                           for (z=j-BarsInFractal/2;z<=j-BarsInFractal/2+BarsInFractal;z++){a_Volume[1]+=Volume[z];} 
                           for (z=j-BarsInFractal/2;z<=j-BarsInFractal/2+BarsInFractal;z++){a_MFI[1]+=High[z]-Low[z];}
                           a_MFI[1]=a_MFI[1]/a_Volume[1];                              
                           if (a_Volume[0]>a_Volume[1]*Percent/100 && a_MFI[0]<a_MFI[1]){ExtRedBuffer[i]=Low[i]-Pips*Point;break;}           // 桁邋?镳桉邃帼?麴嚓蜞?(MFI - 钺?+)
                           if (a_Volume[0]>a_Volume[1]*Percent/100 && a_MFI[0]>a_MFI[1]){ExtLimeBuffer[i]=Low[i]-Pips*Point;break;}          // 桁邋?珏脲睇?麴嚓蜞?(MFI + 钺?+)
                           if (a_Volume[0]*Percent/100<a_Volume[1] && a_MFI[0]>a_MFI[1]){ExtBlueBuffer[i]=Low[i]-Pips*Point;break;}          // 桁邋?羿朦恹?麴嚓蜞?(MFI + 钺?-)
                           if (a_Volume[0]*Percent/100<a_Volume[1] && a_MFI[0]<a_MFI[1]){ExtSaddleBrownBuffer[i]=Low[i]-Pips*Point;break;}   // 桁邋?筲溧栝 麴嚓蜞?(MFI - 钺?-)
                        }
                        j++;                                         
                  }
            }
      }
    double _Price[3,2];
    int  _Time[3,2];
    ArrayInitialize(_Price,-1);
    ArrayInitialize(_Time,-1);
    int up=0,down=0;
    for(i=3; i<=ShiftBars; i++)
      {
         if (FractalLines==0)
            {
               if (ExtLimeBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_UPPER,i)!=NULL && up<=2 && iFractals(NULL,0,MODE_UPPER,i)<=ExtLimeBuffer[i]) 
                  {
                     _Price[up,0]=ExtLimeBuffer[i];_Time[up,0]=iTime(NULL, 0, i);up++;
                  }
               if (ExtLimeBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_LOWER,i)!=NULL && down<=2 && iFractals(NULL,0,MODE_LOWER,i)>=ExtLimeBuffer[i])
                  {
                     _Price[down,1]=ExtLimeBuffer[i];_Time[down,1]=iTime(NULL, 0, i);down++;         
                  } 
            }
         if (FractalLines==1)
            {
               if (ExtRedBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_UPPER,i)!=NULL && up<=2 && iFractals(NULL,0,MODE_UPPER,i)<=ExtRedBuffer[i]) 
                  {
                     _Price[up,0]=ExtRedBuffer[i];_Time[up,0]=iTime(NULL, 0, i);up++;
                  }
               if (ExtRedBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_LOWER,i)!=NULL && down<=2 && iFractals(NULL,0,MODE_LOWER,i)>=ExtRedBuffer[i])
                  {
                     _Price[down,1]=ExtRedBuffer[i];_Time[down,1]=iTime(NULL, 0, i);down++;         
                  } 
            }
         if (FractalLines==2)
            {
               if (ExtSaddleBrownBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_UPPER,i)!=NULL && up<=2 && iFractals(NULL,0,MODE_UPPER,i)<=ExtSaddleBrownBuffer[i]) 
                  {
                     _Price[up,0]=ExtSaddleBrownBuffer[i];_Time[up,0]=iTime(NULL, 0, i);up++;
                  }
               if (ExtSaddleBrownBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_LOWER,i)!=NULL && down<=2 && iFractals(NULL,0,MODE_LOWER,i)>=ExtSaddleBrownBuffer[i])
                  {
                     _Price[down,1]=ExtSaddleBrownBuffer[i];_Time[down,1]=iTime(NULL, 0, i);down++;         
                  } 
            }
         if (FractalLines==3)
            {
               if (ExtBlueBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_UPPER,i)!=NULL && up<=2 && iFractals(NULL,0,MODE_UPPER,i)<=ExtBlueBuffer[i]) 
                  {
                     _Price[up,0]=ExtBlueBuffer[i];_Time[up,0]=iTime(NULL, 0, i);up++;
                  }
               if (ExtBlueBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_LOWER,i)!=NULL && down<=2 && iFractals(NULL,0,MODE_LOWER,i)>=ExtBlueBuffer[i])
                  {
                     _Price[down,1]=ExtBlueBuffer[i];_Time[down,1]=iTime(NULL, 0, i);down++;         
                  } 
            }                                   
      }   
   ObjectMove("Up",1,_Time[0,0],_Price[0,0]);
   ObjectMove("Up",0,_Time[1,0],_Price[1,0]);
    
   ObjectMove("Down",1,_Time[0,1],_Price[0,1]);
   ObjectMove("Down",0,_Time[1,1],_Price[1,1]);
   if (UseOldLine)
      {
         ObjectMove("Up_Prev",1,_Time[1,0],_Price[1,0]);
         ObjectMove("Up_Prev",0,_Time[2,0],_Price[2,0]);
    
         ObjectMove("Down_Prev",1,_Time[1,1],_Price[1,1]);
         ObjectMove("Down_Prev",0,_Time[2,1],_Price[2,1]);         
      }
   return(0);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 分形信号的另类优化 olyakish_fractals_06.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏