Moving-average cross
Trend following with two moving averages: own a stock while its fast average is above its slow one, and step aside when it crosses back below. New crosses compete on six-month momentum. Expect few trades and long holds, and whipsaws when a market goes sideways.
Strategies · sma_cross_trend.rvw
language 1
strategy "Moving-average cross" {
universe members("SYN500")
fast_ma sma(close, fast)
slow_ma sma(close, slow)
enter long when crosses_above(fast_ma, slow_ma)
exit when crosses_below(fast_ma, slow_ma)
rank by roc(close, 126)
size 5% of equity, max 20 positions
param fast = 50 in 20..80 step 10
param slow = 200 in 150..250 step 50
}
Functions it uses
sma, crosses_above, crosses_below, roc
Try it
File ▸ New Script from Example adds it to a project. The examples read the sample’s index label, SYN500, and market ETF, SYNSPY; when your data has neither, a sheet asks what to read instead, one of your index labels (or every stock and ETF) and a ticker, so the example runs on your data as it is.
Before you trust what it does on your data, see whether it’s luck: Is this result luck?