var: ema5, ema20, ema150, l5, h5;
Var: Stop1, Stop2, StopLong, StopShort, PREV, Chandelier(0),OscAtr3, OscAtr25;
Var: contahl,prox0,indzona1,pp,llow,hhigh,aa, bb,expoa,expob,dd,indzona2;
ema5=mov(c,5,e);
ema20=mov(c,20,e);
ema150=mov(c,150,e);
h5=h[5];
l5=l[5];
OscAtr3 = ATR(C, 10) * 3;
OscAtr25 = ATR(C, 10) *2.5;
PREV = Chandelier[1];
if PREV < L THEN
if (H - OscAtr3) >= PREV then
Stop1 = H - OscAtr3;
else
Stop1 = PREV;
endif;
else
Stop1 = H - OscAtr3;
endif;
if PREV < l then
if (C - OscAtr25) >= PREV then
Stop2 = C - OscAtr25;
else
Stop2 = prev;
endif;
else
Stop2 = C - OscAtr25;
endif;
If Stop1 > Stop2 then
StopLong = Stop1;
else
StopLong = Stop2;
endif;
if PREV > H then
if (L + OscAtr3) <= PREV then
Stop1 = L + OscAtr3;
else
Stop1 = PREV;
endif;
else
Stop1 = L + OscAtr3;
endif;
if (PREV > H) then
if (C + OscAtr25) <= PREV then
Stop2 = C + OscAtr25;
else
Stop2 = PREV;
endif;
else
Stop2 = C + OscAtr25;
endif;
If Stop1 < Stop2 then
StopShort = Stop1;
else
StopShort = Stop2;
endif;
if BarSince(L > StopLong[1]) > BarSince(H < StopShort[1]) then
Chandelier = StopLong;
else
Chandelier = StopShort;
endif;
///////////////////////////////////// DD /////////////////////////////////////////
pp=14;
llow=LLV(L,pp);
hhigh=HHV(H,pp);
aa=((3*close - 2*llow -open[1] ) / close)*100;
bb=((open[1] + 2*hhigh - 3*close)/close)*100;
expoa=(aa-expoa[1])*(2/(5*pp+1))+expoa[1];
expob=(bb-expob[1])*(2/(5*pp+1))+expob[1];
dd=expoa-expob;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if h>h[1] then contahl=(contahl+1);endif;
if l<l[1] then contahl=(contahl-1);endif;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if isfirstbarday then contahl = 0;endif;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
prox0=0.0000000001;
PlotChart(Chandelier, 0, yellow, solid, 2);
Indzona1=CreateViewport(300,0,true);
PlotChart(contahl,INDZONA1,black,solid,2 );
PlotChart(prox0,INDZONA1,black,dot,2);
indzona2=CreateViewport(200, 0, true);
Plotchart(dd,indzona2, blue, istogramma, 2);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if c > chandelier and c > ema150 and ema5 > ema20 and c < h5 then enterlong(nextbar,atopen);
endif;
if c < chandelier and c < ema150 and ema5 < ema20 and c > l5 then entershort(nextbar,atopen);
endif;