//+---------------------------------------------------------------------+ //| i-BandsPrice.mq5 | //| Copyright © 2008, Talex | //| tan@gazinter.net | //+---------------------------------------------------------------------+ //| For the indicator to work, place the file SmoothAlgorithms.mqh | //| in the directory: terminal_data_folder\MQL5\Include | //+---------------------------------------------------------------------+ #property copyright "Copyright © 2008, Talex" #property link "tan@gazinter.net" #property description "i-BandsPrice" //---- indicator version number #property version "1.00" //---- drawing indicator in a separate window #property indicator_separate_window //---- number of indicator buffers #property indicator_buffers 2 //---- only one plot is used #property indicator_plots 1 //+-----------------------------------+ //| Indicator drawing parameters | //+-----------------------------------+ //---- drawing the indicator as a multy-color histogram #property indicator_type1 DRAW_COLOR_HISTOGRAM //---- the following colors are used in the histogram #property indicator_color1 clrMagenta,clrMaroon,clrGray,clrTeal,clrLime //---- Indicator line width is equal to 2 #property indicator_width1 2 //---- displaying the indicator label #property indicator_label1 "i-BandsPrice" //+-----------------------------------+ //| Averaging classes description | //+-----------------------------------+ #include //+-----------------------------------+ //---- declaration of the CXMA and CStdDeviation classes variables from the SmoothAlgorithms.mqh file CXMA XMA1,XMA2; CStdDeviation STD; //+-----------------------------------+ //| 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 PRICE_DEMARK_ //Demark 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; //first smoothing method input uint XLength=100; //first smoothing depth input int XPhase=15; //first 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 uint BandsPeriod=100; //BB smoothing period input double BandsDeviation=2.0; //deviation input uint Smooth=5; //indicator smoothing period input Applied_price_ IPC=PRICE_CLOSE;//price constant input int UpLevel=+25; //Up level input int DnLevel=-25; //Down level input int Shift=0; // horizontal shift of the indicator in bars //+-----------------------------------+ //---- declaration of dynamic arrays that will further be //---- will be used as Bollinger Bands indicator buffers double IndBuffer[],ColorIndBuffer[]; //---- Declaration of integer variables of data starting point int min_rates_total,min_rates_1,min_rates_2; //+------------------------------------------------------------------+ //| X2MA BBx3 indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- Initialization of variables of the start of data calculation min_rates_1=XMA1.GetStartBars(XMA_Method,XLength,XPhase)+1; min_rates_2=min_rates_1+int(BandsPeriod); min_rates_total=min_rates_2+30; //---- setting alerts for invalid values of external parameters XMA1.XMALengthCheck("XLength",XLength); XMA2.XMALengthCheck("BandsPeriod", BandsPeriod); XMA1.XMALengthCheck("Smooth",Smooth); //---- setting alerts for invalid values of external parameters XMA1.XMAPhaseCheck("XPhase",XPhase,XMA_Method); //---- set dynamic array as an indicator buffer SetIndexBuffer(0,IndBuffer,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); //---- setting dynamic array as a color index buffer SetIndexBuffer(1,ColorIndBuffer,INDICATOR_COLOR_INDEX); //--- creation of the name to be displayed in a separate sub-window and in a pop up help IndicatorSetString(INDICATOR_SHORTNAME,"i-BandsPrice"); //--- determining the accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,0); //---- the number of the indicator 3 horizontal levels IndicatorSetInteger(INDICATOR_LEVELS,3); //---- values of the indicator horizontal levels IndicatorSetDouble(INDICATOR_LEVELVALUE,0,UpLevel); IndicatorSetDouble(INDICATOR_LEVELVALUE,1,0); IndicatorSetDouble(INDICATOR_LEVELVALUE,2,DnLevel); //---- gray and magenta colors are used for horizontal levels lines IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,clrBlue); IndicatorSetInteger(INDICATOR_LEVELCOLOR,1,clrGray); IndicatorSetInteger(INDICATOR_LEVELCOLOR,2,clrBlue); //---- short dot-dash is used for the horizontal level line IndicatorSetInteger(INDICATOR_LEVELSTYLE,0,STYLE_DASHDOTDOT); IndicatorSetInteger(INDICATOR_LEVELSTYLE,1,STYLE_DASHDOTDOT); IndicatorSetInteger(INDICATOR_LEVELSTYLE,2,STYLE_DASHDOTDOT); //---- end of initialization } //+------------------------------------------------------------------+ //| X2MA BBx3 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 else first=prev_calculated-1; // starting number for calculation of new bars //---- Main calculation loop of the indicator for(bar=first; barUpLevel) clr=4; else if(jres>0) clr=3; if(jres