Appearance

Personalize your experience

Mode
Accent Color
Direction
MarketplacestrategiesSlope Spectrum Trend
QuaScript

Slope Spectrum Trend

Free

Trend following once slopes are significant on most horizons

0.0(0)
0 installs 0 0 comments
Q
433 listings

The QuaTick team's QuaScript analyses, run by the native C++ engine.

View Profile
quascriptstrategyregressiontrendsignificance
Free
Backtest this strategy Open in QuaCode Edit in IDE
Version
Updated
Compatible

Live engine preview

QuaScriptQuaScript

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.

Slope Spectrum Trendengine result
Loading the engine result…
quatick-charts · QuaScript engine on synthetic 1-minute bars · drag to pan · scroll to zoom · Run executes the script on the engine (⌘/Ctrl+Enter while editing)

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
      quascript
      1strategy "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).
      15use "viz/premium" as pr
      16first = param.int(10, title = "Shortest horizon", min = 4, max = 200, group = "Spectrum")
      17gap = param.int(12, title = "Horizon step", min = 1, max = 100, group = "Spectrum")
      18t_sig = param.float(2.0, title = "Significant |t|", min = 1, max = 6, step = 0.1, group = "Spectrum")
      19enter = param.float(0.6, title = "Entry share", min = 0.1, max = 1, step = 0.05, group = "Signals")
      20leave = param.float(0.2, title = "Exit share", min = 0, max = 0.9, step = 0.05, group = "Signals")
      21ch_k = param.float(3.0, title = "Chandelier (ATR)", min = 1, max = 10, step = 0.1, group = "Exit")
      22share = 0.0
      23for 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}
      31share := share / 16
      32(long_stop, short_stop) = ta.chandelier(22, ch_k)
      33go_long = share > enter and share[1] <= enter
      34go_short = share < -enter and share[1] >= -enter
      35flat = position.size == 0
      36if flat and go_long { order.market("L", side.long) }
      37if flat and go_short { order.market("S", side.short) }
      38if position.size > 0 and (share < leave or close < long_stop[1]) { exit.close_all() }
      39if position.size < 0 and (share > -leave or close > short_stop[1]) { exit.close_all() }
      40risk.max_drawdown(25)
      41render.line(position.size > 0 ? long_stop : na, "Long stop", color = color.emerald.300, width = 1.5)
      42render.line(position.size < 0 ? short_stop : na, "Short stop", color = color.rose.300, width = 1.5)
      43render.candle_color(share > enter ? color.emerald.400 : share < -enter ? color.rose.400 : na)
      44render.mark(go_long and flat, shape = shape.triangle_up, at = anchor.below_bar, color = color.emerald.300, size = 0.8, title = "Significant up-trend")
      45render.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 
      Read-only preview. Open in QuaCode to edit and deploy.

      Reviews

      No reviews yet. Be the first to review this listing.

      Discussion

      Sign in to join the discussion. Your posts and replies show up on your profile.