Appearance
Personalize your experience
Slope Spectrum Trend
FreeTrend following once slopes are significant on most horizons
Live engine preview
The QuaScript engine's own output on the chart the terminal uses. Change the settings or edit the code and press Run to recompute it.
About
Trend following that waits until the trend is statistically real on most horizons. Sixteen regression slopes (from short to long) are tested with their t-statistics; the strategy goes long when the share of significantly rising horizons crosses the entry level and short on the mirror condition. A chandelier stop trails the position, and the trade ends when the share falls back below the exit level (the trend is no longer significant).
Settings
Shortest horizon: 10
Horizon step: 12
Significant |t|: 2
Entry share: 0.6
Exit share: 0.2
Chandelier (ATR): 3
Backtest it yourself
Open it on the backtesting page to run it on any symbol, interval and date range, then use Monte Carlo, optimisation, walk-forward and robustness tests.
Strategy Rules
Entry Conditions
Exit Conditions
Source Code
Edit in IDE| 1 | strategy "Slope Spectrum Trend" { |
| 2 | overlay = true |
| 3 | capital = 100000 |
| 4 | commission = 0.05 |
| 5 | slippage = 1 |
| 6 | sizing = risk_percent |
| 7 | size = 1 |
| 8 | max_leverage = 1 |
| 9 | } |
| 10 | /// Trend following that waits until the trend is statistically real on most horizons. Sixteen |
| 11 | /// regression slopes (from short to long) are tested with their t-statistics; the strategy goes |
| 12 | /// long when the share of significantly rising horizons crosses the entry level and short on the |
| 13 | /// mirror condition. A chandelier stop trails the position, and the trade ends when the share |
| 14 | /// falls back below the exit level (the trend is no longer significant). |
| 15 | use "viz/premium" as pr |
| 16 | first = param.int(10, title = "Shortest horizon", min = 4, max = 200, group = "Spectrum") |
| 17 | gap = param.int(12, title = "Horizon step", min = 1, max = 100, group = "Spectrum") |
| 18 | t_sig = param.float(2.0, title = "Significant |t|", min = 1, max = 6, step = 0.1, group = "Spectrum") |
| 19 | enter = param.float(0.6, title = "Entry share", min = 0.1, max = 1, step = 0.05, group = "Signals") |
| 20 | leave = param.float(0.2, title = "Exit share", min = 0, max = 0.9, step = 0.05, group = "Signals") |
| 21 | ch_k = param.float(3.0, title = "Chandelier (ATR)", min = 1, max = 10, step = 0.1, group = "Exit") |
| 22 | share = 0.0 |
| 23 | for k in 0..=15 { |
| 24 | len = first + k * gap |
| 25 | (v, s, _) = stat.linreg(close, len, 0) |
| 26 | sd = stat.stdev(close - v, len) |
| 27 | sxx = len * (len * len - 1) / 12 |
| 28 | tt = s / math.max(sd / math.sqrt(sxx), 1e-12) |
| 29 | share := share + (tt > t_sig ? 1 : tt < -t_sig ? -1 : 0) |
| 30 | } |
| 31 | share := share / 16 |
| 32 | (long_stop, short_stop) = ta.chandelier(22, ch_k) |
| 33 | go_long = share > enter and share[1] <= enter |
| 34 | go_short = share < -enter and share[1] >= -enter |
| 35 | flat = position.size == 0 |
| 36 | if flat and go_long { order.market("L", side.long) } |
| 37 | if flat and go_short { order.market("S", side.short) } |
| 38 | if position.size > 0 and (share < leave or close < long_stop[1]) { exit.close_all() } |
| 39 | if position.size < 0 and (share > -leave or close > short_stop[1]) { exit.close_all() } |
| 40 | risk.max_drawdown(25) |
| 41 | render.line(position.size > 0 ? long_stop : na, "Long stop", color = color.emerald.300, width = 1.5) |
| 42 | render.line(position.size < 0 ? short_stop : na, "Short stop", color = color.rose.300, width = 1.5) |
| 43 | render.candle_color(share > enter ? color.emerald.400 : share < -enter ? color.rose.400 : na) |
| 44 | render.mark(go_long and flat, shape = shape.triangle_up, at = anchor.below_bar, color = color.emerald.300, size = 0.8, title = "Significant up-trend") |
| 45 | render.mark(go_short and flat, shape = shape.triangle_down, at = anchor.above_bar, color = color.rose.300, size = 0.8, title = "Significant down-trend") |
| 46 |
Reviews
No reviews yet. Be the first to review this listing.