#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
double buffer1[];
double buffer2[];
extern int period=20;
extern int price=1; // 0 or other=(H+L)/2
					// 1=Open
					// 2=Close
					// 3=High
					// 4=Low
					// 5=(H+L+C)/3
					// 6=(O+C+H+L)/4
					// 7=(O+C)/2
//---
int init()
{
	SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2,Lime);
	SetIndexBuffer(0,buffer1);
	SetIndexLabel(0,"Buy");
	SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2,Red);
	SetIndexBuffer(1,buffer2);
	SetIndexLabel(1,"Sell");
	return(0);
}
//---
int deinit()
{
	return(0);
}
//---
double Value=0,Value1=0,Value2=0,hbs=0,hbs1=0,hbs2=0;
int buy=0,sell=0;

int start()
{
	int i;
	int barras;
	double _price;
	double MinL=0;
	double MaxH=0;
	double Threshold=1.2;

	barras=Bars;
	i=0;
	while(i<barras)
	{
	MaxH=High[Highest(NULL,0,MODE_HIGH,period,i)];
	MinL=Low[Lowest(NULL,0,MODE_LOW,period,i)];

	switch (price)
	{
	case 1: _price=Open[i]; break;
	case 2: _price=Close[i]; break;
	case 3: _price=High[i]; break;
	case 4: _price=Low[i]; break;
	case 5: _price=(High[i]+Low[i]+Close[i])/3; break;
	case 6: _price=(Open[i]+High[i]+Low[i]+Close[i])/4; break;
	case 7: _price=(Open[i]+Close[i])/2; break;
	default: _price=(High[i]+Low[i])/2; break;
	}

	Value=0.33*2*((_price-MinL)/(MaxH-MinL)-0.5) + 0.67*Value1;
	Value=MathMin(MathMax(Value,-0.999),0.999);
	hbs=0.5*MathLog((1+Value)/(1-Value))+0.5*hbs1;

	buffer1[i]=0;
	buffer2[i]=0;

	if (hbs>=0)
	{
	buffer1[i]=hbs;
	}
	else
	{
	buffer2[i]=hbs;
	}

	Value1=Value;
	hbs2=hbs1;
	hbs1=hbs;

	i++;
	}
	return(0);
}
//---