//+---------------------------------------------------------------------+ //| XDPO.mq5 | //| Copyright © 2011, Nikolay Kositsin | //| Khabarovsk, farria@mail.redcom.ru | //+---------------------------------------------------------------------+ //| Place the SmoothAlgorithms.mqh file | //| in the directory: terminal_data_folder\MQL5\Include | //+---------------------------------------------------------------------+ #property copyright "Copyright © 2011, Nikolay Kositsin" #property link "farria@mail.redcom.ru" //--- Indicator version #property version "1.00" //--- drawing the indicator in the main window #property indicator_chart_window //--- number of indicator buffers is 2 #property indicator_buffers 2 //--- one plot is used #property indicator_plots 1 //+----------------------------------------------+ //| Indicator 1 drawing parameters | //+----------------------------------------------+ //--- drawing the indicator as a colored cloud #property indicator_type1 DRAW_FILLING //--- the following colors are used for the indicator #property indicator_color1 clrGreen,clrRed //--- displaying the indicator label #property indicator_label1 "Up;Down" //+----------------------------------------------+ //| CXMA class description | //+----------------------------------------------+ #include //+----------------------------------------------+ //--- declaration of the CXMA class variables from the SmoothAlgorithms.mqh file CXMA XMA1,XMA2; //+----------------------------------------------+ //| declaration of enumerations | //+----------------------------------------------+ enum Applied_price_ // type of 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_SIMPLE_, // Simple Price (OC/2) PRICE_QUARTER_, // Quarted Price (HLOC/4) PRICE_TRENDFOLLOW0_, // TrendFollow_1 Price PRICE_TRENDFOLLOW1_, // TrendFollow_2 Price PRICE_DEMARK_ // Demark Price }; //+----------------------------------------------+ //| Indicator input parameters | //+----------------------------------------------+ input Smooth_Method MA_Method1=MODE_SMA; // First smoothing averaging method input int Length1=12; // Depth of the first smoothing input int Phase1=15; // First smoothing parameter //--- Phase1: for JJMA it varies within the range -100 ... +100 and influences the quality of the transient period; //--- Phase1: for VIDIA it is a CMO period, for AMA it is a slow average period input Smooth_Method MA_Method2=MODE_T3; // Averaging method of the second smoothing input int Length2 = 5; // Depth of the second smoothing input int Phase2=15; // Second smoothing parameter //--- Phase2: for JJMA it varies within the range -100 ... +100 and influences the quality of the transient period; //--- Phase2: For VIDIA it is a CMO period, for AMA it is a slow average period input Applied_price_ IPC=PRICE_CLOSE; // Price constant input int Shift=0; // Horizontal shift of the indicator in bars //+----------------------------------------------+ //--- declaration of dynamic arrays that will be used as indicator buffers double UpIndBuffer[]; double DnIndBuffer[]; //--- declaration of integer variables for the start of data calculation int min_rates_total,min_rates_1,min_rates_2; //+------------------------------------------------------------------+ //| XDPO indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- initialization of variables of data calculation start min_rates_1=XMA1.GetStartBars(MA_Method1, Length1, Phase1); min_rates_2=XMA2.GetStartBars(MA_Method2, Length2, Phase2); min_rates_total=min_rates_1+min_rates_2; //--- setting up alerts for unacceptable values of external variables XMA1.XMALengthCheck("Length1", Length1); XMA2.XMALengthCheck("Length2", Length2); //--- setting up alerts for unacceptable values of external variables XMA1.XMAPhaseCheck("Phase1", Phase1, MA_Method1); XMA2.XMAPhaseCheck("Phase2", Phase2, MA_Method2); //--- Initialize indicator buffers IndInit(0,UpIndBuffer,INDICATOR_DATA); IndInit(1,DnIndBuffer,INDICATOR_DATA); //--- initialization of indicators PlotInit(0,0.0,min_rates_total,Shift); //--- initializations of a variable for the indicator short name string shortname; string Smooth1=XMA1.GetString_MA_Method(MA_Method1); string Smooth2=XMA1.GetString_MA_Method(MA_Method2); StringConcatenate(shortname,"XDPO(",Length1,", ",Length2,", ",Smooth1,", ",Smooth2,")"); //--- 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 the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); //--- initialization end } //+------------------------------------------------------------------+ //| XDPO iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, // number of bars in history 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 if the number of bars is enough for the calculation if(rates_totalrates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator first=0; // starting index for calculation of all bars else first=prev_calculated-1; // starting number for calculation of new bars //--- main indicator calculation loop for(bar=first; bar