Strategy · Pine Script v6 · On the chart

Swing Pivot ATR

by pineforge-4pass· code credited to PineForge contributors 2026

Swing Pivot ATR is a trend-breakout strategy that identifies swing highs and lows using pivot points and enters positions on price breakouts.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code46
Settings4inputs
LicenceApache-2.0
Last update5 days ago23 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 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 v6 from validation/ta-pivot-atr-stop-target-01/strategy.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

strategy.pine
// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// PF probe 28 — pivot-anchored ATR stop/target
// Purpose: parity test for ta.pivothigh / ta.pivotlow detection paired with
// `var float lastPvtH/L` retention and ATR-multiple stop & target sizing.
//
//@version=6
strategy("Swing Pivot ATR", overlay=true, initial_capital=1000000, process_orders_on_close=false, pyramiding=1, commission_type=strategy.commission.percent, commission_value=0, slippage=0, default_qty_type=strategy.fixed, default_qty_value=1)

// === Inputs ===
pivotLen = input.int(5, "Pivot Length", minval=2)
atrLen   = input.int(14, "ATR Length", minval=1)
atrMult  = input.float(1.5, "ATR SL Multiplier", step=0.1)
tpMult   = input.float(2.0, "ATR TP Multiplier", step=0.1)

// === Pivots ===
pvtHigh = ta.pivothigh(high, pivotLen, pivotLen)
pvtLow  = ta.pivotlow(low, pivotLen, pivotLen)
atrVal  = ta.atr(atrLen)

// === Track last pivot levels ===
var float lastPvtH = na
var float lastPvtL = na

if not na(pvtHigh)
    lastPvtH := pvtHigh
if not na(pvtLow)
    lastPvtL := pvtLow

// === Breakout of pivot levels ===
longCond  = not na(lastPvtH) and close > lastPvtH and close[1] <= lastPvtH
shortCond = not na(lastPvtL) and close < lastPvtL and close[1] >= lastPvtL

// === Strategy with exit targets ===
if longCond
    strategy.entry("Long", strategy.long)
    strategy.exit("XL", "Long", stop=close - atrVal * atrMult, limit=close + atrVal * tpMult)

if shortCond
    strategy.entry("Short", strategy.short)
    strategy.exit("XS", "Short", stop=close + atrVal * atrMult, limit=close - atrVal * tpMult)

plot(lastPvtH, "Last Pivot High", color=color.red, style=plot.style_stepline)
plot(lastPvtL, "Last Pivot Low", color=color.green, style=plot.style_stepline)

Overview

Swing Pivot ATR tracks historical pivot high and low levels, plotting them as steplines directly on the price chart. When price closes above the last pivot high, it opens a long position; when price closes below the last pivot low, it opens a short position. Every trade includes dynamic risk management with ATR-based stop loss and take profit targets. Key settings include pivot detection length, ATR length, and ATR multipliers for stop loss and take profit.

Details

Published by

pineforge-4pass on GitHub

Code credit

PineForge contributors 2026, as written in the script's header

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Breakout, Support & resistance, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingbacktestingparitypine-scriptpinescriptquantitative-financetest-corpustradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Pivot Lengthint5pivotLen
ATR Lengthint14atrLen
ATR SL Multiplierfloat1.5atrMult
ATR TP Multiplierfloat2.0tpMult
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.

Similar Pine Scripts

257 stars

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

Strategy v6 Volatility & bandsSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of V1.6 ES - Futures 1M No Repaint
16 stars

This strategy trades Donchian breakouts measured on weekly bars while orders execute on the chart timeframe. It allows long and short entries when price breaks the prior weekly channel and exits against the shorter weekly channel. Position size risks a set per

Strategy v6 TrendBreakout
Updated 11 months ago · None stated GitHub repository of Seykota Alt 4: Weekly Donchian
11 stars

Calculates upper and lower Donchian Channel bands over a customizable lookback length and plots them on the main price chart. At a specified exchange hour, the strategy places a long buy stop order at the upper Donchian Channel level. Unfilled pending orders a

Strategy v6 BreakoutSupport & resistance
Updated 5 months ago · Apache-2.0 GitHub repository of Estrategia Donchian Breakout

This trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks. It triggers a long entry when the closing price breaks above the highest high of the prior entr

Strategy v6 BreakoutTrend
Updated today · AGPL-3.0 GitHub repository of Forven S01509 - Simple Donchian 20/10 Breakout
106 stars

This overlay strategy plots a two-timeframe Ichimoku setup on the price chart, with Tenkan, Kijun, Chikou, and Kumo from a base higher timeframe and an optional highest-timeframe cloud. It allows two entries in the same direction and uses ATR-based trailing st

Strategy v4 TrendVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of 2Tier Ichimoku Pyramiding [Takazudo]

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers