#property indicator_separate_window
#property indicator_maximum 55
#property indicator_minimum -55
#property indicator_buffers 1
#property indicator_color1 White
#property indicator_levelstyle 0;
#property indicator_level1 25
#property indicator_level2 0
#property indicator_level3 -25
#property indicator_levelcolor 2631703

enum Prise{H_L,O_C};
enum eco{off,        // On every tick.
         eco_open,   // Only when opening
         eco_1min,
         eco_1sec,
         hybrid_hl}; // Only when the price goes beyond the limits, and at the opening

input Prise          Prise_base = H_L;
input ENUM_MA_METHOD ma_mode_pr = MODE_LWMA;
input ENUM_MA_METHOD ma_mode_1  = MODE_LWMA;
input ENUM_MA_METHOD ma_mode_2  = MODE_LWMA;
input int            pre_smooth = 7;
input int            avg_len    = 7;
input int            smooth     = 3;
input eco            eco_mode   = eco_1min;
input int            limit_bars = 0;

double hi=0,lo=0;
datetime time0,time1,time2;

double B_h[],B_l[];
double Bnet_1[],Bh_1[],Bl_1[],Bbull_1[],Bbear_1[],Bbulls_1[],Bbears_1[],Bnet0_1[];

int init(){
   IndicatorBuffers(10);
   SetIndexBuffer(0,Bnet_1);
   SetIndexBuffer(1,Bbulls_1);
   SetIndexBuffer(2,Bbears_1);
   SetIndexBuffer(3,Bbull_1);
   SetIndexBuffer(4,Bbear_1);
   SetIndexBuffer(5,Bnet0_1);
   SetIndexBuffer(6,Bh_1);
   SetIndexBuffer(7,Bl_1);
   SetIndexBuffer(8,B_h);
   SetIndexBuffer(9,B_l);
   IndicatorShortName(NULL);
 return(0);
}

int start(){int t0=1;
            if(Bnet_1[0]==EMPTY_VALUE || Bnet_1[1]==EMPTY_VALUE || Bnet_1[2]==EMPTY_VALUE){time0=-1; time1=-1; time2=-1;}
            if(eco_mode==eco_open){if(time0==Time[0]){return(0);}else{time0=Time[0]; t0=0;}}else
            if(eco_mode==eco_1min){if(time2==Minute()){return(0);}else{time2=Minute(); if(time0!=Time[0]){time0=Time[0]; t0=0;}}}else
            if(eco_mode==eco_1sec){if(time2==Minute() && time1==Seconds()){return(0);}else{time2=Minute(); time1=Seconds(); if(time0!=Time[0]){time0=Time[0]; t0=0;}}}else
            if(eco_mode==hybrid_hl){if(hi==High[0] && lo==Low[0] && time0==Time[0]){return(0);}else{hi=High[0]; lo=Low[0]; if(time0!=Time[0]){time0=Time[0]; t0=0;}}}

int i,limit=Bars-IndicatorCounted()-t0; if(limit_bars>0){if(limit>limit_bars){limit=limit_bars;}}

   double R,hiup,loup,hidn,lodn,test_value1;

   for(i=limit;i>=0;i--){if(Prise_base==H_L){B_h[i]=High[i]; B_l[i]=Low[i];}
                         if(Prise_base==O_C){B_h[i]=MathMax(Open[i],Close[i]); B_l[i]=MathMin(Open[i],Close[i]);}}

   for(i=limit;i>=0;i--){Bh_1[i]=iMAOnArray(B_h,0,pre_smooth,0,ma_mode_pr,i);
                         Bl_1[i]=iMAOnArray(B_l,0,pre_smooth,0,ma_mode_pr,i);}

   for(i=limit;i>=0;i--){
      R=(Bh_1[ArrayMaximum(Bh_1,2,i)]-Bl_1[ArrayMinimum(Bl_1,2,i)]);

      hiup=MathMax(Bh_1[i]-Bh_1[i+1],0);
      loup=MathMax(Bl_1[i]-Bl_1[i+1],0);
      test_value1=(hiup+loup);
      if(test_value1==0 || R==0){Bbulls_1[i]=0;}
      else                       Bbulls_1[i]=MathMin((test_value1)/R,1)*100;

      hidn=MathMin(Bh_1[i]-Bh_1[i+1],0);
      lodn=MathMin(Bl_1[i]-Bl_1[i+1],0);
      test_value1=(hidn+lodn);
      if(test_value1==0 || R==0){Bbears_1[i]=0;}
      else                       Bbears_1[i]=MathMax((test_value1)/R,-1)*-100;}

   for(i=limit;i>=0;i--){Bbear_1[i]=iMAOnArray(Bbears_1,0,avg_len,0,ma_mode_1,i);
                         Bbull_1[i]=iMAOnArray(Bbulls_1,0,avg_len,0,ma_mode_1,i);}

   for(i=limit;i>=0;i--){Bnet0_1[i]=Bbull_1[i]-Bbear_1[i];}

   for(i=limit;i>=0;i--){Bnet_1[i]=iMAOnArray(Bnet0_1,0,smooth,0,ma_mode_2,i);}

 return(0);
}