1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.
Source Code
46 lines of Pine Script v5 from Adaptive Price Channel Strategy.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
Adaptive Price Channel Strategy.pine
//@version=5
strategy("Adaptive Price Channel Strategy", overlay=true)
length = input(20, title="Length")
exit_length = input(10, title="Exit After X Periods")
atr_multiplier = input(3.2, title="ATR Multiplier")
startDate = input.time(defval = timestamp("2019-01-15T08:15:15+00:00"), title = "Start Date")
endDate = input.time(defval = timestamp("2023-04-01T08:15:00+00:00"), title = "End Date")
hh = ta.highest(high, length)
ll = ta.lowest(low, length)
atr = ta.atr(length)
// calculate +DI and -DI
upMove = high - high[1]
downMove = low[1] - low
plusDM = na(upMove[1]) ? na : (upMove > downMove and upMove > 0 ? upMove : 0)
minusDM = na(downMove[1]) ? na : (downMove > upMove and downMove > 0 ? downMove : 0)
plusDI = ta.rma(plusDM, length) / atr * 100
minusDI = ta.rma(minusDM, length) / atr * 100
// calculate ADX
dx = math.abs(plusDI - minusDI) / (plusDI + minusDI) * 100
adx = ta.rma(dx, length)
var int barSinceEntry = na
if (not na(close[length]) and time >= startDate and time <= endDate)
if (adx < 25) // Sideways market
if (close > hh - atr_multiplier * atr)
strategy.entry("PChLE", strategy.long, comment="PChLE")
barSinceEntry := 0
else if (close < ll + atr_multiplier * atr)
strategy.entry("PChSE", strategy.short, comment="PChSE")
barSinceEntry := 0
else if (adx >= 25 and plusDI > minusDI) // Bullish market
if (close > hh - atr_multiplier * atr)
strategy.entry("PChLE", strategy.long, comment="PChLE")
barSinceEntry := 0
else if (adx >= 25 and plusDI < minusDI) // Bearish market
if (close < ll + atr_multiplier * atr)
strategy.entry("PChSE", strategy.short, comment="PChSE")
barSinceEntry := 0
if (na(barSinceEntry))
barSinceEntry := barSinceEntry[1] + 1
else if (barSinceEntry >= exit_length)
strategy.close("PChLE")
strategy.close("PChSE")
barSinceEntry := na
plot(hh, title="Highest High", color=color.green, linewidth=2)
plot(ll, title="Lowest Low", color=color.red, linewidth=2)
Expand (56 lines)
Overview
Adaptive Price Channel Strategy evaluates trend strength and directional movement to trigger entries when price crosses ATR-adjusted upper or lower channel thresholds. Open positions exit automatically after a user-defined number of bars. It plots the highest high and lowest low lines directly on the price chart and features a backtesting date range filter. Note that it relies entirely on time-based exits and lacks explicit stop loss or take profit orders.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Length
int
20
length
Exit After X Periods
int
10
exit_length
ATR Multiplier
float
3.2
atr_multiplier
Start Date
time
timestamp("2019-01-15T08:15:15+00:00")
startDate
End Date
time
timestamp("2023-04-01T08:15:00+00:00")
endDate
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This strategy plots VWMA-based Bollinger bands on the 1-minute ES futures price chart for volatility analysis and potential breakout identification. It calculates dynamic long and short stop loss and take profit levels using percentage inputs relative to entry
This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the
This trend-following strategy adapts classic Donchian breakout channels according to market volatility regimes. It calculates an ATR percentile rank across a rolling lookback period, shifting dynamically between tighter breakout channels with smaller stops dur
This strategy executes breakout trades using two Donchian Channels alongside an optional 200-period EMA trend filter. Entries trigger when the price sets a new highest high or lowest low over the primary Donchian Channel period. Exits are managed via a shorter
This strategy implements a channel breakout system directly on the main price chart. It calculates highest highs and lowest lows over configurable entry and exit periods using historical candles. A long entry triggers when the close breaks above the entry chan
This strategy combines channel breakout concepts with an ATR-ADX volatility trailing framework and multi-timeframe moving averages. It evaluates trend conditions using configurable moving average types, including SMA, EMA, Hull MA, and Tilson T3, paired with d