//+------------------------------------------------------------------+ //| PFE2.mq5 | //| Copyright © 2007, | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, " #property link "" //---- indicator version number #property version "1.01" //---- drawing 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 six-color histogram #property indicator_type1 DRAW_COLOR_HISTOGRAM //---- colors of the six-color histogram are as follows #property indicator_color1 clrRed,clrMagenta,clrMediumVioletRed,clrTeal,clrDeepSkyBlue,clrLime //---- indicator line is a solid one #property indicator_style1 STYLE_SOLID //---- Indicator line width is equal to 2 #property indicator_width1 2 //---- displaying the indicator label #property indicator_label1 "PFE2" //+----------------------------------------------+ //| Parameters of displaying horizontal levels | //+----------------------------------------------+ #property indicator_level1 +70.0 #property indicator_level2 0.0 #property indicator_level3 -70.0 #property indicator_levelcolor clrBlueViolet #property indicator_levelstyle STYLE_DASHDOTDOT //+----------------------------------------------+ //| INDICATOR INPUT PARAMETERS | //+----------------------------------------------+ input uint Length=7; //smoothing depth //+----------------------------------------------+ //---- Declaration of integer variables of data starting point int min_rates_total,size; //---- declaration of dynamic arrays that will further be // used as indicator buffers double IndBuffer[],ColorIndBuffer[]; //---- declaration of global variables int Count[]; double SMA[]; //+------------------------------------------------------------------+ //| Recalculation of position of the newest element in the array | //+------------------------------------------------------------------+ void Recount_ArrayZeroPos(int &CoArr[],// Return the current value of the price series by the link int Size) { //---- int numb,Max1,Max2; static int count=1; Max2=Size; Max1=Max2-1; count--; if(count<0) count=Max1; for(int iii=0; iiiMax1) numb-=Max2; CoArr[iii]=numb; } //---- } //+------------------------------------------------------------------+ //| Getting the averaging of a price series values | //+------------------------------------------------------------------+ double Get_SMA(const double &Array[],int index) { //---- double sum=0; for(int kkk=int(index-Length-1); kkk<=index; kkk++) sum+=Array[kkk]; //---- return(sum/Length); } //+------------------------------------------------------------------+ //| PFE2 indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- Initialization of variables of the start of data calculation size=11; min_rates_total=int(Length+size); //---- memory allocation for arrays of variables ArrayResize(Count,size); ArrayResize(SMA,size); ArrayInitialize(Count,0); ArrayInitialize(SMA,0.0); //---- set IndBuffer dynamic array as an indicator buffer SetIndexBuffer(0,IndBuffer,INDICATOR_DATA); //---- performing the shift of beginning of indicator drawing PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); //---- setting the indicator values that won't be visible on a chart PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); //---- setting dynamic array as a color index buffer SetIndexBuffer(1,ColorIndBuffer,INDICATOR_COLOR_INDEX); //--- creation of the name to be displayed in a separate sub-window and in a pop up help IndicatorSetString(INDICATOR_SHORTNAME,"PFE2"); //--- determining the accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,0); //---- end of initialization } //+------------------------------------------------------------------+ //| PFE2 iteration function | //+------------------------------------------------------------------+ int OnCalculate( const int rates_total, // amount of history in bars at the current tick const int prev_calculated, // amount of history in bars at the previous tick const int begin, // number of beginning of reliable counting of bars const double &price[] // price array for calculation of the indicatorą ) { //---- Checking if the number of bars is sufficient for the calculation if(rates_totalrates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator { min_rates=min_rates_total+begin; first=min_rates; // starting number for calculation of all bars //---- increase the position of the beginning of data by 'begin' bars as a result of calculation using data of another indicator if(begin>0) PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total+begin); } else first=prev_calculated-1; // starting number for calculation of new bars //---- Main calculation loop of the indicator for(bar=first; bar0) fraceff=MathRound(+res); else fraceff=MathRound(-res); if(bar>min_rates) IndBuffer[bar]=MathRound((fraceff*0.333)+(IndBuffer[bar-1]*(1-0.333))); else IndBuffer[bar]=fraceff; if(barrates_total || prev_calculated<=0) first++; //---- Main indicator coloring loop for(bar=first; bar0) { if(IndBuffer[bar]>IndBuffer[bar-1]) ColorIndBuffer[bar]=5; if(IndBuffer[bar]==IndBuffer[bar-1]) ColorIndBuffer[bar]=4; if(IndBuffer[bar]IndBuffer[bar-1]) ColorIndBuffer[bar]=2; } } //---- return(rates_total); } //+------------------------------------------------------------------+