5-8-13 moving crossover

Need a code to generate Buy and Sell signals/alerts for the 5 period moving average crossing over (both from above and below) the 8 period & 13 period moving average. All the average types are Simple moving averages.

For the above given condition

Buy Script:

CROSSOVER(EMA(CLOSE,5),EMA(CLOSE,8)) AND CROSSOVER(EMA(CLOSE,5),EMA(CLOSE,13))

Sell Script:

CROSSOVER(EMA(CLOSE,8),EMA(CLOSE,5)) AND CROSSOVER(EMA(CLOSE,13),EMA(CLOSE,5))
1 Like

hello trader,

For Better Results, us this tradescript code

BUY SCRIPT:

SMA(CLOSE,8) > SMA(CLOSE,13) AND 
SMA(CLOSE,5) > SMA(CLOSE,8) 

SELL SCRIPT:

SMA(CLOSE,8) < SMA(CLOSE,13) AND 
SMA(CLOSE,5) < SMA(CLOSE,8) 

Thank you for the code(s)…I am kind of a newbie…so what percentage of success should one look while back testing strategies?
For example, using the above code(s), i could find more trades on losing side than on the winning side (almost double losing trades)

If you find there are more losing sides than winning sides, then you have to take a closer look at your strategy (whether it is flawed) not the algo. If trading was so straight forward, then everyone who can write a code would have made millions in the market.

Moreover, EMA gives the right picture than SMA, EMA accounts for the more latest prices and gives lesser weights to the earlier prices, which makes it a better leading indicator. You can find more on Zerodha/Varsity.

Good Luck!

where to copy paste code and see the results?

Hi,

Please see below testing results. Looks really weird. Signals are quite erratic, Ratio of winning to losing trades is great, but the Profit percentage is negative.

It appears that you have chosen a scrip which is traveling sideways. Did you test it on any other trending stocks and bigger timelines?

Yes, tired it on other stocks as well. I am switiching back to my old strategy. Parabolic SAR with MACD crossover.