//+------------------------------------------------------------------+
//|                                                   Inside Bar.mq5 |
//|                                    Copyright @ 2022, Billyenaire |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright @ 2022, Billyenaire"    
#property version   "1.20"
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots 4
#property indicator_type1 DRAW_CANDLES
#property indicator_style1 STYLE_SOLID
#property indicator_color1 clrBlack, clrDarkGray
#property indicator_width1 1
//--- indicator buffers
double H[];
double L[];
double O[];
double C[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0, O, INDICATOR_DATA);
   SetIndexBuffer(1, H, INDICATOR_DATA);
   SetIndexBuffer(2, L, INDICATOR_DATA);
   SetIndexBuffer(3, C, INDICATOR_DATA);
   ArraySetAsSeries(O, true);
   ArraySetAsSeries(H, true);
   ArraySetAsSeries(L, true);
   ArraySetAsSeries(C, true);
  }
//+------------------------------------------------------------------+
//|  Inside Bar                                                      |
//+------------------------------------------------------------------+
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[])
  {
   
   if(rates_total-prev_calculated<=0) 
      return(0);
   
   int limit=0;
   
   if(prev_calculated==0 || rates_total-prev_calculated>1){
      ArraySetAsSeries(open, true);
      ArraySetAsSeries(high, true);
      ArraySetAsSeries(low, true);
      ArraySetAsSeries(close, true);
      limit=rates_total-2;
      }
      
   for(int i=limit; i>=1; i--){
      if(high[i]<high[i+1] && low[i]>low[i+1]){
         H[i] = high[i];
         L[i] = low[i];
         O[i] = open[i];
         C[i] = close[i];
      }
      else{
         H[i] = EMPTY_VALUE;
         L[i] = EMPTY_VALUE;
         O[i] = EMPTY_VALUE;
         C[i] = EMPTY_VALUE;
         }
    }
         H[0] = EMPTY_VALUE;
         L[0] = EMPTY_VALUE;
         O[0] = EMPTY_VALUE;
         C[0] = EMPTY_VALUE;
   return(rates_total-1);
 }
//+------------------------------------------------------------------+---------+
