#property copyright "4kk4" #property link "https://www.mql5.com/en/users/4kk4" #property description "KG Bollinger Bands" //#include //--- #property indicator_chart_window #property indicator_buffers 6 #property indicator_plots 5 #property indicator_type1 DRAW_LINE #property indicator_color1 Red #property indicator_width1 2 #property indicator_type2 DRAW_LINE #property indicator_color2 Red #property indicator_type3 DRAW_LINE #property indicator_color3 Red #property indicator_type4 DRAW_LINE #property indicator_color4 Red #property indicator_style4 STYLE_DOT #property indicator_type5 DRAW_LINE #property indicator_color5 Red #property indicator_style5 STYLE_DOT #property indicator_label1 "Bands middle" #property indicator_label2 "Bands upper 1" #property indicator_label3 "Bands lower 1" #property indicator_label4 "Bands upper 2" #property indicator_label5 "Bands lower 2" //--- input parametrs input ENUM_MA_METHOD InpMaMethod = MODE_EMA; // Mode input int InpBandsPeriod=60; // Periode MA (Total Menit) input int InpBandsShift=0; // Shift input double InpBandsDeviations=1.0; // Deviation 1 input double InpBandsDeviation2=2.0; // Deviation 2 //--- global variables int ExtBandsPeriod,ExtBandsShift; double ExtBandsDeviations; double ExtBandsDeviation2; int ExtPlotBegin=0; //--- indicator buffer double ExtMLBuffer[]; double ExtTLBuffer[]; double ExtBLBuffer[]; double ExtTL2Buffer[]; double ExtBL2Buffer[]; double ExtStdDevBuffer[]; string short_name = "Bands "; //+------------------------------------------------------------------+ //| simple moving average | //+------------------------------------------------------------------+ void CalculateSimpleMA(int rates_total,int prev_calculated,int begin,const double &price[]) { int i,limit; //--- first calculation or number of bars was changed if(prev_calculated==0)// first calculation { limit=ExtBandsPeriod+begin; //--- set empty value for first limit bars for(i=0;i=period) { for(int i=0; i1) pos=prev_calculated-1; else pos=0; //--- main cycle switch(InpMaMethod) { case MODE_EMA: CalculateEMA(rates_total,prev_calculated,begin,price); break; case MODE_LWMA: CalculateLWMA(rates_total,prev_calculated,begin,price); break; case MODE_SMMA: CalculateSmoothedMA(rates_total,prev_calculated,begin,price); break; case MODE_SMA: CalculateSimpleMA(rates_total,prev_calculated,begin,price); break; } for(int i=pos; i 0) { //--- upper line ExtTLBuffer[i]=ExtMLBuffer[i]+ExtBandsDeviations*ExtStdDevBuffer[i]; //--- lower line ExtBLBuffer[i]=ExtMLBuffer[i]-ExtBandsDeviations*ExtStdDevBuffer[i]; } else { //--- upper line ExtTLBuffer[i]=0; //--- lower line ExtBLBuffer[i]=0; } if(ExtBandsDeviation2>0) { //--- upper line ExtTL2Buffer[i]=ExtMLBuffer[i]+ExtBandsDeviation2*ExtStdDevBuffer[i]; //--- lower line ExtBL2Buffer[i]=ExtMLBuffer[i]-ExtBandsDeviation2*ExtStdDevBuffer[i]; } else { //--- upper line ExtTL2Buffer[i]=0; //--- lower line ExtBL2Buffer[i]=0; } } //--- OnCalculate done. Return new prev_calculated. return(rates_total); } //+------------------------------------------------------------------+