//+---------------------------------------------------------------------+ //| MovingAverage_FN.mq5 | //| Copyright © 2009, TULA | //| Piboli | //+---------------------------------------------------------------------+ //| For the indicator to work, place the file SmoothAlgorithms.mqh | //| in the directory: terminal_data_folder\MQL5\Include | //+---------------------------------------------------------------------+ #property copyright "Copyright © 2009, TULA" #property link "" //---- indicator version number #property version "1.00" //---- drawing the indicator in the main window #property indicator_chart_window //---- number of indicator buffers #property indicator_buffers 1 //---- only one plot is used #property indicator_plots 1 //+-----------------------------------+ //| Indicator drawing parameters | //+-----------------------------------+ //---- drawing the indicator as a line #property indicator_type1 DRAW_LINE //---- DodgerBlue color is used for the indicator line #property indicator_color1 DodgerBlue //---- the indicator line is a continuous curve #property indicator_style1 STYLE_SOLID //---- indicator line width is equal to 1 #property indicator_width1 1 //---- displaying the indicator label #property indicator_label1 "MovingAverage_FN" //+-----------------------------------+ //| CXMA class description | //+-----------------------------------+ #include //+-----------------------------------+ //---- declaration of the CXMA class variables from the SmoothAlgorithms.mqh file CXMA XMA1; //+-----------------------------------+ //| Declaration of enumerations | //+-----------------------------------+ enum Applied_price_ //Type od constant { 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_TRENDFOLLOW0_, //TrendFollow_1 Price PRICE_TRENDFOLLOW1_ //TrendFollow_2 Price }; //+-----------------------------------+ //| Declaration of enumerations | //+-----------------------------------+ /*enum Smooth_Method - enumeration is declared in SmoothAlgorithms.mqh { MODE_SMA_, //SMA MODE_EMA_, //EMA MODE_SMMA_, //SMMA MODE_LWMA_, //LWMA MODE_JJMA, //JJMA MODE_JurX, //JurX MODE_ParMA, //ParMA MODE_T3, //T3 MODE_VIDYA, //VIDYA MODE_AMA, //AMA }; */ //+-----------------------------------+ //| Declaration of enumerations | //+-----------------------------------+ enum filter_mode { N4=4, //filter ¹4 N5, //filter ¹5 N6, //filter ¹6 N7, //filter ¹7 N8, //filter ¹8 N9, //filter ¹9 N10, //filter ¹10 N11, //filter ¹11 N12, //filter ¹12 N13, //filter ¹13 N14, //filter ¹14 N15, //filter ¹15 N16, //filter ¹16 N17, //filter ¹17 N18, //filter ¹18 N19, //filter ¹19 N20, //filter ¹20 N21, //filter ¹21 N22, //filter ¹22 N23, //filter ¹23 N24, //filter ¹24 N25, //filter ¹25 N26, //filter ¹26 N27, //filter ¹27 N28, //filter ¹28 N29, //filter ¹29 N30, //filter ¹30 N31, //filter ¹31 N32, //filter ¹32 N33, //filter ¹33 N34, //filter ¹34 N35, //filter ¹35 N36, //filter ¹36 N37, //filter ¹37 N38, //filter ¹38 N39, //filter ¹39 N40, //filter ¹40 N41, //filter ¹41 N42, //filter ¹42 N43, //filter ¹43 N44, //filter ¹44 N45, //filter ¹45 N46, //filter ¹46 N47, //filter ¹47 N48, //filter ¹48 N49, //filter ¹49 N50, //filter ¹50 N51, //filter ¹51 N52, //filter ¹52 N53, //filter ¹53 N54, //filter ¹54 N55, //filter ¹55 N56, //filter ¹56 N57, //filter ¹57 N58, //filter ¹58 N59, //filter ¹59 N60 //filter ¹60 }; //+-----------------------------------+ //| INDICATOR INPUT PARAMETERS | //+-----------------------------------+ input filter_mode FilterNumber=N44; //fulter number for the calculation input Smooth_Method XMA_Method=MODE_JJMA; //smoothing method input int XLength=12; //smoothing depth input int XPhase=15; //smoothing parameter, // for JJMA that can change withing the range -100 ... +100. It impacts the quality of the intermediate process of smoothing; // For VIDIA, it is a CMO period, for AMA, it is a slow moving average period input Applied_price_ IPC=PRICE_CLOSE;//price constant /* , used for calculation of the indicator ( 1-CLOSE, 2-OPEN, 3-HIGH, 4-LOW, 5-MEDIAN, 6-TYPICAL, 7-WEIGHTED, 8-SIMPL, 9-QUARTER, 10-TRENDFOLLOW, 11-0.5 * TRENDFOLLOW.) */ input int Shift=0; // horizontal shift of the indicator in bars input int PriceShift=0; // vertical shift of the indicator in pointsõ //+-----------------------------------+ //---- declaration of a dynamic array that further // will be used as an indicator buffer double XMA[]; //---- Declaration of the average vertical shift value variable double dPriceShift; //---- Declaration of integer variables of data starting point int min_rates_total; //+------------------------------------------------------------------+ //| MovingAverage_FN indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- Initialization of variables of the start of data calculation min_rates_total=700+XMA1.GetStartBars(XMA_Method, XLength, XPhase); //---- setting alerts for invalid values of external parameters XMA1.XMALengthCheck("XLength", XLength); XMA1.XMAPhaseCheck("XPhase", XPhase, XMA_Method); //---- Initialization of the vertical shift dPriceShift=_Point*PriceShift; //---- set dynamic array as an indicator buffer SetIndexBuffer(0,XMA,INDICATOR_DATA); //---- moving the indicator 1 horizontally PlotIndexSetInteger(0,PLOT_SHIFT,Shift); //---- 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); //--- creation of the name to be displayed in a separate sub-window and in a pop up help IndicatorSetString(INDICATOR_SHORTNAME,"MovingAverage_FN"); //--- determining the accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); //---- end of initialization } //+------------------------------------------------------------------+ //| MovingAverage_FN 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 datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[] ) { //---- checking the number of bars to be enough for calculation if(rates_totalrates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator first=700; // starting number for calculation of all bars else first=prev_calculated-1; // starting number for calculation of new bars //---- Main calculation loop of the indicator for(bar=first; bar