Simple Coding Help - No Promise.

Romeo1998

Well-Known Member
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 :happy: so if u dont have volume data , MFI wont be shown :happy:
here is the code :happy:
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);
:happy:
 
Last edited:

Romeo1998

Well-Known Member
Dear friend ocil,
I am not able to understand clearly :( or maybe i m just too tired :D

if u want to buy when current price of stock is above yesterday's high, nifty is in plus and current price of stock is ABOVE its pivot,
then buy will be triggered for all the candles satisfying these conditions
for that use this code :happy:
Code:
Buy = COVER = C > H1 AND symbolplus AND C>pv;
Short = Sell = C < L1 AND symbolminus AND C<pv;
if u want to buy when current price of stock is above yesterday's high, nifty is in plus and current price of stock CROSSES its pivot,
then this buy will be triggered only for those candles when current price of stock CROSSES the pivot and satisfies the other buy conditions too
for that use this code :happy:
Code:
Buy = COVER = C > H1 AND symbolplus AND Cross(C,pv);
Short = Sell = C < L1 AND symbolminus AND Cross(pv,C);
Have attached 2 pics for better understanding :happy:
pic 1 -- sell is triggered when current price is below yesterday's low
pic 2 -- sell is triggered when current price crosses below yesterday's low
:happy:
 

Attachments

Last edited:
Dear friend Loveenajyothi,
i m not VijKrish gaaru :happy:
i searched in google abt Kase Peak Oscillator and found it here :pompus:
http://www.wisestocktrader.com/indicators/4317-kase-peak-osc-v2-batu
i hope this helps :happy:
Code:
_SECTION_BEGIN("Kase Peak Osc Orginal V2.batu");
Per1=Param("Max Length",55,2,200,1);
Per2=Param("Min Length",13,2,200,1);
RWH=RWIHi(Per2,Per1);
RWL=RWILo(Per2,Per1);
Pk=WMA((RWH-RWL),3);
MN=MA(Pk,Per1);
SD=StDev(Pk,Per1);
Val1=Max(MN+(2*SD),2.2*SD);
Val2=Min(MN-(2*SD),-2.2*SD);
Val3=Max(MN+(2*SD),3*SD);
Val4=Min(MN-(2*SD),-3*SD);
LN1=IIf(PK>=0,Val1,Val2);
LN2=IIf(PK>=0,Val3,Val4);
Red=IIf(Ref(Pk,-1)>Pk,Pk,0);
Green=IIf(Pk>Ref(Pk,-1),Pk,0);

WriteIf( Val2>=Pk, "Buraya yazabilirsin", "Buraya yaziliyor" );

Buy= IIf(Pk<Val2,Val2>=Pk-0.01,Val2>=Pk);
Sell= IIf(Pk>Val1,Pk+0.01>=Val1,Pk>=Val1);

for( i = 0; i < BarCount; i++ )
 {
if( Buy[i] ) PlotText( "Pk<" + Val2[ i ], i, Pk[ i ]-2, colorGreen,colorWhite);
if( Sell[i] ) PlotText( "Pk>" + Val1[ i ], i, Pk[ i ]+2, colorRed,colorWhite);
  }

PlotShapes( Buy *18,IIf( Buy, colorGreen, colorRed ),0,0);
PlotShapes(Sell * 17, IIf( Buy, colorGreen, colorRed ),0,0);

Buy= IIf(Pk<Val4,Val4>=Pk-0.01,Val4>=Pk);
Sell= IIf(Pk>Val3,Pk+0.01>=Val3,Pk>=Val3);
Plot(Red,"Red min "+per2+"-max "+per1,IIf(Buy,11,colorOrange),styleHistogram|styleThick,Null,Null,0,1);
Plot(Green,"Green min"+per2+"-max "+per1,IIf(Sell,11,colorGreen),styleHistogram|styleThick,Null,Null,0,1);
Plot(LN1,"StDev Loc",colorViolet,styleLine);
Plot(ln2,"StDev GL",colorTurquoise,styleLine);
_SECTION_END();
thank u for helping me earlier :happy:
:happy:
Dear friend VijKrish gaaru, (Ya , I know),
Do you have anything new , not 6 years old AFL for Amibroker 6.26
 

ocil

Well-Known Member
Dear Romeo,
My fault if u have not understand. Let me try again.
1) Only Buy when the first candle closed green above pivot and nifty also green and price brk yesterday high.
2) Only Short when the first candle closed red below pivot and nifty also Red and price brk yesterday low.

Q is how to check day first candle it should green and closed above pivot
Q is how to check day first candle it should red and closed below pivot.

Thanks again for the time and effort.


Dear friend ocil,
I am not able to understand clearly :( or maybe i m just too tired :D

if u want to buy when current price of stock is above yesterday's high, nifty is in plus and current price of stock is ABOVE its pivot,
then buy will be triggered for all the candles satisfying these conditions
for that use this code :happy:
Code:
Buy = COVER = C > H1 AND symbolplus AND C>pv;
Short = Sell = C < L1 AND symbolminus AND C<pv;
if u want to buy when current price of stock is above yesterday's high, nifty is in plus and current price of stock CROSSES its pivot,
then this buy will be triggered only for those candles when current price of stock CROSSES the pivot and satisfies the other buy conditions too
for that use this code :happy:
Code:
Buy = COVER = C > H1 AND symbolplus AND Cross(C,pv);
Short = Sell = C < L1 AND symbolminus AND Cross(pv,C);
Have attached 2 pics for better understanding :happy:
pic 1 -- sell is triggered when current price is below yesterday's low
pic 2 -- sell is triggered when current price crosses below yesterday's low
:happy:
 

Romeo1998

Well-Known Member
Dear friend ocil,
finally i have understood ur question :happy:
here is the required code :happy:
Code:
// first candle in intraday timeframe
dn = DateNum();
newday = dn != Ref( dn, -1 );

// first candle's close
f1 = ValueWhen( newday, C );

// PV's value for first candle
p1 = ValueWhen( newday, PV );

Buy = COVER = C > H1  AND symbolplus AND f1 > p1;
Short = Sell = C < L1 AND symbolminus AND f1 < p1;
:happy:
 
Last edited:

Similar threads