//+------------------------------------------------------------------+ //| convex_v1.00.mq5 | //| convex_v1.00 Copyright 2016, fxborg | //| http://fxborg-labo.hateblo.jp/ | //+------------------------------------------------------------------+ #property copyright "Copyright 2016, fxborg" #property link "http://fxborg-labo.hateblo.jp/" #property version "1.00" #property indicator_chart_window #property indicator_buffers 3 #property indicator_plots 1 #property indicator_type1 DRAW_ARROW #property indicator_color1 clrDodgerBlue #property indicator_width1 2 #property indicator_type2 DRAW_ARROW #property indicator_color2 clrSilver #property indicator_width2 1 #property indicator_type3 DRAW_ARROW #property indicator_color3 clrSilver #property indicator_width3 1 input int InpPeriod=20; // Period double R1[]; double S1[]; double OSC[]; double POS[]; double NEG[]; double CNT[]; int WinNo=ChartWindowFind(); int min_rates_total=InpPeriod; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { ObjectsDeleteAll(0,WinNo); //--- //--- int i=0; SetIndexBuffer(i++,CNT,INDICATOR_DATA); SetIndexBuffer(i++,R1,INDICATOR_CALCULATIONS); SetIndexBuffer(i++,S1,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=2 && (cross(temp[k-2][0],temp[k-2][1], temp[k-1][0],temp[k-1][1], points[i][0],points[i][1]))>=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(upper,temp,0,2); ArrayResize(temp,0,len); k=0; for(int i=len-1;i>=0;i--) { while(k>=2 && (cross(temp[k-2][0],temp[k-2][1], temp[k-1][0],temp[k-1][1], points[i][0],points[i][1]))>=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(lower,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 calc_convex(double &R[],double &S[],const double &High[],const double &Low[],const int i,const datetime &time[]) { double vertex[][2]; ArrayResize(vertex,0,InpPeriod*3); int i_vtx=0; double upper[][2]; double lower[][2]; int up_sz=0; int lo_sz=0; for(int j=0;jdst) dmin=dst; } return(dmin<=limit); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double distance(const double ax,const double ay,const double bx,const double by) { double dx = ax-bx; double dy = ay-by; return MathSqrt((dx * dx) + (dy * dy)); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void regression(double &a,double &b,double &dev,const double &data[],const int from,const int to) { int temp_sz=to-from; double temp[][2]; ArrayResize(temp,temp_sz+1); int n=0; for(int k=from;k<=to;k++) { temp[n][0]=k; temp[n][1]=data[k]; n++; } _regression(a,b,temp,n); dev=0; for(int i=0; i