If I may suggest something, the colors of histogram are changing. I mean are changing on history. When u load it again, u can see difrent colors. That is of course becouse of optimalization. If u use restriction to some of bars like count 300 last bars or 1000 last bars, the indicator will not lag much, and will refresh every bar after each tick.
That's just my few pips
Just change this lines:
int limit;
int counted_bars=IndicatorCounted();
double prev,current,cur,pre;
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
Like that:
int limit = 500;
//int counted_bars=IndicatorCounted();
double prev,current,cur,pre;
//if(counted_bars>0) counted_bars--;
//limit=Bars-counted_bars;