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

分形通道 FractalChannel_v1.mq4

FractalChannel_v1 指标以特定算法创建价格通道。

图表:FractalChannel_v1 指标

源码:

//+------------------------------------------------------------------+
//|                                            FractalChannel_v1.mq4 |
//|                             Copyright 2005, TrendLaboratory Ltd. |
//+------------------------------------------------------------------+
#property copyright "Copyright 2005, TrendLaboratory Ltd."
#property link      "http://www.125808047.com"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 DodgerBlue
#property indicator_color3 DodgerBlue

extern int ChannelType=1;
extern double Margins=0;
extern double Advance=0;
extern int OpenClose=0;

double UpBuffer[];
double DnBuffer[];
double MdBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{ 
   string short_name;
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE,2);
   SetIndexBuffer(0,UpBuffer);
   SetIndexBuffer(1,DnBuffer);
   SetIndexBuffer(2,MdBuffer);

   short_name="Fractal Channel("+ChannelType+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"Up Channel");
   SetIndexLabel(1,"Down Channel");
   SetIndexLabel(2,"Middle Channel");

   SetIndexDrawBegin(0,2*ChannelType);
   SetIndexDrawBegin(1,2*ChannelType);
   SetIndexDrawBegin(2,2*ChannelType);
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| FractalChannel_v1                                                         |
//+------------------------------------------------------------------+
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  	   shift;
double   v1,v2,smax,smin,
			High0,High1,High2,High3,High4,High5,High6,
			Low0,Low1,Low2,Low3,Low4,Low5,Low6;			

for (shift=Bars-1-2*ChannelType;shift>=0;shift--)	
	{
	v1=-1;
	v2=-1;
	
	High0=High[shift];
	High1=High[shift+1];
	High2=High[shift+2];
	High3=High[shift+3];
	High4=High[shift+4];
	High5=High[shift+5];
	High6=High[shift+6];
	
	Low0=Low[shift];
	Low1=Low[shift+1];
	Low2=Low[shift+2];
	Low3=Low[shift+3];
	Low4=Low[shift+4];
	Low5=Low[shift+5];
	Low6=Low[shift+6];
	
	if (OpenClose>0) 
	{
	High0=MathMax(Close[shift],Open[shift]);
	High1=MathMax(Close[shift+1],Open[shift+1]);
	High2=MathMax(Close[shift+2],Open[shift+2]);
	High3=MathMax(Close[shift+3],Open[shift+3]);
	High4=MathMax(Close[shift+4],Open[shift+4]);
	High5=MathMax(Close[shift+5],Open[shift+5]);
	High6=MathMax(Close[shift+6],Open[shift+6]);
	
	Low0=MathMin(Close[shift],Open[shift]);
	Low1=MathMin(Close[shift+1],Open[shift+1]);
	Low2=MathMin(Close[shift+2],Open[shift+2]);
	Low3=MathMin(Close[shift+3],Open[shift+3]);
	Low4=MathMin(Close[shift+4],Open[shift+4]);
	Low5=MathMin(Close[shift+5],Open[shift+5]);
	Low6=MathMin(Close[shift+6],Open[shift+6]);
	}

	if (ChannelType==1)  
	{		
	if (High2<=High1 && High0<High1) v1=High1;
	if (Low2>=Low1 && Low0>Low1) v2=Low1;
	}	
	
	if (ChannelType==2) 
	{	
	if (High4<=High2 && High3<=High2 && High0<High2 && High1<High2) 
	v1=High2;
	if (Low4>=Low2 && Low3>=Low2 && Low0>Low2 && Low1>Low2)  
	v2=Low2;
	}
	
	if (ChannelType==3)
	{	
	if (High6<=High3 && High5<=High3 && High4<=High3 && 
	High0<High3 && High1<High3 && High2<High3) 
	v1=High3;
	if (Low6>=Low3 && Low5>=Low3 && Low4>=Low3 && 
	Low0>Low3 && Low1>Low3 && Low2>Low3) 
	v2=Low3;
	}
			
	if ( v1>0 ) smax=v1; 
	if (High0>smax) smax=High0;
	
	if ( v2>0 ) smin=v2; 
	if (Low0<smin) smin=Low0;
	
	if (shift==Bars-1-2*ChannelType) {smin=Low0;smax=High0;}
	
	UpBuffer[shift]=smax-(smax-smin)*Margins;
	DnBuffer[shift]=smin+(smax-smin)*Margins;
	MdBuffer[shift]=(UpBuffer[shift]+DnBuffer[shift])/2;
	}
return(rates_total);
}
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 分形通道 FractalChannel_v1.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏