Dear friend houmansat,
for rsi divergence number 1 will be shown on chart
for stoch divergence number 2 will be shown on chart
and for mfi divergence number 3 will be shown on chart
Note --- for calculation of MFI, volume is needed so if u dont have volume data , MFI wont be shown
here is the code
for rsi divergence number 1 will be shown on chart
for stoch divergence number 2 will be shown on chart
and for mfi divergence number 3 will be shown on chart
Note --- for calculation of MFI, volume is needed so if u dont have volume data , MFI wont be shown
here is the code
Code:
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
Buy=Sell=Cover=Short=0;
mfip=Param("MFI period",14,5,100,1);
rsip=Param("RSI period",14,5,100,1);
stochp=Param("Stoch period",14,5,100,1);
n=Param("Divergence Distance RSI",20,0,100,1);
Buy1=Sell1=0;
Var = Zig(RSI(rsip), n);
t= Trough(RSI(rsip), n, 1);
p= Peak(RSI(rsip), n, 1);
for ( i=0; i<BarCount; i++)
{
if (i ==0)
{
x[0] =Var[0];
price[0] = C[0];
j=0;
}
if(Var[i] == p[i])
{
j++;
x[j] =Var[i];
price[j] =C[i];
if(x[j] <x[j-1] && price[j-1]< price[j])
Sell1[i] =1;
}
}
for ( i=0; i<BarCount; i++)
{
if (i ==0)
{
x[0] =Var[0];
price[0] = C[0];
j=0;
}
if(Var[i] == t[i])
{
j++;
x[j] =Var[i];
price[j] =C[i];
if(x[j] >x[j-1] && price[j]<price[j-1])
Buy1[i] =1;
}
}
PlotShapes ( IIf(Sell1, shapeDigit1, shapeNone), colorRed,0,H,12);
PlotShapes( IIf(Buy1, shapeDigit1, shapeNone), colorBrightGreen,0,L,-12);
ST33=StochD(stochp);
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);
Buy2=DD>0 ;
ST33=StochD(stochp);
TR11=HHVBars(ST33,4);
TR21=IIf(ST33>70 AND TR11>0 AND Ref(TR11,-1)==0,Ref(ST33,-1),0);
TRC1=IIf(TR21>0,C,0);
vs1=ValueWhen(tr21, Ref(st33,-1), 1);
dvs1=vs1-Ref(vs1,-1);
vc1=ValueWhen(trc1, HHV(H,3), 1);
dvc1=vc1-Ref(vc1,-1);
diver1=IIf(dvs1<0 AND dvc1>0,90,0);
DAS1=BarsSince(Ref(TR21,-1)>0);
ddd1=IIf(DAS1<20 AND C<Ref(C,-1),DIVER1,0);
Sell2=ddd1==90;
PlotShapes( IIf(Buy2, shapeDigit2, shapeNone), colorBrightGreen,0,L,-12);
PlotShapes ( IIf(Sell2, shapeDigit2, shapeNone), colorRed,0,H,12);
f=Param("Divergence Distance MFI",20,0,100,1);
Buy3=Sell3=0;
Varf = Zig(MFI(mfip), f);
tf= Trough(MFI(mfip), f, 1);
pf= Peak(MFI(mfip), f, 1);
for ( i=0; i<BarCount; i++)
{
if (i ==0)
{
x[0] =Varf[0];
price[0] = C[0];
j=0;
}
if(Varf[i] == pf[i])
{
j++;
x[j] =Varf[i];
price[j] =C[i];
if(x[j] <x[j-1] && price[j-1]< price[j])
Sell3[i] =1;
}
}
for ( i=0; i<BarCount; i++)
{
if (i ==0)
{
x[0] =Varf[0];
price[0] = C[0];
j=0;
}
if(Varf[i] == tf[i])
{
j++;
x[j] =Varf[i];
price[j] =C[i];
if(x[j] >x[j-1] && price[j]<price[j-1])
Buy3[i] =1;
}
}
PlotShapes ( IIf(Sell3, shapeDigit3, shapeNone), colorRed,0,H,12);
PlotShapes( IIf(Buy3, shapeDigit3, shapeNone), colorBrightGreen,0,L,-12);
Last edited: