//+------------------------------------------------------------------+ //| XXMA.mq5 | //| Copyright © 2009, XrustSolution. Toys from Vinin.| //| http://www.xrust.ucoz.net http://www.vinin.ucoz.ru | //| xrust@land.ru xrust@gmail.com xrust@mksat.net | //+------------------------------------------------------------------+ /* * For the indicator to work, place the * SmoothAlgorithms.mqh * in the directory: MetaTrader\\MQL5\Include */ #property copyright "#Copyright © 2008, XrustSolution.#" #property link "#http://www.xrust.ucoz.net#" //---- 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 //---- blue color is used for the indicator line #property indicator_color1 clrBlue //---- the indicator line is a continuous curve #property indicator_style1 STYLE_SOLID //---- Indicator line width is equal to 2 #property indicator_width1 2 //---- displaying the indicator label #property indicator_label1 "XXMA" //+-----------------------------------+ //| 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 }; /*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 }; */ //+-----------------------------------+ //| INDICATOR INPUT PARAMETERS | //+-----------------------------------+ input Smooth_Method XMA_Method=MODE_SMA; // Smoothing method input uint XLength=12; // Smoothing depth input int XPhase=15; // Smoothing parameter input Applied_price_ IPC=PRICE_CLOSE; // Price constant input uint Step=10; // Step of trigger 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 XXMA[]; //---- Declaration of the average vertical shift value variables double dPriceShift,dStep; //---- Declaration of integer variables of data starting point int min_rates_total; //+------------------------------------------------------------------+ //| XXMA indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- Initialization of variables of the start of data calculation min_rates_total=XMA1.GetStartBars(XMA_Method,XLength,XPhase)+1; //---- 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; dStep=_Point*Step; //---- set dynamic array as an indicator buffer SetIndexBuffer(0,XXMA,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,EMPTY_VALUE); //---- initializations of variable for indicator short name string shortname; string Smooth1=XMA1.GetString_MA_Method(XMA_Method); StringConcatenate(shortname,"XXMA(",XLength,", ",Smooth1,")"); //--- creation of the name to be displayed in a separate sub-window and in a pop up help IndicatorSetString(INDICATOR_SHORTNAME,shortname); //--- determining the accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); //---- end of initialization } //+------------------------------------------------------------------+ //| XXMA 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=0; // starting number for calculation of all bars prevxma=PriceSeries(IPC,0,open,low,high,close); } else first=prev_calculated-1; // starting number for calculation of new bars //---- Main calculation loop of the indicator for(bar=first; bar=dStep) XXMA[bar]=xma+dPriceShift; else XXMA[bar]=XXMA[bar-1]; if(bar