• Australian (ASX) Stock Market Forum

# AFL stoch, macd, overbought

Discussion in 'Trading Strategies/Systems' started by colokit, Jun 30, 2018.

1. ### colokit

Posts:
1
0
Joined:
Jun 29, 2018
1. StochK<30=>checking stoch crossup and macd crossup=>buy
2. if line of stoch and line of macd cross up from 30 to 50 in range=>buy
3. if next bar or next few bar can't crossup over 50 and drop down below 30=>sell
4. if stoch crossdown and macd crossdown StochK>70=>sell
I coded as below and ran it in amibroker. The result was wrong.
I dont know where i coded wrong.

I would appreciate some assistance.

Thanks.
Tim

r1 = Param( "Macd Fast avg", 12, 2, 200, 1 );
r2 = Param( "Macd Slow avg", 26, 2, 200, 1 );
r3 = Param( "Macd Signal avg", 9, 2, 200, 1 );
myMacd = MACD(r1,r2);
mySignal = Signal(r1,r2,r3);
crossUpMACD = Cross( MACD(), Signal() );
crossDownMACD = Cross( Signal(), MACD() );
upMacd = IIf(myMacd > mySignal, 1, 0);
sk=StochK(10,5);
sd=StochD(10,5,3);
uptrend= IIf( StochK(10,5) > StochD(10,5,3), 1, 0 );
downtrend=IIf( StochK(10,5)<StochD(10,5,3), 1, 0 ); crossBuy=Cross(StochK(10,5),StochD(10,5,3)); crossSell=Cross(StochD(10,5,3),StochK(10,5));
for(i=0;i<BarCount;i++){
if(i>1){
if(sk <=30){
bottomPos=1;
bmiddlePos=0;
bmiddlePos=0;
topPos=0;
if ((myMacd > mySignal) AND (sk>sd)){
}
actionSell=1;
bmiddlePos=0;
}
}
if(sk >31 && sk <=50){
if (bottomPos){
bmiddlePos=1;
if ((myMacd > mySignal) AND (sk[i]>sd[i])){
}
}
}else if(tmiddlePos[i]){
bottomPos[i]=0;
bmiddlePos[i]=0;
tmiddlePos[i]=0;
topPos[i]=0;
}
}
if(sk[i] >50 && sk[i] <=70){
if (topPos[i]){
tmiddlePos[i]=1;
}else if(tmiddlePos[i]){
bottomPos[i]=0;
bmiddlePos[i]=0;
tmiddlePos[i]=0;
topPos[i]=0;
}
}
if(stochasticK[i] >70){
bottomPos[i]=0;
bmiddlePos[i]=0;
tmiddlePos[i]=0;
topPos[i]=1;
if ((myMacd[i] < mySignal[i]) AND (sk[i]<sd[i])){
actionSell[i]=1;
}
}
}
}