Skip to main content

Stochastic Divergence - Positive for Amibroker (AFL)

eurosiva almost 14 years ago Amibroker (AFL)

  • Rating:
    3 / 5 (Votes 3)
  • Tags:
    oscillator, amibroker

A very simple positive stochastic divergence which does not show chart, but gives only a vertical line when there is a divergence.

I had posted the stochastic Divergence – Negative afl. This one is a positive divergence. If someone can combine together the two afls, it would be great.

Indicator / Formula

Copy & Paste Friendly
/*Positive Stochastic Divergence for use in 
Indicator Builder and Automatic Analysis (scan mode)*/

ST33=StochD(14);
TR1=LLVBars(ST33,4);
TR2=IIf(ST33<30 AND TR1>0 AND Ref(TR1,-1)==0,Ref(ST33,-1),0);
TRC=IIf(TR2>0,C,0);
vs=ValueWhen(tr2, Ref(st33,-1), 1);
dvs=vs-Ref(vs,-1);
vc=ValueWhen(trc, LLV(C,3), 1);
dvc=vc-Ref(vc,-1);
diver=IIf(dvs>0 AND dvc<0,30,0);
DAS=BarsSince(Ref(TR2,-1)>0);
DD=IIf(DAS<20 AND C>=Ref(C,-1),DIVER,0);
Graph0=TR2;
Graph0Style=2;
Graph0BarColor=12;
Graph1=dd;
Graph1BarColor=5;
Buy=DD>0 ;

1 comments

over 13 years ago
_SECTION_BEGIN("Ensign Volatility Stop");
// Ensign Volatility Stop
// get the multiple of 9 period EMA of ATR_Ensign

k=Param("multiplication factor", 1,0.5,5,0.1);
period=k*9;

VS_raw = 2.5 * EMA(ATR(1), period);

// for longs, VS line is below price

loline = VS_below_price = HHV(Close, period) - VS_raw;

// for shorts, VS line is above price

hiline = VS_above_price = LLV(Close, period) + VS_raw;

between = IIf (C < hiline AND C > loline, 1, 0);

up = IIf(C > hiline OR (H > Ref(H, -1) AND H > hiline), 1, 0);

dn = IIf(C < loline OR (L < Ref(L, -1) AND L < loline), 1, 0);

upcond = IIf(between AND BarsSince(up) < BarsSince(dn) , 1, 0);

dncond = IIf(between AND BarsSince(dn) < BarsSince(up) , 1, 0);

upline = IIf(up OR upcond, loline, Null);

dnline = IIf(dn OR dncond, hiline, Null);

Plot(C, "", colorLightGrey, styleBar);

Plot(upline, "", colorGreen, styleStaircase) ;

Plot(dnline, "", colorRed, styleStaircase) ;
Buy=upline;
Sell=dnline;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
PlotShapes(Buy*shapeUpArrow,colorGreen);
PlotShapes(Sell*shapeDownArrow,colorRed);


/**** END ****/

_SECTION_BEGIN("Background");
SetChartOptions(0,chartShowArrows|chartShowDates);
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g
(%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1
)));
}

SetChartBkColor(ParamColor("Outer panel color ",colorBlack)); // color of outer border 
SetChartBkGradientFill( ParamColor("Inner panel color upper half",colorDarkTeal),
ParamColor("Inner panel color lower half",colorBlack)//color of inner panel
,ParamColor("behind Text Color", colorRed));
_SECTION_END(); 

Leave Comment

Please login here to leave a comment.