Custom indicator not displaying arrows...

 

Hello, I originally made this indicator just to display an arrow on the following bar after MACD histogram changes direction, I would now like these arrows to filtered using two MAs ie. fast is above slow. 

I have edited my code and it is running with no errors but it will not display anything anymore - can anyone help please I don't know whats wrong?


Many Thanks! :)

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrLawnGreen
#property indicator_color2 clrRed
#property strict


//------------------------------------------------------------------
//MACD//
extern int                Fast_EMA = 12;          // Fast ema period
extern int                Slow_EMA = 26;          // Slow ema period
extern ENUM_APPLIED_PRICE price    = PRICE_CLOSE; // Price
extern ENUM_TIMEFRAMES TF = PERIOD_H1;

//Moving Average//
extern int                MA_Fast  = 20;          // Fast MA period
extern int                MA_Slow  = 50;          // Slow MA period
extern ENUM_MA_METHOD     MA_Type  = MODE_SMA;

double CrossUp[],CrossDown[],direction[],macd[],FastMA[],SlowMA[];

int OnInit()
{
   IndicatorBuffers(5);
   SetIndexBuffer(0, CrossUp);   SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 225);
   SetIndexBuffer(1, CrossDown); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 226);
   SetIndexBuffer(2, direction); 
   SetIndexBuffer(3, macd); 
   SetIndexBuffer(4, FastMA);
   SetIndexBuffer(5, SlowMA);
   
   SetIndexShift(0,1);
   SetIndexShift(1,1);
  return(0);
}
int OnCalculate (const int       rates_total,
                 const int       prev_calculated,
                 const datetime& btime[],
                 const double&   open[],
                 const double&   high[],
                 const double&   low[],
                 const double&   close[],
                 const long&     tick_volume[],
                 const long&     volume[],
                 const int&      spread[] )
{
   int counted_bars = prev_calculated;
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
            int limit=MathMin(rates_total-counted_bars,rates_total-1);
         int shift;

      for(int i=limit; i>0; i--)
      {
      shift=iBarShift(Symbol(),TF,Time[i]);
      if(Time[i]!=iTime(Symbol(),TF,shift)) continue;
      
      
         macd[i]      = iMA(NULL,TF,Fast_EMA,0,MODE_EMA,price,shift)-iMA(NULL,TF,Slow_EMA,0,MODE_EMA,price,shift);
         FastMA[i]    = iMA(NULL,TF,MA_Fast,0,MA_Type,price,shift);
         SlowMA[i]    = iMA(NULL,TF,MA_Slow,0,MA_Type,price,shift);
         
if(i<rates_total-TF/Period()-1)
  {
   if((macd[i]>macd[i+TF/Period()]) && (macd[i]<0)   &&  (FastMA[i]>SlowMA[i])    )
     {
      direction[i]=1;
     }
   else if((macd[i]<macd[i+TF/Period()])  && (macd[i]>0)   &&  (FastMA[i]<SlowMA[i])    )
     {
      direction[i]=-1;
     }
   else
     {
      direction[i]=0;
     }
  }
else
  {
   direction[i]=0;
  }
        
        
        
        
        
//------------       
         CrossUp[i]   = EMPTY_VALUE;
         CrossDown[i] = EMPTY_VALUE;
         if (i<Bars-TF/Period()-1 && direction[i]!=direction[i+TF/Period()])
         {
               if (direction[i]== 1) CrossUp[i-TF/Period()+1]   = Low[i-TF/Period()+1]  - iATR(NULL,0,10,i-TF/Period()+1);
               if (direction[i]==-1) CrossDown[i-TF/Period()+1] = High[i-TF/Period()+1] + iATR(NULL,0,10,i-TF/Period()+1);
         }
  }
  
  
  
  
  
  
  return(rates_total);
}
 

You reset index 'i', but then change the value of 'i-TF/Period()+1'

         CrossUp[i]   = EMPTY_VALUE;
         CrossDown[i] = EMPTY_VALUE;
         if (i<Bars-TF/Period()-1 && direction[i]!=direction[i+TF/Period()])
         {
               if (direction[i]== 1) CrossUp[i-TF/Period()+1]   = Low[i-TF/Period()+1]  - iATR(NULL,0,10,i-TF/Period()+1);
               if (direction[i]==-1) CrossDown[i-TF/Period()+1] = High[i-TF/Period()+1] + iATR(NULL,0,10,i-TF/Period()+1);
         }
 
THanks for reply knave - little confused what you mean - please advise how to go ahead... thanks! :)