MACD with a market filter
MACD crossovers below zero, taken only while the market itself is in an uptrend: the stock turns up after a dip in a rising market. Exit on the opposite cross or when the market filter switches off.
Strategies · macd_regime.rvw
language 1
strategy "MACD with a market filter" {
universe members("SYN500")
regime close("SYNSPY") > sma(close("SYNSPY"), 200)
line macd_line(close, 12, 26, 9)
sig macd_signal(close, 12, 26, 9)
enter long when regime and crosses_above(line, sig) and line < 0
exit when crosses_below(line, sig) or not regime
rank by -line / close
size 5% of equity, max 15 positions
}
Functions it uses
sma, macd_line, macd_signal, crosses_above, crosses_below
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?