//+------------------------------------------------------------------+ //| HMA.mq5 | //| Copyright © 2010, Nikolay Kositsin | //| Khabarovsk, farria@mail.redcom.ru | //+------------------------------------------------------------------+ //| Place the SmoothAlgorithms.mqh file | //| to the directory: terminal_data_folder\\MQL5\Include | //+------------------------------------------------------------------+ #property copyright "2010, Nikolay Kositsin" #property link "farria@mail.redcom.ru" #property version "1.00" //---- drawing the indicator in the main window #property indicator_chart_window //---- one buffer is used for the indicator calculation and drawing #property indicator_buffers 1 //---- only one plot is used #property indicator_plots 1 //---- drawing the indicator as a line #property indicator_type1 DRAW_LINE //---- medium purple color is used for the indicator line #property indicator_color1 MediumPurple //---- the indicator line is a continuous curve #property indicator_style1 STYLE_SOLID //---- indicator line width is equal to 1 #property indicator_width1 2 //+-----------------------------------+ //| Indicator input parameters | //+-----------------------------------+ input int HMA_Period=13; // Moving average period input int HMA_Shift=0; // Horizontal shift of the average in bars //+-----------------------------------+ //---- indicator buffer double ExtLineBuffer[]; //---- declaration of integer variables int Hma2_Period,Sqrt_Period; //---- declaration of the integer variables for the start of data calculation int min_rates_total; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { Hma2_Period=int(MathFloor(HMA_Period/2)); Sqrt_Period=int(MathFloor(MathSqrt(HMA_Period))); //---- initialization of variables of the start of data calculation min_rates_total=HMA_Period+Sqrt_Period; //---- name for the data window and the label for sub-windows string short_name="HMA"; IndicatorSetString(INDICATOR_SHORTNAME,short_name+"("+string(HMA_Period)+")"); //---- setting the indicator values that won't be visible on a chart PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE); //---- set ExtLineBuffer[] dynamic array as an indicator buffer SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA); //---- shifting the moving average horizontally by HMAShift PlotIndexSetInteger(0,PLOT_SHIFT,HMA_Shift); //---- shifting the start of drawing of the HMAPeriod indicator PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); //---- setting the format of accuracy of displaying the indicator IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); //---- } //---- Description of the CMoving_Average class #include //+------------------------------------------------------------------+ //| 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_total