Appearance
Personalize your experience
Mode
Accent Color
Direction
Regression Supertrend Trader
FreeAlways-in trading on the regression supertrend
0.0(0)
0 installs 0 0 commentsQ
quascriptstrategysupertrendregression
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.
Regression Supertrend Traderengine 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
Always-in trend trading on a supertrend that trails the regression line: long on a bull flip, short on a bear flip, with the trailing stop as the protective exit.
Settings
Regression window: 30
ATR factor: 2.5
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 IDEquascript
| 1 | strategy "Regression Supertrend Trader" { |
| 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 | /// Always-in trend trading on a supertrend that trails the regression line: long on a bull flip, |
| 11 | /// short on a bear flip, with the trailing stop as the protective exit. |
| 12 | len = param.int(30, title = "Regression window", min = 5, max = 500) |
| 13 | factor = param.float(2.5, title = "ATR factor", min = 0.5, max = 10, step = 0.1) |
| 14 | (reg, _, _) = stat.linreg(close, len, 0) |
| 15 | a = ta.atr(14) |
| 16 | persist up = na |
| 17 | persist dn = na |
| 18 | persist dir = 1 |
| 19 | up := math.is_na(up) ? reg - factor * a : reg[1] > up ? math.max(reg - factor * a, up) : reg - factor * a |
| 20 | dn := math.is_na(dn) ? reg + factor * a : reg[1] < dn ? math.min(reg + factor * a, dn) : reg + factor * a |
| 21 | if dir == 1 and reg < up { dir := -1 } |
| 22 | else if dir == -1 and reg > dn { dir := 1 } |
| 23 | stop = dir == 1 ? up : dn |
| 24 | ready = not math.is_na(stop) |
| 25 | if ready and dir == 1 and dir[1] == -1 { |
| 26 | order.market("L", side.long) |
| 27 | exit.bracket("L stop", entry = "L", stop = stop) |
| 28 | } |
| 29 | if ready and dir == -1 and dir[1] == 1 { |
| 30 | order.market("S", side.short) |
| 31 | exit.bracket("S stop", entry = "S", stop = stop) |
| 32 | } |
| 33 | risk.max_drawdown(30) |
| 34 | render.line(dir == 1 ? stop : na, "Bull stop", color = color.emerald.400, width = 2) |
| 35 | render.line(dir == -1 ? stop : na, "Bear stop", color = color.rose.400, width = 2) |
| 36 |
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.