переделать индикатор Bollinger Bands

 

Добрый день всем!

пытаюсь переделать код ВВ на основе экспоненциальной средней , не простой МА,

что-то не получается, может ли кто-нибудь подсказать где ошибка?

Индикатор не рисуется. При компиляции ошибок нет. Спасибо.

//+------------------------------------------------------------------+
//|                                                  Bb exponent.mq4 |
//|                   Copyright 2005-2015, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2015, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "BB exponent"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 DeepSkyBlue
#property indicator_color2 Gold
#property indicator_color3 Gold
//--- indicator parameters
input int            InpMAPeriod=20;        // Period
input int            InpMAShift=0;          // Shift
//input ENUM_MA_METHOD InpMAMethod=MODE_EMA;  // Method
input double InpBandsDeviations=2; // Bands Deviations
//--- indicator buffer
//--- buffers
double ExtMovingBuffer[];
double ExtUpperBuffer[];
double ExtLowerBuffer[];
double ExtStdDevBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
  //--- 1 additional buffer used for counting.
   IndicatorBuffers(4);
   IndicatorDigits(Digits);
   //--- middle line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMovingBuffer);
   SetIndexShift(0,InpMAShift);
   SetIndexLabel(0,"EMA");
//--- upper band
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtUpperBuffer);
   SetIndexShift(1,InpMAShift);
   SetIndexLabel(1,"Bands Upper");
//--- lower band
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtLowerBuffer);
   SetIndexShift(2,InpMAShift);
   SetIndexLabel(2,"Bands Lower");
//--- work buffer
   SetIndexBuffer(3,ExtStdDevBuffer);
   //--- check for input parameter
   if(InpMAPeriod<=0)
     {
      Print("Wrong input parameter Bands Period=",InpMAPeriod);
      return(INIT_FAILED);
     }
//---
   SetIndexDrawBegin(0,InpMAPeriod+InpMAShift);
   SetIndexDrawBegin(1,InpMAPeriod+InpMAShift);
   SetIndexDrawBegin(2,InpMAPeriod+InpMAShift);
//--- initialization done
  // return(INIT_SUCCEEDED);
//---------------------------------------------------------------------------------
   string short_name;
   int    draw_begin=InpMAPeriod-1;
//--- indicator short name
    IndicatorShortName(short_name+string(InpMAPeriod)+")");
 //--- check for input
   if(InpMAPeriod<2)
      return(INIT_FAILED);
//--- drawing settings
//--- initialization done
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|  Moving Average                                                  |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                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[])
  {
   int i,limit,pos;
//--- check for bars count
   if(rates_total<InpMAPeriod-1 || InpMAPeriod<2)
      return(0);
//--- counting from 0 to rates_total
   ArraySetAsSeries(ExtMovingBuffer,false);
   ArraySetAsSeries(ExtUpperBuffer,false);
   ArraySetAsSeries(ExtLowerBuffer,false);
   ArraySetAsSeries(ExtStdDevBuffer,false);
   ArraySetAsSeries(close,false);
   ArraySetAsSeries(ExtMovingBuffer,false);
//--- first calculation or number of bars was changed
 //  if(prev_calculated==0)
 //     ArrayInitialize(ExtLineBuffer,0);
//--- calculation
       //CalculateEMA(rates_total,prev_calculated,close);   
     
//===================================================================================================
//--- initial zero
   if(prev_calculated<1)
     {
      for(i=0; i<InpMAPeriod; i++)
        {
         ExtMovingBuffer[i]=EMPTY_VALUE;
         ExtUpperBuffer[i]=EMPTY_VALUE;
         ExtLowerBuffer[i]=EMPTY_VALUE;
        }
     }
//--- starting calculation
   if(prev_calculated>1)
      pos=prev_calculated-1;
   else
      pos=0;
//--- main cycle
double price[];
double SmoothFactor=2.0/(1.0+InpMAPeriod);
   for(i=pos; i<rates_total && !IsStopped(); i++)
     {
      //--- middle line
      ExtMovingBuffer[i]=price[i]*SmoothFactor+ExtMovingBuffer[i-1]*(1.0-SmoothFactor);
      //iMAOnArray(i,0,InpMAPeriod,0,MODE_EMA,0);
      //--- calculate and write down StdDev
      ExtStdDevBuffer[i]=StdDev_Func(i,close,ExtMovingBuffer,InpMAPeriod);
      //--- upper line
      ExtUpperBuffer[i]=ExtMovingBuffer[i]+InpBandsDeviations*ExtStdDevBuffer[i];
      //--- lower line
      ExtLowerBuffer[i]=ExtMovingBuffer[i]-InpBandsDeviations*ExtStdDevBuffer[i];
      //---
     }     
//====================================================================================
 //--- first calculation or number of bars was changed
   if(prev_calculated==0)
     {
      limit=InpMAPeriod;
      ExtMovingBuffer[0]=price[0];
      for(i=1; i<limit; i++)
         ExtMovingBuffer[i]=price[i]*SmoothFactor+ExtMovingBuffer[i-1]*(1.0-SmoothFactor);
     }
   else
      limit=prev_calculated-1;
//--- main loop
   for(i=limit; i<rates_total && !IsStopped(); i++)
      ExtMovingBuffer[i]=price[i]*SmoothFactor+ExtMovingBuffer[i-1]*(1.0-SmoothFactor);
//---
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Calculate Standard Deviation                                     |
//+------------------------------------------------------------------+
double StdDev_Func(int position,const double &price[],const double &MAprice[],int period)
  {
//--- variables
   double StdDev_dTmp=0.0;
//--- check for position
   if(position>=period)
     {
      //--- calcualte StdDev
      for(int i=0; i<period; i++)
         StdDev_dTmp+=MathPow(price[position-i]-MAprice[position],2);
      StdDev_dTmp=MathSqrt(StdDev_dTmp/period);
     }
//--- return calculated value
   return(StdDev_dTmp);
  }
//+------------------------------------------------------------------+
 
flat55:  пытаюсь переделать код ВВ на основе экспоненциальной средней , не простой МА,

что-то не получается, может ли кто-нибудь подсказать где ошибка? Индикатор не рисуется. При компиляции ошибок нет.

Журнал смотрели? Файл прикрепите. Руководитель курсового проекта объяснял, как отлаживать?
 

 в журнале ничего нет , спасибо за советы.

нужна реальная помощь.