OPEN-SOURCE SCRIPT
DOUBLE SUPERTREND PYRAMID STRATEGY

Double Supertrend Pyramid Strategy
This strategy trades off two Supertrend indicators calculated on independent, user-selected timeframes (defaults: 1-minute and 2-minute). A trade is only taken when both Supertrends agree on direction — when they align upward, the strategy goes long; when they align downward, it goes short. Each new alignment is treated as a new "plotted course," and the strategy tracks that course's direction so it doesn't re-enter on every bar, only on an actual flip.
Core Entry Logic
Long/Short/Both direction control, so you can restrict the strategy to one side of the market if desired.
A session time-window filter (with a timezone dropdown covering major global zones) lets you restrict trading to specific hours, with an option to auto-close everything when the window ends.
On a Supertrend flip, the strategy normally waits until the position is completely flat before entering the new direction — it does not force-close open tiered or pyramid contracts just because the trend flipped. (See "Exit At Next Supertrend Plotted Course" below for the opt-in alternative.)
Tiered Exit System
Three independent, fully self-contained profit-scaling tiers (Tier 1/2/3), each with:
A profit target (ticks) and contract quantity to scale out at that target
An optional Stop Loss, and an optional Trailing Stop with a separate activation threshold (ticks, own enable checkbox)
An "Exit At Next Supertrend Plotted Course" checkbox — when checked, that tier's contracts are force-closed the moment the trend flips; when unchecked (default), the tier runs entirely on its own Target/Stop/Trailing settings regardless of what the trend does next.
Pyramid Add-On System
Eight independent pyramid types can each be enabled separately to add contracts in the direction of an existing position when their own specific condition fires:
Turtle ATR Unit — adds every time price moves a set fraction of ATR in your favor from the last fill.
Swing Structure — adds on a new confirmed swing high/low in the trend direction.
Momentum Re-confirmation — adds when ADX is rising with DI+/DI- agreement and RSI holds past a threshold.
Breakout / Consolidation — adds on a fresh Donchian channel breakout.
Multi-Timeframe Alignment — adds only when a higher-timeframe EMA filter agrees with the trade direction.
Error-Function One-Tailed Test — adds when the current bar's move is statistically significant versus its recent return distribution (Normal or Student-T approximation).
KDE Percentile — adds when the current move ranks in the top percentile of a non-parametric kernel-density estimate of recent returns.
Viterbi Regime Detection — adds only while a 2-state Hidden Markov Model infers the market is in a "trending" (versus "ranging") regime.
Each pyramid type is fully self-contained: its own contracts-per-signal size, its own optional TP/SL/Trailing Stop, its own per-course contract and signal caps, a delay-between-signals timer, a minimum-distance-before-next-add gate (selectable as ATR multiple, percent, ticks, points, or dollars), and its own "Exit At Next Supertrend Plotted Course" checkbox. All types default to fully disabled.
Global Risk Controls (always active, override everything)
Max contracts per trade (position size cap across core + pyramid adds)
Master daily $ take-profit and $ max-loss halts
Volatility Exit — flattens everything if ATR expands beyond a multiple of its recent average
ATR Protective Stop — a catastrophic-loss stop measured off the position's average entry price
Reverse-At-Stop-Loss — an optional system that flips the core position to the opposite side when the per-course Stop Loss is hit, capped at a configurable number of reversals per course
This strategy trades off two Supertrend indicators calculated on independent, user-selected timeframes (defaults: 1-minute and 2-minute). A trade is only taken when both Supertrends agree on direction — when they align upward, the strategy goes long; when they align downward, it goes short. Each new alignment is treated as a new "plotted course," and the strategy tracks that course's direction so it doesn't re-enter on every bar, only on an actual flip.
Core Entry Logic
Long/Short/Both direction control, so you can restrict the strategy to one side of the market if desired.
A session time-window filter (with a timezone dropdown covering major global zones) lets you restrict trading to specific hours, with an option to auto-close everything when the window ends.
On a Supertrend flip, the strategy normally waits until the position is completely flat before entering the new direction — it does not force-close open tiered or pyramid contracts just because the trend flipped. (See "Exit At Next Supertrend Plotted Course" below for the opt-in alternative.)
Tiered Exit System
Three independent, fully self-contained profit-scaling tiers (Tier 1/2/3), each with:
A profit target (ticks) and contract quantity to scale out at that target
An optional Stop Loss, and an optional Trailing Stop with a separate activation threshold (ticks, own enable checkbox)
An "Exit At Next Supertrend Plotted Course" checkbox — when checked, that tier's contracts are force-closed the moment the trend flips; when unchecked (default), the tier runs entirely on its own Target/Stop/Trailing settings regardless of what the trend does next.
Pyramid Add-On System
Eight independent pyramid types can each be enabled separately to add contracts in the direction of an existing position when their own specific condition fires:
Turtle ATR Unit — adds every time price moves a set fraction of ATR in your favor from the last fill.
Swing Structure — adds on a new confirmed swing high/low in the trend direction.
Momentum Re-confirmation — adds when ADX is rising with DI+/DI- agreement and RSI holds past a threshold.
Breakout / Consolidation — adds on a fresh Donchian channel breakout.
Multi-Timeframe Alignment — adds only when a higher-timeframe EMA filter agrees with the trade direction.
Error-Function One-Tailed Test — adds when the current bar's move is statistically significant versus its recent return distribution (Normal or Student-T approximation).
KDE Percentile — adds when the current move ranks in the top percentile of a non-parametric kernel-density estimate of recent returns.
Viterbi Regime Detection — adds only while a 2-state Hidden Markov Model infers the market is in a "trending" (versus "ranging") regime.
Each pyramid type is fully self-contained: its own contracts-per-signal size, its own optional TP/SL/Trailing Stop, its own per-course contract and signal caps, a delay-between-signals timer, a minimum-distance-before-next-add gate (selectable as ATR multiple, percent, ticks, points, or dollars), and its own "Exit At Next Supertrend Plotted Course" checkbox. All types default to fully disabled.
Global Risk Controls (always active, override everything)
Max contracts per trade (position size cap across core + pyramid adds)
Master daily $ take-profit and $ max-loss halts
Volatility Exit — flattens everything if ATR expands beyond a multiple of its recent average
ATR Protective Stop — a catastrophic-loss stop measured off the position's average entry price
Reverse-At-Stop-Loss — an optional system that flips the core position to the opposite side when the per-course Stop Loss is hit, capped at a configurable number of reversals per course
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。