Need help [count 4 candles]

 
//--- input parameters
input int minRangePips = 200; // Minimal range in pips
input int maxRangePips = 500; // Maximal range in pips

//--- indicator buffers
double BuyBuffer[];
double SellBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   // Indicator buffers mapping
   SetIndexBuffer(0, BuyBuffer);
   SetIndexBuffer(1, SellBuffer);

   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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 counted_bars = BarsCalculated(rates_total);
   if(counted_bars < 1)
      counted_bars = 1;
   
   for(int i = counted_bars; i < rates_total; i++)
   {
      double range = (high[i-1] - low[i-1]) / Point;
      
      // Identify 4 candle patterns and meet range conditions
      bool bullBearPatternBuy = high[i] > low[i-1] && low[i-1] > high[i-2] && high[i-2] > low[i-3] && low[i-3] > high[i-4];
      bool bullBearPatternSell = high[i] < low[i-1] && low[i-1] < high[i-2] && high[i-2] < low[i-3] && low[i-3] < high[i-4];
      
      if(range >= minRangePips && range <= maxRangePips)
      {
         BuyBuffer[i] = bullBearPatternBuy ? high[i] : EMPTY_VALUE;
         SellBuffer[i] = bullBearPatternSell ? low[i] : EMPTY_VALUE;
      }
      else
      {
         BuyBuffer[i] = EMPTY_VALUE;
         SellBuffer[i] = EMPTY_VALUE;
      }
   }
   
   return(rates_total);
}
//+------------------------------------------------------------------+

I'm learning to make a simple indicator to identify 4 bull-bear-bull-bear or bear-bull-bear-bull candles with a range of no less than 200 points and no more than 500 points and if the area has been identified it should be marked with a rectangle box.

Can you help what are the shortcomings, I try to compile it in the meta editor, there is always something missing

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2023.08.11
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 

you have not stated a problem.

Who coded this indicator?