|
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1
#property indicator_width6 1
#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 阻力Buffer1[];
double 支撑Buffer2[];
double 上分形Buffer3[];
double 下分形Buffer4[];
double 上突破Buffer5[];
double 下突破Buffer6[];
int init()
{
SetIndexStyle(0, DRAW_LINE);
SetIndexArrow(0, 158);
SetIndexBuffer(0, 阻力Buffer1);
SetIndexEmptyValue(0, 0.0);
SetIndexLabel(0, "阻力");
SetIndexStyle(1, DRAW_LINE);
SetIndexArrow(1, 158);
SetIndexBuffer(1, 支撑Buffer2);
SetIndexEmptyValue(1, 0.0);
SetIndexLabel(1, "支撑");
SetIndexStyle(2, DRAW_ARROW);
SetIndexArrow(2, 119);
SetIndexBuffer(2, 上分形Buffer3);
SetIndexEmptyValue(2, 0.0);
SetIndexLabel(2, "上分形");
SetIndexStyle(3, DRAW_ARROW);
SetIndexArrow(3, 119);
SetIndexBuffer(3, 下分形Buffer4);
SetIndexEmptyValue(3, 0.0);
SetIndexLabel(3, "下分形");
SetIndexStyle(4, DRAW_ARROW);
SetIndexArrow(4, 119);
SetIndexBuffer(4, 上突破Buffer5);
SetIndexEmptyValue(4, 0.0);
SetIndexLabel(4, "上破");
SetIndexStyle(5, DRAW_ARROW);
SetIndexArrow(5, 119);
SetIndexBuffer(5, 下突破Buffer6);
SetIndexEmptyValue(5, 0.0);
SetIndexLabel(5, "下破");
return(0);
}
int deinit(){return(0);}
int start()
{
int counted_bars = IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars > 0) counted_bars--;
int limit = Bars - counted_bars;
if(counted_bars==0) limit-=1+MathMax(LeftBars,RightBars);
for(int i = limit-1; i >= 0; i--)
{
阻力Buffer1 = isFractalUp(i, LeftBars, RightBars,limit);
if(阻力Buffer1 == 0)
阻力Buffer1 = 阻力Buffer1[i+1];
else
上分形Buffer3 = 阻力Buffer1;
支撑Buffer2 = isFractalDown(i, LeftBars, RightBars,limit);
if(支撑Buffer2 == 0)
支撑Buffer2 = 支撑Buffer2[i+1];
else
下分形Buffer4 = 支撑Buffer2;
if(Close < 支撑Buffer2 && Close[i+1] >= 支撑Buffer2[i+1])
下突破Buffer6 = Close;
if(Close > 阻力Buffer1 && Close[i+1] <= 阻力Buffer1[i+1])
下突破Buffer6 = Close; }
//阻力Buffer1[-1] = 阻力Buffer1[0];
//支撑Buffer2[-1] = 支撑Buffer2[0];
return(0);
}
double isFractalUp(int index, int lBars, int rBars, int maxind)
{
int left = lBars, right = rBars;
double max = High[index];
for(int i = index - right; i <= (index + left); i++)
{
if (i<0 || i>maxind) return(0);
if(!(High > 0.0))return(0);
if(max < High && i != index)
{
if(max < High) return(0);
if(MathAbs(i - index) > 1) return(0);
}
}
return(max);
}
double isFractalDown(int index, int lBars, int rBars, int maxind)
{
int left = lBars, right = rBars;
double min = Low[index];
for(int i = index - right; i <= (index + left); i++)
{
if (i<0 || i>maxind) return(0);
if(!(Low > 0.0))return(0);
//if(min >= Low && i != index)
if(min > Low && i != index)
{
if(min > Low)
return(0);
if(MathAbs(i - index) > 1)
return(0);
}
}
return(min);
}
|
|