//+------------------------------------------------------------------+ //| J_TPO_Velocity.mq5 | //| Copyright © 2011, Nikolay Kositsin | //| Khabarovsk, farria@mail.redcom.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2011, Nikolay Kositsin" #property link "farria@mail.redcom.ru" //---- indicator version #property version "1.00" //---- drawing the indicator in a separate window #property indicator_separate_window //---- number of indicator buffers 2 #property indicator_buffers 2 //---- only one plot is used #property indicator_plots 1 //+-----------------------------------+ //| Indicator drawing parameters | //+-----------------------------------+ //---- drawing the indicator as a five-color histogram #property indicator_type1 DRAW_COLOR_HISTOGRAM //---- five colors are used in the histogram #property indicator_color1 Gray,Lime,Blue,Red,Magenta //---- indicator line is a solid one #property indicator_style1 STYLE_SOLID //---- indicator line width is equal to 2 #property indicator_width1 2 //+----------------------------------------------+ //| Indicator input parameters | //+----------------------------------------------+ input int Len_=14; // Smoothing period //+----------------------------------------------+ //---- declaration of dynamic arrays that further //---- will be used as indicator buffers double ExtBuffer[],ColorExtBuffer[]; int Len; double normalization,Lenp1half,arr1[],arr2[],arr3[]; //---- declaration of the integer variables for the start of data calculation int min_rates_total; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //---- initialization of variables Len=Len_; if(Len<3) Len=3; normalization=12.0/(Len*(Len-1)*(Len+1)); Lenp1half=(Len+1)*0.5; //---- initialization of variables of the start of data calculation min_rates_total=2*Len+1; //---- memory distribution for variables' arrays int size=Len+2; if(ArrayResize(arr1,size)1) { accum=accum/(j-m); for(int n=m; n<=j-1; n++) arr3[n]=accum; } flag=false; } else { accum+=arr3[j]; j++; } } m=j; } for(accum=0,m=1; m<=period; m++) accum+=(arr3[m]-Lenp1half) *(arr2[m]-Lenp1half); value=normalization*accum; //---- return(value); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, // number of bars in history at the current tick const int prev_calculated,// number of bars calculated at previous call const datetime &time[], const double &open[], const double& high[], // price array of maximums of price for the indicator calculation const double& low[], // price array of minimums of price for the indicator calculation const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //---- checking the number of bars to be enough for the calculation if(rates_totalrates_total || prev_calculated<=0) // checking for the first start of the indicator calculation { limit1=rates_total-min_rates_total-1; // starting index for calculation of all bars limit2=limit1-1; } else { limit1=rates_total-prev_calculated; // starting index for calculation of new bars limit2=limit1; // starting index for calculation of new bars } //---- main indicator calculation loop for(int bar=limit1; bar>=0 && !IsStopped(); bar--) ExtBuffer[bar]=J_TPO_value(Len,close,bar)*Range(Len,high,low,bar)/Len; //---- main cycle of the indicator coloring for(int bar=limit2; bar>=0 && !IsStopped(); bar--) { ColorExtBuffer[bar]=0; if(ExtBuffer[bar]>0) { if(ExtBuffer[bar]>ExtBuffer[bar+1]) ColorExtBuffer[bar]=1; if(ExtBuffer[bar]ExtBuffer[bar+1]) ColorExtBuffer[bar]=4; } } //---- return(rates_total); } //+------------------------------------------------------------------+