//+------------------------------------------------------------------+ //| convex_v1.02.mq5 | //| polygon_trend_v1.02 Copyright 2016, fxborg | //| http://fxborg-labo.hateblo.jp/ | //+------------------------------------------------------------------+ #property copyright "Copyright 2016, fxborg" #property link "http://fxborg-labo.hateblo.jp/" #property version "1.02" #property indicator_chart_window #property indicator_buffers 10 #property indicator_plots 5 #property indicator_type1 DRAW_LINE #property indicator_color1 clrAqua #property indicator_width1 1 #property indicator_type2 DRAW_LINE #property indicator_color2 clrAqua #property indicator_width2 1 #property indicator_type3 DRAW_LINE #property indicator_color3 clrAqua #property indicator_width3 1 #property indicator_type4 DRAW_LINE #property indicator_color4 clrAqua #property indicator_width4 1 #property indicator_type5 DRAW_LINE #property indicator_color5 clrAqua #property indicator_width5 1 #property indicator_type6 DRAW_SECTION #property indicator_color6 clrRed #property indicator_width6 1 input int InpConvexPeriod=40; // Convex Hull Period input int InpRegrPeriod=8; // Regression Period input int Inp1stPeriod=5; // 1st Period input color Inp1stColor=clrGold; // 1st color input int Inp2ndPeriod=40; // 2nd Period input color Inp2ndColor=clrRed; // 2nd color input int Inp3rdPeriod=120; // 2nd Period input color Inp3rdColor=clrBlueViolet; // 2nd color input int InpDisplayMode=1; // Display Mode( 1:show , 0:hide); double R1[]; double S1[]; double OSC[]; double POS[]; double NEG[]; double CX[]; double CY[]; double LA[]; double LB[]; double LN1[]; double LN2[]; double LN3[]; double LN4[]; double LN5[]; double CNT[]; int WinNo=ChartWindowFind(); int min_rates_total=InpConvexPeriod+MathMax(Inp2ndPeriod,Inp1stPeriod); //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { ObjectsDeleteAll(0,WinNo); //--- if(InpDisplayMode==0) { PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_NONE); PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_NONE); PlotIndexSetInteger(2,PLOT_DRAW_TYPE,DRAW_NONE); PlotIndexSetInteger(3,PLOT_DRAW_TYPE,DRAW_NONE); PlotIndexSetInteger(4,PLOT_DRAW_TYPE,DRAW_NONE); } else { PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE); PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_LINE); PlotIndexSetInteger(2,PLOT_DRAW_TYPE,DRAW_LINE); PlotIndexSetInteger(3,PLOT_DRAW_TYPE,DRAW_LINE); PlotIndexSetInteger(4,PLOT_DRAW_TYPE,DRAW_LINE); } //--- SetIndexBuffer(0,LN1,INDICATOR_DATA); SetIndexBuffer(1,LN2,INDICATOR_DATA); SetIndexBuffer(2,LN3,INDICATOR_DATA); SetIndexBuffer(3,LN4,INDICATOR_DATA); SetIndexBuffer(4,LN5,INDICATOR_DATA); SetIndexBuffer(5,CNT,INDICATOR_DATA); SetIndexBuffer(6,CX,INDICATOR_CALCULATIONS); SetIndexBuffer(7,CY,INDICATOR_CALCULATIONS); SetIndexBuffer(8,LA,INDICATOR_CALCULATIONS); SetIndexBuffer(9,LB,INDICATOR_CALCULATIONS); /// --- //--- digits IndicatorSetInteger(INDICATOR_DIGITS,2); return(0); } //+------------------------------------------------------------------+ //| 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,first; if(rates_total<=min_rates_total) return(0); //--- int begin_pos=min_rates_total; first=begin_pos; if(first+1=0;j--) { ArrayResize(vertices,n+1,sz); vertices[n][0]=lower[j][0]; vertices[n][1]=lower[j][1]; n++; } int v_cnt=n; y=0; x=0; double signedArea=0.0; double x0 = 0.0; // Current vertex X double y0 = 0.0; // Current vertex Y double x1 = 0.0; // Next vertex X double y1 = 0.0; // Next vertex Y double a = 0.0; // Partial signed area // For all vertices int i=0; for(i=0; i=2 && (cross(temp[k-2][0],temp[k-2][1], temp[k-1][0],temp[k-1][1], points[i][0],points[i][1])*dir)>=0) { k--; } if(points[i][0]!=EMPTY_VALUE) { ArrayResize(temp,k+1,len); temp[k][0]= points[i][0]; temp[k][1]= points[i][1]; k++; } } ArrayCopy(convex,temp,0,2); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double cross(const double ox,double oy, const double ax,double ay, const double bx,double by) { return ((ax - ox) * (by - oy) - (ay - oy) * (bx - ox)); } //+------------------------------------------------------------------+ void drawTrend(const int no,const color clr,const int x0,const double y0,const int x1,const double y1,const datetime &time[]) { ObjectCreate(0,"Trend"+StringFormat("%d",no),OBJ_TREND,WinNo,time[x0],y0,time[x1],y1); ObjectSetInteger(0,"Trend"+StringFormat("%d",no),OBJPROP_COLOR,clr); ObjectSetInteger(0,"Trend"+StringFormat("%d",no),OBJPROP_WIDTH,2); ObjectSetInteger(0,"Trend"+StringFormat("%d",no),OBJPROP_RAY_RIGHT,true); } //+------------------------------------------------------------------+