Indicator disappears

 
Hi everybody,


I've been build some indicators, but most of them have the same errors:

Just at the moment when a new bar appears, the indicator shows zero. If a new tick comes, the indicator come back to it's normal value.

If I change the time frame, the indicator disappears.


Example :

#property copyright "Copyright © 2010, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Yellow

//--- External Variables ---//
extern int aver_Impulse_period=14;
extern double perc_above_aver=40;

//--- External Buffers ---//
double Impulse[];
double mov_Impulse[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators buffers
   IndicatorBuffers(2);

   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(0,Impulse);
   
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1,mov_Impulse);
   
   return(0);
  }
//-----  
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {int   counted_bars=IndicatorCounted();
   int limit;
  
//---- Data ckecking ----//
   if (counted_bars==0)
      {
      limit=Bars-aver_Impulse_period-1;
      }
   if (counted_bars>0)
      {
      limit=Bars-counted_bars;
      } 
   Print("limit= ",limit);
    
//---- Math part ----//
double aaa = 1+NormalizeDouble(perc_above_aver/100,2);

   for(int i=limit;i>=0;i--) // Count down for one pass
      {   
         Impulse[i]=MathAbs(Close[i]-Close[i+1]);
         mov_Impulse[i]=iMAOnArray(Impulse,0,aver_Impulse_period,0,MODE_EMA,i)*aaa;
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

There is a solution for it?


Thanks

 
Don't use bar 0 of the indicator.
 
Ok, are you doing reference to this part? for(int i=limit;i>=0;i--) I changed it to for(int i=limit;i>0;i--) but the problem remains.
 

Now I realize that this problem only occurs when I do an average of an array ( when I use iMAOnArray function).

Any idea to solve this problem?

WHRoeder, thanks for your help.


rodrigosm

Reason: