How to write a customer indicator(CIndicator ) for Expert using.

 

  I am trying to use  "Indictors"  in EA. instead the original iMACD we use.
 But get some trouble .. there is no data . After I run on EA. There is no error message as initial., Create buffer there is no update data.

>><




#include <Indicators/Indicator.mqh>

class CiMACD2 : public CIndicator
  {
protected:
   int               m_fast_ema_period;
   int               m_slow_ema_period;
   int               m_signal_period;
   int               m_applied;

public:
                     CiMACD2(void);
                    ~CiMACD2(void);
...
   //--- method of creation
   bool              Create(const string symbol,const ENUM_TIMEFRAMES period,
                            const int fast_ema_period,const int slow_ema_period,
                            const int signal_period,const int applied);
   //--- methods of access to indicator data
   double            Main(const int index) const;
   double            Signal(const int index) const;
protected:
   //--- methods of tuning
   virtual bool      Initialize(const string symbol,const ENUM_TIMEFRAMES period,const int num_params,const MqlParam &params[]);
   bool              Initialize(const string symbol,const ENUM_TIMEFRAMES period,
                                const int fast_ema_period,const int slow_ema_period,
                                const int signal_period,const int applied);
  };

....

bool CiMACD2::Create(const string symbol,const ENUM_TIMEFRAMES period,
                    const int fast_ema_period,const int slow_ema_period,
                    const int signal_period,const int applied)
  {
...
   m_handle=iCustom(_Symbol,period,"macd_anytimeframe",period,m_fast_ema_period,m_slow_ema_period,m_signal_period, PRICE_CLOSE);
...
  }


bool CiMACD2::Initialize(const string symbol,const ENUM_TIMEFRAMES period,
                        const int fast_ema_period,const int slow_ema_period,
                        const int signal_period,const int applied)
  {
   if(CreateBuffers(symbol,period,2))
     {//--- string of status of drawing
      m_name  ="MACD";
      m_status="("+symbol+","+PeriodDescription()+","+
               IntegerToString(fast_ema_period)+","+IntegerToString(slow_ema_period)+","+
               IntegerToString(signal_period)+","+PriceDescription(applied)+","+") H="+IntegerToString(m_handle);
...
      //--- create buffers
      ((CIndicatorBuffer*)At(0)).Name("MAIN_LINE");
      ((CIndicatorBuffer*)At(1)).Name("SIGNAL_LINE");
      //--- ok
      return(true);
     }
//--- error
   return(false);
  }



ool CSignalmutiMACD2::InitMACD(CIndicators *indicators)
  {
...
   int subWindowId=(int)ChartGetInteger(0,CHART_WINDOWS_TOTAL); 
   if(!indicators.Add(GetPointer(m_MACD1)))
     {
      printf(__FUNCTION__+": error adding object");
      return(false);
     }

  //--- initialize object
   if(!m_MACD1.Create(m_symbol.Name(),PERIOD_CURRENT,m_period_fast,m_period_slow,m_period_signal,m_applied))
     {//m_symbol.Name(),m_period_small,5,3,m_applied))
      printf(__FUNCTION__+": error initializing object");
      return(false);
     }
   chart1=iCustom(_Symbol,PERIOD_CURRENT,"macd_anytimeframe",m_period_small,5,3);
   if(chart1){
      if(!ChartIndicatorAdd(0,1  ,chart1))
         PrintFormat("Failed to add MACD(samll) on chart. Error code  %d",GetLastError());
   }else{
      printf(__FUNCTION__+": error initializing small indictor object");
      return(false);
     }
                                      
//--- ok
   //--- add object to collection
   if(!indicators.Add(GetPointer(m_MACD2)))
     {
      printf(__FUNCTION__+": error adding object");
      return(false);
     }
   ChartRedraw(0);  
//--- ok
   return(true);
  }