//+------------------------------------------------------------------+ //| EMAVFS_channel.mq5 | //| Copyright © 2018, ????????? ??????? | //| http://stan.okis.ru/file/stan/EMAVFS.pdf | //+------------------------------------------------------------------+ #property copyright "Copyright © 2018, Stanislav Bulasev" #property link "http://stan.okis.ru/file/stan/EMAVFS.pdf" #property description "Channel using exponential moving average with variable smoothing factor" //---- indicator version number #property version "1.10" //---- drawing the indicator in the main window #property indicator_chart_window //---- number of indicator buffers #property indicator_buffers 3 //---- used only one graphical construction #property indicator_plots 3 //+-----------------------------------+ //| Indicator drawing parameters | //+-----------------------------------+ //---- drawing the indicator as a line #property indicator_type1 DRAW_LINE //---- clr DodgerBlue color is used as the indicator line color. #property indicator_color1 clrDodgerBlue //---- indicator line - continuous curve #property indicator_style1 STYLE_SOLID //---- the thickness of the indicator line is equal to 2 #property indicator_width1 2 //---- display of the indicator label #property indicator_label1 "EMAVFS Max" //+-----------------------------------+ //| Indicator drawing parameters 2 | //+-----------------------------------+ //---- drawing the indicator as a line #property indicator_type2 DRAW_LINE //---- clrSlateGray color is used as indicator line color #property indicator_color2 clrSlateGray //---- indicator line - continuous curve #property indicator_style2 STYLE_DASHDOTDOT //---- the thickness of the indicator line is equal to 1 #property indicator_width2 1 //---- display of the indicator label #property indicator_label2 "EMAVFS" //+-----------------------------------+ //| Indicator drawing parameters | //+-----------------------------------+ //---- drawing the indicator as a line #property indicator_type3 DRAW_LINE //---- color DeepPink color is used as the indicator line color #property indicator_color3 clrDeepPink //---- indicator line - continuous curve #property indicator_style3 STYLE_SOLID //---- the thickness of the indicator line is equal to 2 #property indicator_width3 2 //---- display of the indicator label #property indicator_label3 "EMAVFS Min" //+---------------------------------------------+ //| INPUT PARAMETERS OF THE INDICATOR | //+---------------------------------------------+ enum Applied_price_ // Constant type { PRICE_CLOSE_ = 1, //Close PRICE_OPEN_, //Open PRICE_HIGH_, //High PRICE_LOW_, //Low PRICE_MEDIAN_, //Median Price (HL/2) PRICE_TYPICAL_, //Typical Price (HLC/3) PRICE_WEIGHTED_, //Weighted Close (HLCC/4) PRICE_SIMPL_, //Simpl Price (OC/2) PRICE_QUARTER_, //Quarted Price (HLOC/4) PRICE_TRENDFOLdLow0_, //TrendFoldLow_1 Price PRICE_TRENDFOLdLow1_, //TrendFoldLow_2 Price PRICE_DEMARK_ //Demark Price }; //+-----------------------------------+ //| ??????? ????????? ?????????? | //+-----------------------------------+ input double Wmin=0; // minimum sensitivity input double Wmax=5; // maximum sensitivity input double Efactor=1.01; // coefficient E (change the value of about one in tenths and hundredths) input double Afactor=1.001; // power/degree A (change the value of about one in tenths and hundredths) input Applied_price_ IPC=PRICE_CLOSE_; // price constant input int Shift=0; // horizontal shift of the indicator in bars input int PriceShift=0; // vertical shift of the indicator in points //+-----------------------------------+ //---- declaration of dynamic arrays, which will be further used as indicator buffers double IndBuffer1[],IndBuffer2[],IndBuffer3[]; double dPriceShift,dRange; //---- Global variable declaration int min_rates_total; //+------------------------------------------------------------------+ //| EMA indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- Initialization variables starting counting data min_rates_total=2; //---- turning a dynamic array into an indicator buffer SetIndexBuffer(0,IndBuffer1,INDICATOR_DATA); //---- indexing elements in the buffer is not like in timeseries! ArraySetAsSeries(IndBuffer1,false); //---- the horizontal shift of the indicator by Shift PlotIndexSetInteger(0,PLOT_SHIFT,Shift); //---- setting indicator values that are not visible on the chart PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE); //---- turning a dynamic array into an indicator buffer SetIndexBuffer(1,IndBuffer2,INDICATOR_DATA); //---- indexing elements in the buffer is not like in timeseries! ArraySetAsSeries(IndBuffer2,false); //---- Shifting the indicator horizontally PlotIndexSetInteger(1,PLOT_SHIFT,Shift); //---- setting indicator values that are not visible on the chart PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE); //---- turning a dynamic array into an indicator buffer SetIndexBuffer(2,IndBuffer3,INDICATOR_DATA); //---- indexing elements in the buffer is not like in timeseries! ArraySetAsSeries(IndBuffer3,false); //---- Shifting the indicator horizontally PlotIndexSetInteger(2,PLOT_SHIFT,Shift); //---- setting indicator values that are not visible on the chart PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE); //---- variable initialization for the short name of the indicator string shortname="EMAVFS_channel"; //---- creating a name for display in a separate subwindow and in a tooltip IndicatorSetString(INDICATOR_SHORTNAME,shortname); //---- determination of the accuracy of the display of indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); //---- Vertical shift initialization dPriceShift=_Point*PriceShift; //---- Initialization scale calculations dRange=100000*_Point; //---- completion of initialization } //+------------------------------------------------------------------+ //| EMA iteration function | //+------------------------------------------------------------------+ int OnCalculate( const int rates_total, // amount of history in bars on the current tick const int prev_calculated,// amount of history in bars on the previous tick const datetime &time[], const double &open[], const double& high[], // price array of price highs for calculating the indicator const double& low[], // price array of price lows for calculating the indicator const double &close[], const long &tick_volume[], const long &volume[], const int &spread[] ) { //---- checking the number of bars for sufficiency for calculation if(rates_totalrates_total || prev_calculated<=0) // check on the first start of the indicator calculation { first=1; // starting number for calculating all bars wema_prew=PriceSeries(IPC,first-1,open,low,high,close)/dRange; } else first=prev_calculated-1; // starting number for calculating new bars //---- main indicator calculation cycle for(bar=first; bardOpen[bar])return(dHigh[bar]); else { if(dClose[bar]dOpen[bar])return((dHigh[bar]+dClose[bar])/2.0); else { if(dClose[bar]dOpen[bar]) res=(res+dHigh[bar])/2; if(dClose[bar]==dOpen[bar]) res=(res+dClose[bar])/2; return(((res-dLow[bar])+(res-dHigh[bar]))/2); } //---- default: return(dClose[bar]); } //---- //return(0); } //+------------------------------------------------------------------+