//+------------------------------------------------------------------+ //| JCFBaux.mq5 | //| JCFBaux: Copyright © 2005, Weld | //| http://weld.torguem.net | //+------------------------------------------------------------------+ //---- author of the indicator #property copyright "Copyright © 2005, Weld" //---- author of the indicator #property link "http://weld.torguem.net" //---- indicator version #property version "1.00" //---- drawing the indicator in a separate window #property indicator_separate_window //---- one buffer is used for calculation and drawing the indicator #property indicator_buffers 1 //---- one plot is used #property indicator_plots 1 //+----------------------------------------------+ //| Indicator drawing parameters | //+----------------------------------------------+ //---- drawing the indicator 1 as a line #property indicator_type1 DRAW_LINE //---- Magenta color is used for the indicator line #property indicator_color1 Magenta //---- the indicator 1 line is a continuous curve #property indicator_style1 STYLE_SOLID //---- indicator 1 line width is equal to 1 #property indicator_width1 1 //---- displaying the indicator label #property indicator_label1 "JCFBaux" //+----------------------------------------------+ //| Declaration of constants | //+----------------------------------------------+ #define RESET 0 // the constant for getting the command for the indicator recalculation back to the terminal //+----------------------------------------------+ //| Declaration of enumerations | //+----------------------------------------------+ enum Applied_price_ // Type of constant { PRICE_CLOSE_ = 1, // PRICE_CLOSE PRICE_OPEN_, // PRICE_OPEN PRICE_HIGH_, // PRICE_HIGH PRICE_LOW_, // PRICE_LOW PRICE_MEDIAN_, // PRICE_MEDIAN PRICE_TYPICAL_, // PRICE_TYPICAL PRICE_WEIGHTED_, // PRICE_WEIGHTED PRICE_SIMPLE, // PRICE_SIMPLE PRICE_QUARTER_, // PRICE_QUARTER_ PRICE_TRENDFOLLOW0_, // PRICE_TRENDFOLLOW0_ PRICE_TRENDFOLLOW1_ // PRICE_TRENDFOLLOW1_ }; //+----------------------------------------------+ //| Indicator input parameters | //+----------------------------------------------+ input int Depth=15; // Indicator smoothing period input Applied_price_ IPC=PRICE_CLOSE_; // Applied price input int Shift=0; // Horizontal shift of the indicator in bars //+----------------------------------------------+ //---- declaration of dynamic arrays that //---- will be used as indicator buffers double IndBuffer[]; //---- declaration of the integer variables for the start of data calculation int min_rates_total; //---- declaration of global variables int Count[]; double Series[]; //+------------------------------------------------------------------+ //| 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; } //---- } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- initialization of variables of the start of data calculation min_rates_total=Depth*2+1; //---- memory distribution for variables' arrays ArrayResize(Count,min_rates_total); ArrayResize(Series,min_rates_total); //---- set IndBuffer[] dynamic array as an indicator buffer SetIndexBuffer(0,IndBuffer,INDICATOR_DATA); //---- shifting the indicator 1 horizontally by Shift PlotIndexSetInteger(0,PLOT_SHIFT,Shift); //---- performing shift of the beginning of counting of drawing the indicator 1 by min_rates_total 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,EMPTY_VALUE); //---- initializations of a variable for the indicator short name string shortname; StringConcatenate(shortname,"JCFBaux(",Depth,")"); //--- creation of the name to be displayed in a separate sub-window and in a tooltip IndicatorSetString(INDICATOR_SHORTNAME,shortname); //--- determination of accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //---- } //+------------------------------------------------------------------+ //| 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 first=0; // starting index for calculation of all bars else first=prev_calculated-1; // starting index for calculation of new bars //---- restore values of the variables jrc04=JRC04; jrc05=JRC05; jrc06=JRC06; //---- main indicator calculation loop for(bar=first; bar=min_rates_total) { jrc04 = 0.0; jrc05 = 0.0; jrc06 = 0.0; for(int iii=Depth-1; iii>=0; iii--) { jrc03=MathAbs(Series[Count[iii]]-Series[Count[iii+1]]); jrc04 += jrc03; jrc05 += (Depth + iii) * jrc03; jrc06 += Series[Count[iii+1]]; } } else { jrc03 = MathAbs(Series[Count[0]] - Series[Count[1]]); jrc13 = MathAbs(Series[Count[Depth]]-Series[Count[Depth+1]]); jrc04 += jrc03-jrc13; jrc05 += jrc03 * Depth - jrc04; jrc06 += Series[Count[1]] - Series[Count[Depth+1]]; } jrc08=MathAbs(Depth*Series[Count[0]]-jrc06); if(!jrc05) IndBuffer[bar]=EMPTY_VALUE; else IndBuffer[bar]=jrc08/jrc05; if(barOpen[bar])return(High[bar]); else { if(Close[bar]Open[bar])return((High[bar]+Close[bar])/2.0); else { if(Close[bar]