//+------------------------------------------------------------------+ //| Trending.mq5 | //| Copyright 2010, Grebenev V. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2010, Grebenev V." #property description "Trending Indicator" #property version "1.00" #property indicator_separate_window #property indicator_separate_window #property indicator_buffers 3 #property indicator_plots 3 #property indicator_type1 DRAW_LINE #property indicator_type2 DRAW_SECTION #property indicator_type3 DRAW_SECTION #property indicator_color1 LightSeaGreen #property indicator_color2 DarkGreen #property indicator_color3 DarkGreen #property indicator_label1 "TrendingOpen" //--- input parameters N – количество баров, по которым считается трендовость input int N=30; double ExtTRbuffer[]; // массив для индикатора double ExtTRbufferP[]; // массив для верхней оценки трендовости double ExtTRbufferM[]; // массив для нижней оценки трендовости double average[150000]; // массив для средних значений курса //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator digits // IndicatorSetInteger(INDICATOR_DIGITS,0); //--- indicator short name IndicatorSetString(INDICATOR_SHORTNAME,"Trending Open"); //---- index buffer SetIndexBuffer(0,ExtTRbuffer); SetIndexBuffer(1,ExtTRbufferP); SetIndexBuffer(2,ExtTRbufferM); //--- set index draw begin PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,1); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,1); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,1); //---- Array Initialization ArrayInitialize(ExtTRbuffer,0); ArrayInitialize(ExtTRbufferP,0); ArrayInitialize(ExtTRbufferM,0); ArrayInitialize(average,0); 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[]) { double pp=0,pm=0,mp=0,mm=0; // pp - количество цепочек «++», pm - количество цепочек «+-», mp – «-+», mm –«- -» // Заполняем массив средних значений курса average значениями OPEN for(int i=prev_calculated;i=0) // проверяем, чтобы индекс массива не вышел за границу 0 { if((average[i-j-1]-average[i-j-2])>0 && (average[i-j]-average[i-j-1])>0) pp++; if((average[i-j-1]-average[i-j-2])>0 && (average[i-j]-average[i-j-1])<0) pm++; if((average[i-j-1]-average[i-j-2])<0 && (average[i-j]-average[i-j-1])>0) mp++; if((average[i-j-1]-average[i-j-2])<0 && (average[i-j]-average[i-j-1])<0) mm++; // цепочки содержащие «0» просто выбросили } } // заполняем массивы индикатора ExtTRbuffer[i]=pp+mm-pm-mp; ExtTRbufferP[i]=sqrt(N); ExtTRbufferM[i]=-sqrt(N); } return(rates_total); } //+------------------------------------------------------------------+