AFL stoch, macd, overbought

- StochK<30=>checking stoch crossup and macd crossup=>buy
- if line of stoch and line of macd cross up from 30 to 50 in range=>buy
- if next bar or next few bar can't crossup over 50 and drop down below 30=>sell
- 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[i] <=30){
bottomPos[i]=1;
bmiddlePos[i]=0;
bmiddlePos[i]=0;
topPos[i]=0;
if ((myMacd[i] > mySignal[i]) AND (sk[i]>sd[i])){
actionBuy[i]=1;
}
if(actionBuy[i] AND bmiddlePos[i]){
actionSell[i]=1;
bmiddlePos[i]=0;
}
}
if(sk[i] >31 && sk[i] <=50){
if (bottomPos[i]){
bmiddlePos[i]=1;
if ((myMacd[i] > mySignal[i]) AND (sk[i]>sd[i])){
actionBuy[i]=1;
}
}
}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;
}
}
}
}
Buy = actionBuy ;
Sell = actionSell;
Buy=ExRem(Buy, Sell)
Sell=ExRem(Sell,Buy);
```