Difficulty in attempt of Multi Timeframe Indicator

 

Ive been trying to make the following code draw a double smoothed stochastic of the 30m chart while on the 5m chart but always get a critical error and not sure why? I have tried to put PERIOD_M30 enumeration in 2nd parameter of iHigest() and iLowest() but it doesnt work. 

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 2
#property indicator_level1 20
#property indicator_level2 80

#define stochBull 97
#define stochBear 10

//---- input parameters
extern int EMA_period = 16;
extern int Stochastic_period = 20;

//---- buffers
double DssBuffer[];
double MitBuffer[];


double smooth_coefficient;
int period = 0;
int largerTimeFrame = 0;


int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_NONE); 
   SetIndexBuffer(0,DssBufferSmall);
   
   SetIndexStyle(1,DRAW_NONE); 
   SetIndexBuffer(1,MitBufferSmall);

   return(0);
  }   

int start()
  {                     
   int i, limitS, counted_bars = IndicatorCounted();                
//----
   if (counted_bars == 0)   limitS = Bars - Stochastic_period;  
   if (counted_bars > 0)   limitS = Bars - counted_bars;       
                                                                                                                  
   double HighRange, LowRange;
   double delta, MIT;
   
   // Small Chart Buffers
   for (i = limitS; i >= 0; i--) 
   {                          
      HighRange = High[iHighest(_Symbol,PERIOD_M30,MODE_HIGH,Stochastic_period,i)];
      LowRange = Low[iLowest(_Symbol,PERIOD_M30,MODE_LOW,Stochastic_period,i)];
      delta = Close[i] - LowRange; 
      MIT = delta/(HighRange - LowRange)*100.0;
      MitBufferSmall[i] = smooth_coefficient * (MIT - MitBufferSmall[i+1]) + MitBufferSmall[i+1];  
   }

   double DSS;   
   for (i = limitS; i >= 0; i--)
   {
      HighRange = MitBufferSmall[ArrayMaximum(MitBufferSmall, Stochastic_period, i)];
      LowRange = MitBufferSmall[ArrayMinimum(MitBufferSmall, Stochastic_period, i)];
      delta = MitBufferSmall[i] - LowRange;
      DSS = delta/(HighRange - LowRange)*100.0;
      DssBufferSmall[i] = smooth_coefficient * (DSS - DssBufferSmall[i+1]) + DssBufferSmall[i+1];
   }
   
   // Here I create the artwork for drawing the line (Using ObjectCreate() instead of SetIndexStyle())   
   for(i = limitS; i >= 0; i--)
   {
      datetime timeS = iTime(NULL,0,i);
      string ob_LineS = "LineS "+TimeToStr(timeS);

      // Small buffers   
      if(DssBufferSmall[i] > DssBufferSmall[i+1]) 
      {
         ObjectCreate(0,ob_LineS,OBJ_ARROW,1,timeS,DssBufferSmall[i]);
         ObjectSetInteger(0,ob_LineS,OBJPROP_ARROWCODE,159);
         ObjectSetInteger(0,ob_LineS,OBJPROP_COLOR,clrRed);   
      }
      else 
      {
         ObjectCreate(0,ob_LineS,OBJ_ARROW,1,timeS,DssBufferSmall[i]);
         ObjectSetInteger(0,ob_LineS,OBJPROP_ARROWCODE,159);
         ObjectSetInteger(0,ob_LineS,OBJPROP_COLOR,clrBlue);
      }
   }

   return(0);
}
 

What error do you get?

                        
      HighRange = High[iHighest(_Symbol,PERIOD_M30,MODE_HIGH,Stochastic_period,i)];

you are getting an index from a higher timeframe and using it on a lower timeframe. That doesn't make sense

 
HighRange = High[iHighest(_Symbol,PERIOD_M30,MODE_HIGH,Stochastic_period,i)];
  1. GumRai: you are getting an index from a higher timeframe and using it on a lower timeframe. That doesn't make sense
    And using a index on a lower timeframe to find the highest bar on a higher timeframe.
  2. You are mixing apples and oranges
Reason: