//+------------------------------------------------------------------+
//|                                                                  |
//|                                                                  |
//|                         Based upon Kiosotto Kilian19@FF          |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 clrRed
#property indicator_color2 clrGreen
#property indicator_width1 2
#property indicator_width2 2

extern int       dev_period = 150;
extern int       bars       = 1000;

double ExtMapBuffer1[];
double ExtMapBuffer2[];


int init()
  {
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexLabel(0,"SELL");

   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexLabel(1,"Buy");   
   return(0);
  }

int start()
  {
   int limit = Bars-IndicatorCounted();
   
   if (limit > bars)  limit=bars;
   
   for(int i = limit; i >= 0; i--) {
      double TSBUL = 0;
      double TSBER = 0;
      
      double globalHigh =0;
      double globalLow = 9999999;
      
      for(int j = 0; j<dev_period; j++)   
      {
         int shift=i+j; 
         double rsi = iRSI(Symbol(),0,dev_period,PRICE_CLOSE,shift);
         double high = iHigh(Symbol(), Period(), shift);
         double low = iLow(Symbol(), Period(), shift);
         double close = iClose(Symbol(), Period(), shift);                
         
         double power = rsi * close;
         
         if (high > globalHigh)
         {
            globalHigh = high;
            TSBUL += power;
         }
         
         if (low < globalLow)
         {
            globalLow = low;
            TSBER += power;
         }              
      }

      ExtMapBuffer1[i] = TSBER/TSBUL;
      ExtMapBuffer2[i] = TSBUL/TSBER;       
    }
    
    return(0);
}