Strategy · Pine Script v5 · On the chart

Pivot Points - S/R Trading

by Basant1Saini· code credited to TradingTools

Calculates classic support and resistance pivot levels using Traditional, Fibonacci, or Camarilla formulas from a higher timeframe.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code97
Settings7inputs
LicenceNone statedfile: MPL-2.0
Last update7 months ago4 Mar 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

97 lines of Pine Script v5 from 11_Pivot_Points/11_Pivot_Points.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

11_Pivot_Points.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0
// © TradingTools

//@version=5
strategy("Pivot Points - S/R Trading", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// ─── Inputs ───
pivotType       = input.string("Traditional", "Pivot Type", options=["Traditional", "Fibonacci", "Camarilla"], group="Pivot Settings")
pivotTF         = input.timeframe("D", "Pivot Timeframe", group="Pivot Settings")
entryMode       = input.string("Bounce", "Entry Mode", options=["Bounce", "Breakout"], group="Entry")
bounceBuffer    = input.float(0.15, "Bounce Buffer (%)", step=0.05, group="Entry")
atrLength       = input.int(14, "ATR Length", group="Risk Management")
atrMult         = input.float(1.5, "ATR Multiplier for SL", step=0.1, group="Risk Management")
rrRatio         = input.float(2.0, "Risk:Reward Ratio", step=0.1, group="Risk Management")

// ─── Previous Period Data ───
prevHigh  = request.security(syminfo.tickerid, pivotTF, high[1], barmerge.gaps_off, barmerge.lookahead_on)
prevLow   = request.security(syminfo.tickerid, pivotTF, low[1], barmerge.gaps_off, barmerge.lookahead_on)
prevClose = request.security(syminfo.tickerid, pivotTF, close[1], barmerge.gaps_off, barmerge.lookahead_on)

// ─── Pivot Calculation ───
pp = (prevHigh + prevLow + prevClose) / 3

var float s1 = na, var float s2 = na, var float s3 = na
var float r1 = na, var float r2 = na, var float r3 = na

if pivotType == "Traditional"
    r1 := 2 * pp - prevLow
    s1 := 2 * pp - prevHigh
    r2 := pp + (prevHigh - prevLow)
    s2 := pp - (prevHigh - prevLow)
    r3 := prevHigh + 2 * (pp - prevLow)
    s3 := prevLow - 2 * (prevHigh - pp)
else if pivotType == "Fibonacci"
    r1 := pp + 0.382 * (prevHigh - prevLow)
    s1 := pp - 0.382 * (prevHigh - prevLow)
    r2 := pp + 0.618 * (prevHigh - prevLow)
    s2 := pp - 0.618 * (prevHigh - prevLow)
    r3 := pp + 1.000 * (prevHigh - prevLow)
    s3 := pp - 1.000 * (prevHigh - prevLow)
else // Camarilla
    r1 := prevClose + (prevHigh - prevLow) * 1.1 / 12
    s1 := prevClose - (prevHigh - prevLow) * 1.1 / 12
    r2 := prevClose + (prevHigh - prevLow) * 1.1 / 6
    s2 := prevClose - (prevHigh - prevLow) * 1.1 / 6
    r3 := prevClose + (prevHigh - prevLow) * 1.1 / 4
    s3 := prevClose - (prevHigh - prevLow) * 1.1 / 4

// ─── ATR ───
atrVal = ta.atr(atrLength)

// ─── Bounce Entries ───
buf = close * (bounceBuffer / 100)

bounceLongS1  = low <= s1 + buf and close > s1 and entryMode == "Bounce"
bounceLongS2  = low <= s2 + buf and close > s2 and entryMode == "Bounce"
bounceShortR1 = high >= r1 - buf and close < r1 and entryMode == "Bounce"
bounceShortR2 = high >= r2 - buf and close < r2 and entryMode == "Bounce"

// ─── Breakout Entries ───
breakLongR1  = ta.crossover(close, r1) and entryMode == "Breakout"
breakLongR2  = ta.crossover(close, r2) and entryMode == "Breakout"
breakShortS1 = ta.crossunder(close, s1) and entryMode == "Breakout"
breakShortS2 = ta.crossunder(close, s2) and entryMode == "Breakout"

// ─── Combined ───
longCondition  = bounceLongS1 or bounceLongS2 or breakLongR1 or breakLongR2
shortCondition = bounceShortR1 or bounceShortR2 or breakShortS1 or breakShortS2

// ─── Execute Trades ───
if longCondition and strategy.position_size == 0
    sl = close - atrVal * atrMult
    tp = close + (close - sl) * rrRatio
    strategy.entry("Pivot Long", strategy.long)
    strategy.exit("Pivot Long Exit", "Pivot Long", stop=sl, limit=tp)

if shortCondition and strategy.position_size == 0
    sl = close + atrVal * atrMult
    tp = close - (sl - close) * rrRatio
    strategy.entry("Pivot Short", strategy.short)
    strategy.exit("Pivot Short Exit", "Pivot Short", stop=sl, limit=tp)

// ─── Plotting ───
plot(pp, "Pivot", color=color.new(color.yellow, 0), linewidth=2, style=plot.style_linebr)
plot(r1, "R1", color=color.new(color.red, 30), style=plot.style_linebr)
plot(r2, "R2", color=color.new(color.red, 10), style=plot.style_linebr)
plot(r3, "R3", color=color.new(color.red, 0), linewidth=2, style=plot.style_linebr)
plot(s1, "S1", color=color.new(color.green, 30), style=plot.style_linebr)
plot(s2, "S2", color=color.new(color.green, 10), style=plot.style_linebr)
plot(s3, "S3", color=color.new(color.green, 0), linewidth=2, style=plot.style_linebr)

plotshape(longCondition, title="Pivot Long", location=location.belowbar, style=shape.circle, color=color.green, size=size.tiny)
plotshape(shortCondition, title="Pivot Short", location=location.abovebar, style=shape.circle, color=color.red, size=size.tiny)

// ─── Alerts ───
alertcondition(longCondition, title="Pivot Long", message="Pivot Points: Long entry at support")
alertcondition(shortCondition, title="Pivot Short", message="Pivot Points: Short entry at resistance")

Overview

The strategy offers two execution modes: Bounce mode trades reversals within a customizable percentage buffer of support and resistance levels, while Breakout mode trades level crossovers. Risk is managed using an ATR-based dynamic stop loss and a fixed risk-to-reward take profit target. Plotted directly as an overlay on the main price chart.

Details

Published by

Basant1Saini on GitHub

Code credit

TradingTools, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Support & resistance, Breakout, Mean reversion

Markets

Any symbol

Timeframes

M15-H1, M1-M5

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.

Settings

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

SettingTypeDefaultVariable
Pivot TypestringTraditionalpivotType
Pivot TimeframetimeframeDpivotTF
Entry ModestringBounceentryMode
Bounce Buffer (%)float0.15bounceBuffer
ATR Lengthint14atrLength
ATR Multiplier for SLfloat1.5atrMult
Risk:Reward Ratiofloat2.0rrRatio
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

(IK) Base Break Buy

by hasnocool
106 stars

This price-chart strategy marks a base when enough recent bar bottoms cluster within a set deviation of the current bottom, then ignores new bases that sit too close to existing ones. A buy is considered when price falls a chosen percentage below a base inside

Strategy v4 Support & resistanceBreakout
Updated 2 years ago · GPL-3.0 GitHub repository of (IK) Base Break Buy
1 stars

The strategy detects range expansion by comparing the previous bar's range to its ATR multiple. It places pending stop entries above highs of up bars or below lows of down bars. On trigger it enters positions with take profit and stop loss in ticks using OCA g

Strategy v6 Volatility & bandsSupport & resistance
Updated 5 days ago · Apache-2.0 GitHub repository of PF probe 97 - tp/sl gap reversal oca
1 stars

This strategy identifies pivot-based Darvas Box levels on the price chart and trades re-entries following box sweeps. A long position arms when the price dips below the lower boundary and triggers when it closes back inside, provided the price is above a highe

Strategy v6 Support & resistanceBreakout
Updated 2 months ago · None stated GitHub repository of TN Sovereign Darvas Box v6

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

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