Strategy library

Pivot Point Breakout strategy in Pine Script

Buys when the high breaks above the last pivot high and sells when the low breaks below the last pivot low.

Pivots · long only (as set in the code) · by EduardoMattje · Mozilla Public License 2.0

What is its backtest worth?

A parameter sweep finds the best setting of the Pivot Point Breakout strategy. PineTester tells you if it holds up: whether the best result was only picked after the fact, what it makes with fees, what you could have known at the time (a walk-forward on data the pick did not see) and how deep it fell along the way. On the free start, your first own backtest gets the full evaluation; its trade list and result file come with the full report or a plan.

Creates a draft on Binance BTC/USDT 4h over about six and a half years with 0.1% commission per order and 2 ticks slippage; you start it yourself. A backtest uses credits; new accounts receive free credits.

The rules

  • Enters long when the high rises above the most recent pivot high (bars to its left and right set by the inputs).
  • Closes the long when the low falls below the most recent pivot low.
  • Only long trades by default (the order direction input); invests the whole account in each trade.

What to watch for

  • A pivot is only known once its right-hand bars are complete, so the levels lag the price by that many bars.
  • Breakouts of nearby pivots happen often; fees weigh heavily on short pivot settings.

How PineTester judges a backtest, with its sources: how we judge results.

The Pine Script code

The author's code with its licence notice (Mozilla Public License 2.0), with one change marked in the code: the same test conditions for every library strategy in its strategy() line – the whole account per trade (split over the entries where it adds to a position), 0.1% commission per order and 2 ticks slippage; the trading rules are unchanged. Pine Script v5; PineTester converts it to v6 automatically, so results can differ slightly from TradingView.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EduardoMattje
// Modified by PineTester (2026-11-14): the same test conditions for every library strategy in strategy(): 100% of equity per entry,
// 0.1% commission per order, 2 ticks slippage, initial capital 10,000. The trading rules are unchanged.
//@version=5
strategy("Pivot Point Breakout", "PPB", true, process_orders_on_close=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, slippage=2)
// Constants
var L_PIVOT_HIGH = "Pivot high"
var L_PIVOT_LOW = "Pivot low"
var LEFT = "Left"
var RIGHT = "Right"
var BOTH = "Both"
var LONG = "Long"
var SHORT = "Short"
var DATES = "Date selection"
var DATES_TOOLTIP = "Change it to limit the trades for the given time interval.\n\nLeave it to disable this behaviour."
// Inputs
var orderDirection = input.string(LONG, "Order direction", options=[BOTH, LONG, SHORT])
var leftHigh = input.int(3, LEFT, minval=0, inline=L_PIVOT_HIGH, group=L_PIVOT_HIGH)
var rightHigh = input.int(3, RIGHT, minval=0, inline=L_PIVOT_HIGH, group=L_PIVOT_HIGH)
var leftLow = input.int(3, LEFT, minval=0, inline=L_PIVOT_LOW, group=L_PIVOT_LOW)
var rightLow = input.int(3, RIGHT, minval=0, inline=L_PIVOT_LOW, group=L_PIVOT_LOW)
var startDate = input.time(0, "Starting date", group=DATES)
var endDate = input.time(0, "Final date", group=DATES)
//
var float lastHigh = na
var float lastLow = na
lowPivot = ta.pivotlow(leftLow, rightLow)
highPivot = ta.pivothigh(leftHigh, rightHigh)
f_updateLevels(pivot_) => 
    var float pastLevel = na
    
    if not na(pivot_)
        pastLevel := pivot_
    
    pastLevel
    
lastLow := f_updateLevels(lowPivot)
lastHigh := f_updateLevels(highPivot)
// Validates the time interval
validTrade = (startDate == 0 ? true : time >= startDate) and
 (endDate == 0 ? true : time <= endDate)
// Orders
if high > lastHigh
    strategy.entry("Long", strategy.long, when=orderDirection != SHORT and validTrade)
    strategy.close("Short", when=orderDirection == SHORT)
if low < lastLow
    strategy.entry("Short", strategy.short, when=orderDirection != LONG and validTrade)
    strategy.close("Long", when=orderDirection == LONG)
    
// Plots
plot(lastLow, "Last pivot low", color.red, offset=1)
plot(lastHigh, "Last pivot high", color.teal, offset=1)
plotshape(lowPivot, "Pivot low", location=location.belowbar, color=color.red, offset=-rightLow)
plotshape(highPivot, "Pivot high", color=color.teal, offset=-rightHigh)
  • Steven Primo's Bollinger Bands – After several closes above narrow Bollinger Bands, a stop order above the last pivot high enters the breakout.
  • Bollinger Bands Modified (Stormer) – A close through narrow Bollinger Bands in the direction of the EMA, with a stop at the recent low and a target factor.
  • Vix Fix + Stochastic – Buys dips after a spike of the Williams Vix Fix and sells when the Stochastic turns down from overbought.

Open-source script by EduardoMattje, shown under the Mozilla Public License 2.0. Not a recommendation; neither the author nor TradingView endorses PineTester. Backtests are hypothetical results on past data, not a forecast.