//+------------------------------------------------------------------+ //| ColorTrend_CF.mq5 | //| CF = Continuation Factor | //| Converted by and Copyright: Ronald Verwer/ROVERCOM | //| 27/04/06 | //+------------------------------------------------------------------+ //---- author of the indicator #property copyright "Converted by and Copyright: Ronald Verwer/ROVERCOM" #property link "" //---- indicator version #property version "1.00" //---- drawing the indicator in a separate window #property indicator_separate_window //---- two buffers are used for calculation of drawing the indicator #property indicator_buffers 2 //---- one plot is used #property indicator_plots 1 //+-----------------------------------+ //| Parameters of filling drawing | //+-----------------------------------+ //---- drawing indicator as a filling between two lines #property indicator_type1 DRAW_FILLING //---- medium sea green and deep pink colors are used as the indicator filling colors #property indicator_color1 MediumSeaGreen, DeepPink //---- displaying the indicator label #property indicator_label1 "Trend_CF" //+----------------------------------------------+ //| Indicator input parameters | //+----------------------------------------------+ input int Period_=16; //+----------------------------------------------+ //---- declaration of dynamic arrays that further // will be used as indicator buffers double UpperBuffer[]; double LowerBuffer[]; int Count[]; //---- Declaration of the integer variables for the start of data calculation int StartBar; //---- Declare variables arrays for ring buffers double x_p[],x_n[],y_p[],y_n[]; //+------------------------------------------------------------------+ //| Recalculation of position of a newest element in the ring buffer| //+------------------------------------------------------------------+ void Recount_ArrayZeroPos ( int &CoArr[]// Return the current value of the price series by the link ) //+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+ { //---- int numb; static int count=1; count--; if(count<0) count=Period_-1; for(int iii=0; iiiPeriod_-1) numb-=Period_; CoArr[iii]=numb; } //---- } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- initialization of constants StartBar=Period_; //---- memory distribution for variables' arrays ArrayResize(x_p,Period_); ArrayResize(x_n,Period_); ArrayResize(y_p,Period_); ArrayResize(y_n,Period_); ArrayResize(Count,Period_); //---- set dynamic array as an indicator buffer SetIndexBuffer(0,UpperBuffer,INDICATOR_DATA); //---- performing the shift of beginning of indicator drawing PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,StartBar); //---- set dynamic array as an indicator buffer SetIndexBuffer(1,LowerBuffer,INDICATOR_DATA); //---- performing the shift of beginning of indicator drawing PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,StartBar); //---- initializations of a variable for the indicator short name string shortname; StringConcatenate(shortname,"Trend_CF(",Period_,")"); //---- creating a name for displaying in a separate sub-window and in a tooltip IndicatorSetString(INDICATOR_SHORTNAME,shortname); //---- determination of accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,0); //---- } //+------------------------------------------------------------------+ //| 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 int begin, // bars reliable counting beginning index const double &price[] // price array for calculation of the indicator ) { //---- checking the number of bars to be enough for the calculation if(rates_total0) { x_p[bar0]=dprice; y_p[bar0]=x_p[bar0]+y_p[bar1]; x_n[bar0]=0; y_n[bar0]=0; } else { x_n[bar0]=-dprice; y_n[bar0]=x_n[bar0]+y_n[bar1]; x_p[bar0]=0; y_p[bar0]=0; } if(bar=0; q--) { barq=Count[q]; chp+=x_p[barq]; chn+=x_n[barq]; cffp+=y_p[barq]; cffn+=y_n[barq]; } UpperBuffer[bar]=(chp-cffn)/_Point; LowerBuffer[bar]=(chn-cffp)/_Point; //---- if(bar