Pine Script v3 · Strategy
LegacyPivots strategy XN
A Pine Script v3 strategy built on SMA (close, 20) and ATR (10). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 11 settings; defaults include Pivot Type Daily, Trading Session 0800-1600 and Factor 2.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does Pivots strategy XN repaint?
- Yes
- At least one pattern in the source can repaint: higher-timeframe data.
- How did Pivots strategy XN do on BTCUSDT 1D with default settings?
- −5.72%
- From 26 Jan 2024 to 21 Oct 2026, over 86 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Pivots strategy XN be converted to Pine Script v5?
- Yes
- The upgrade takes 2 steps, from v3; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- What alerts does Pivots strategy XN have?
- 9
- Pivot S3 Cross; Pivot S2 Cross; Pivot S1 Cross; Pivot TC Cross; and more.
- Does Pivots strategy XN use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
BTCUSDT · 1D · default settings
- R3
- R2
- R1
- TC
- PP
- BC
- S1
- S2
- S3
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −5.72%
- −$5,723.82
- Buy and hold
- +102.5%
- same period
- Closed trades
- 86
- 28 won · 58 lost
- Profitable
- 32.6%
- of closed trades
- Profit factor
- 0.96
- gross profit ÷ gross loss
- Max drawdown
- 61.22%
- −$69,290.00
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A short position was still open at the last bar. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
2 settings have no label
In the settings dialog Factor (line 181), Pd (line 182) show an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 204, 205. The upgraded version below moves each call inside an if block.
Upgrade and export
Written in Pine Script v3. The upgrade to v5 takes 2 steps, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames security → request.security, max → math.max, min → math.min, cross → ta.cross, sma → ta.sma, atr → ta.atr.
- Colours are bare names (orange, red, blue); v4 spells them color.orange, color.red, color.blue.
- 2 strategy calls use the when = argument (line 204, 205). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v3 → v4
VerifiedSame 86 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=3 → //@version=4
- Line 10: bool → input.bool
- Line 11: bool → input.bool
- Line 12: bool → input.bool
- Line 13: bool → input.bool
- Line 14: bool → input.bool
19 more edits
- Line 16: session → input.session
- Line 17: bool → input.bool
- Line 19: bool → input.bool
- Line 23: tickerid → syminfo.tickerid
- Line 35: period → timeframe.period
- Line 90: circles → plot.style_circles
- Line 92: circles → plot.style_circles
- Line 94: circles → plot.style_circles
- Line 96: circles → plot.style_circles
- Line 98: circles → plot.style_circles
- Line 100: circles → plot.style_circles
- Line 102: circles → plot.style_circles
- Line 104: circles → plot.style_circles
- Line 106: circles → plot.style_circles
- Line 111: monday → dayofweek.monday
- Line 147: orange → color.orange
- Line 180: red → color.red
- Line 181: float → input.float
- Line 192: blue → color.blue
⋯// © amysojexson-//@version=3+//@version=4strategy(title="Pivots strategy", overlay=true)⋯// Make toggles for pivot level options-plotPP = input(title="Plot PP", type=bool, defval=true)+plotPP = input(title="Plot PP", type=input.bool, defval=true)-plotS1R1 = input(title="Plot S1 and R1", type=bool, defval=true)+plotS1R1 = input(title="Plot S1 and R1", type=input.bool, defval=true)-plotS2R2 = input(title="Plot S2 and R2", type=bool, defval=true)+plotS2R2 = input(title="Plot S2 and R2", type=input.bool, defval=true)-plotS3R3 = input(title="Plot S3 and R3", type=bool, defval=true)+plotS3R3 = input(title="Plot S3 and R3", type=input.bool, defval=true)-plotTCBC = input(title="Plot S3 and R3", type=bool, defval=true)+plotTCBC = input(title="Plot S3 and R3", type=input.bool, defval=true)// Configure session options-sessRange = input(title="Trading Session", type=session, defval="0800-1600")+sessRange = input(title="Trading Session", type=input.session, defval="0800-1600")-showSess = input(title="Highlight Session?", type=bool, defval=false)+showSess = input(title="Highlight Session?", type=input.bool, defval=false)// Enable or disable pivot labels-showLabels = input(title="Show Labels?", type=bool, defval=false)+showLabels = input(title="Show Labels?", type=input.bool, defval=false)// Step 2. Calculate indicator values⋯GetData(res, data) =>- security(tickerid, res, data[1],+ security(syminfo.tickerid, res, data[1], lookahead=barmerge.lookahead_on)⋯// the session time range-inSession = not na(time(period, sessRange)[1])+inSession = not na(time(timeframe.period, sessRange)[1])sessStart = inSession and not inSession[1]⋯plot(series=plotS3R3 ? r3 : na, title="R3",- style=circles, linewidth=1, color=#0023FF)+ style=plot.style_circles, linewidth=1, color=#0023FF)plot(series=plotS2R2 ? r2 : na, title="R2",- style=circles, linewidth=1, color=#1E90FF)+ style=plot.style_circles, linewidth=1, color=#1E90FF)plot(series=plotS1R1 ? r1 : na, title="R1",- style=circles, linewidth=1, color=#09E0F3)+ style=plot.style_circles, linewidth=1, color=#09E0F3)plot(series=plotTCBC ? tc : na, title="TC",- style=circles, linewidth=.75, color=#FF00D1)+ style=plot.style_circles, linewidth=.75, color=#FF00D1)plot(series=plotPP ? pp : na, title="PP",- style=circles, linewidth=1, color=#000000)+ style=plot.style_circles, linewidth=1, color=#000000)plot(series=plotTCBC ? bc : na, title="BC",- style=circles, linewidth=.75, color=#FF00D1)+ style=plot.style_circles, linewidth=.75, color=#FF00D1)plot(series=plotS1R1 ? s1 : na, title="S1",- style=circles, linewidth=1, color=#09E0F3)+ style=plot.style_circles, linewidth=1, color=#09E0F3)plot(series=plotS2R2 ? s2 : na, title="S2",- style=circles, linewidth=1, color=#1E90FF)+ style=plot.style_circles, linewidth=1, color=#1E90FF)plot(series=plotS3R3 ? s3 : na, title="S3",- style=circles, linewidth=1, color=#0023FF)+ style=plot.style_circles, linewidth=1, color=#0023FF)// Display the pivot names on the chart, if applicable⋯ (pivotType == "Daily") ? dayofmonth != dayofmonth[1] :- dayofweek == monday and dayofmonth != dayofmonth[1]+ dayofweek == dayofweek.monday and dayofmonth != dayofmonth[1]plotchar(series=newPivots and plotS3R3 ? r3 : na,⋯bgcolor(color=showSess and inSession and (pivotType == "Intraday") ?- orange : na, transp=95)+ color.orange : na, transp=95)// Step 4. Create indicator alerts⋯MA = sma(close, 20)-plot(MA, color=red)+plot(MA, color=color.red)-Factor = input(2, type=float)+Factor = input(2, type=input.float)Pd = input(10, minval=1,maxval = 100)⋯Tsl = Trend==1? TrendUp: TrendDown-plot(Tsl, color=blue)+plot(Tsl, color=color.blue)if close>open⋯v4 → v5
VerifiedSame 86 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 10: input(type = input.bool) → input.bool()
- Line 11: input(type = input.bool) → input.bool()
- Line 12: input(type = input.bool) → input.bool()
- Line 13: input(type = input.bool) → input.bool()
- Line 14: input(type = input.bool) → input.bool()
24 more edits
- Line 16: input(type = input.session) → input.session()
- Line 17: input(type = input.bool) → input.bool()
- Line 19: input(type = input.bool) → input.bool()
- Line 23: security → request.security
- Line 43: max → math.max
- Line 45: min → math.min
- Line 146: transp = 95 → color.new(showSess and inSession and (pivotType == "Intraday") ? color.orange : na, 95)
- Line 149: cross → ta.cross
- Line 152: cross → ta.cross
- Line 155: cross → ta.cross
- Line 159: cross → ta.cross
- Line 162: cross → ta.cross
- Line 166: cross → ta.cross
- Line 169: cross → ta.cross
- Line 172: cross → ta.cross
- Line 175: cross → ta.cross
- Line 179: sma → ta.sma
- Line 181: input(type = input.float) → input.float()
- Line 183: atr → ta.atr
- Line 184: atr → ta.atr
- Line 186: max → math.max
- Line 188: min → math.min
- Line 197: strategy.entry(…, true) → strategy.entry(…, strategy.long)
- Line 202: strategy.entry(…, false) → strategy.entry(…, strategy.short)
⋯// © amysojexson-//@version=4+//@version=5strategy(title="Pivots strategy", overlay=true)⋯// Make toggles for pivot level options-plotPP = input(title="Plot PP", type=input.bool, defval=true)+plotPP = input.bool(title="Plot PP", defval=true)-plotS1R1 = input(title="Plot S1 and R1", type=input.bool, defval=true)+plotS1R1 = input.bool(title="Plot S1 and R1", defval=true)-plotS2R2 = input(title="Plot S2 and R2", type=input.bool, defval=true)+plotS2R2 = input.bool(title="Plot S2 and R2", defval=true)-plotS3R3 = input(title="Plot S3 and R3", type=input.bool, defval=true)+plotS3R3 = input.bool(title="Plot S3 and R3", defval=true)-plotTCBC = input(title="Plot S3 and R3", type=input.bool, defval=true)+plotTCBC = input.bool(title="Plot S3 and R3", defval=true)// Configure session options-sessRange = input(title="Trading Session", type=input.session, defval="0800-1600")+sessRange = input.session(title="Trading Session", defval="0800-1600")-showSess = input(title="Highlight Session?", type=input.bool, defval=false)+showSess = input.bool(title="Highlight Session?", defval=false)// Enable or disable pivot labels-showLabels = input(title="Show Labels?", type=input.bool, defval=false)+showLabels = input.bool(title="Show Labels?", defval=false)// Step 2. Calculate indicator values⋯GetData(res, data) =>- security(syminfo.tickerid, res, data[1],+ request.security(syminfo.tickerid, res, data[1], lookahead=barmerge.lookahead_on)⋯sessHigh := sessStart ? high :- inSession ? max(high, sessHigh[1]) : na+ inSession ? math.max(high, sessHigh[1]) : nasessLow := sessStart ? low :- inSession ? min(low, sessLow[1]) : na+ inSession ? math.min(low, sessLow[1]) : nasessClose := sessEnd ? close[1] : na⋯// Highlight the intra-day price data session on the chart-bgcolor(color=showSess and inSession and (pivotType == "Intraday") ?+bgcolor(color=color.new(showSess and inSession and (pivotType == "Intraday") ?- color.orange : na, transp=95)+ color.orange : na, 95))// Step 4. Create indicator alerts-alertcondition(condition=cross(close, s3),+alertcondition(condition=ta.cross(close, s3), title="Pivot S3 Cross", message="Prices crossed Pivot S3 level")-alertcondition(condition=cross(close, s2),+alertcondition(condition=ta.cross(close, s2), title="Pivot S2 Cross", message="Prices crossed Pivot S2 level")-alertcondition(condition=cross(close, s1),+alertcondition(condition=ta.cross(close, s1), title="Pivot S1 Cross",⋯ -alertcondition(condition=cross(close, tc),+alertcondition(condition=ta.cross(close, tc), title="Pivot TC Cross", message="Prices crossed Pivot TC level")-alertcondition(condition=cross(close, pp),+alertcondition(condition=ta.cross(close, pp), title="Pivot PP Cross",⋯ -alertcondition(condition=cross(close, bc),+alertcondition(condition=ta.cross(close, bc), title="Pivot BC Cross", message="Prices crossed Pivot BC level")-alertcondition(condition=cross(close, r1),+alertcondition(condition=ta.cross(close, r1), title="Pivot R1 Cross", message="Prices crossed Pivot R1 level")-alertcondition(condition=cross(close, r2),+alertcondition(condition=ta.cross(close, r2), title="Pivot R2 Cross", message="Prices crossed Pivot R2 level")-alertcondition(condition=cross(close, r3),+alertcondition(condition=ta.cross(close, r3), title="Pivot R3 Cross",⋯ -MA = sma(close, 20)+MA = ta.sma(close, 20)plot(MA, color=color.red)-Factor = input(2, type=input.float)+Factor = input.float(2)Pd = input(10, minval=1,maxval = 100)-Up = hl2-(Factor*atr(Pd))+Up = hl2-(Factor*ta.atr(Pd))-Dn = hl2+(Factor*atr(Pd))+Dn = hl2+(Factor*ta.atr(Pd))TrendUp = 0.0-TrendUp := close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up+TrendUp := close[1]>TrendUp[1]? math.max(Up,TrendUp[1]) : UpTrendDown = 0.0-TrendDown := close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn+TrendDown := close[1]<TrendDown[1]? math.min(Dn,TrendDown[1]) : DnTrend = 0.0⋯ if close>MA- strategy.entry("long", true) + strategy.entry("long", strategy.long) if close<open⋯ if close<MA- strategy.entry("short", false) + strategy.entry("short", strategy.short) ⋯Same 86 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 7: input() → input.string()
- Line 182: input() → input.int()
- Line 204: when = open<Tsl → if block
- Line 205: when = open>Tsl → if block
⋯// Create a pull-down menu for the pivot type-pivotType = input(title="Pivot Type",+pivotType = input.string(title="Pivot Type", options=["Daily", "Intraday", "Weekly"], defval="Daily")⋯Factor = input.float(2)-Pd = input(10, minval=1,maxval = 100)+Pd = input.int(10, minval=1,maxval = 100)Up = hl2-(Factor*ta.atr(Pd))⋯ -strategy.close("long", when = open<Tsl)+if open<Tsl+ strategy.close("long")-strategy.close("short", when = open>Tsl)+if open>Tsl+ strategy.close("short")Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L96:C31: 'linewidth' must be at least 1 in Pine Script v6. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © amysojexson-//@version=5+//@version=6strategy(title="Pivots strategy", overlay=true)⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Pivot Type | Daily | string · options ["Daily", "Intraday", "Weekly"] | theHigh theLow theClose newPivots bgcolor |
| Plot PP | true | bool | PP |
| Plot S1 and R1 | true | bool | R1 S1 R1 label S1 label |
| Plot S2 and R2 | true | bool | R2 S2 R2 label S2 label |
| Plot S3 and R3 | true | bool | R3 S3 R3 label S3 label |
| Plot S3 and R3 | true | bool | TC BC TC label BC label |
| Trading Session | 0800-1600 | session | inSession |
| Highlight Session? | false | bool | bgcolor |
| Show Labels? | false | bool | newPivots |
| Factor (no label in the script) | 2 | float | Up Dn |
| Pd (no label in the script) | 10 | int · min 1 · max 100 | Up Dn |
What it calculates
- SMA (
sma,ta.smain v5)close, 20MA · line 179 - ATR (
atr,ta.atrin v5)Pd (10)Up · line 183 - ATR (
atr,ta.atrin v5)Pd (10)Dn · line 184
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
The script has 68 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | close>MA | On | 197 |
| Open short short | close<MA | On | 202 |
| Close long | open<Tsl | On | 204 |
| Close short | open>Tsl | On | 205 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Pivot S3 Cross | alertcondition | Prices crossed Pivot S3 level | 149 |
| Pivot S2 Cross | alertcondition | Prices crossed Pivot S2 level | 152 |
| Pivot S1 Cross | alertcondition | Prices crossed Pivot S1 level | 155 |
| Pivot TC Cross | alertcondition | Prices crossed Pivot TC level | 159 |
| Pivot PP Cross | alertcondition | Prices crossed the main Pivot Point level | 162 |
| Pivot BC Cross | alertcondition | Prices crossed Pivot BC level | 166 |
| Pivot R1 Cross | alertcondition | Prices crossed Pivot R1 level | 169 |
| Pivot R2 Cross | alertcondition | Prices crossed Pivot R2 level | 172 |
| Pivot R3 Cross | alertcondition | Prices crossed Pivot R3 level | 175 |
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- CheckHigher-timeframe data1 security call(s) use lookahead_on (line 23). Without a [1] offset this reads future bars in history.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo calc_on_every_tick. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −5.7% | +102.5% | 86 | 33% | 0.96 | 61.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +3.5% | +5.5% | 53 | 32% | 1.13 | 6.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +2.6% | +9.8% | 66 | 45% | 1.43 | 2.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.3% | +8.4% | 73 | 33% | 1.22 | 0.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.0% | +16.7% | 87 | 44% | 0.93 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 54 | 35% | 1.07 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.5% | +148.3% | 82 | 33% | 1.53 | 0.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.2% | +17.1% | 68 | 26% | 0.53 | 0.2% | 8 May 2026 – 21 Oct 2026 |
Higher-timeframe data for request.security(): BINANCE:BTCUSDT W (Binance BTCUSDT 1w), fetched from Binance's public market data for each market.
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 26 | 27% | $6,572.29 |
| Sideways market | 30 | 37% | −$17,376.60 |
| Falling market | 30 | 33% | $5,080.52 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
59.3%
The 95th percentile of the worst drawdown when the same 86 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 32.8% to 59.3%; the tick is what actually happened, 51.7%. Order luck alone moves it this much.
All 86 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 17 Feb 2024 52,124.10 | 17 Mar 2024 65,300.60 | 29 | $13,176.50 |
| short | 17 Mar 2024 65,300.60 | 18 Mar 2024 68,393.50 | 1 | −$3,092.83 |
| long | 18 Mar 2024 68,393.50 | 19 Mar 2024 67,610.00 | 1 | −$783.47 |
| long | 21 Mar 2024 67,840.50 | 22 Mar 2024 65,501.30 | 1 | −$2,339.23 |
| short | 22 Mar 2024 65,501.30 | 29 Mar 2024 70,780.60 | 7 | −$5,279.32 |
| long | 29 Mar 2024 70,780.60 | 30 Mar 2024 69,850.50 | 1 | −$930.07 |
| long | 1 Apr 2024 71,280.00 | 2 Apr 2024 69,649.80 | 1 | −$1,630.19 |
| long | 9 Apr 2024 71,620.00 | 10 Apr 2024 69,146.00 | 1 | −$2,474.00 |
| long | 11 Apr 2024 70,631.10 | 12 Apr 2024 70,006.20 | 1 | −$624.86 |
| short | 16 Apr 2024 63,420.00 | 23 Apr 2024 66,819.30 | 7 | −$3,399.33 |
| long | 23 Apr 2024 66,819.30 | 24 Apr 2024 66,414.00 | 1 | −$405.32 |
| short | 27 Apr 2024 63,770.00 | 16 May 2024 66,206.50 | 19 | −$2,436.51 |
| long | 16 May 2024 66,206.50 | 14 Jun 2024 66,773.00 | 29 | $566.50 |
| short | 18 Jun 2024 66,504.30 | 15 Jul 2024 60,797.90 | 27 | $5,706.42 |
| long | 20 Jul 2024 66,660.00 | 1 Aug 2024 64,628.00 | 12 | −$2,032.00 |
| short | 1 Aug 2024 64,628.00 | 2 Aug 2024 65,354.00 | 1 | −$726.01 |
| short | 3 Aug 2024 61,498.30 | 9 Aug 2024 61,686.00 | 6 | −$187.66 |
| short | 12 Aug 2024 58,712.60 | 13 Aug 2024 59,346.60 | 1 | −$634.05 |
| short | 15 Aug 2024 58,683.40 | 16 Aug 2024 57,541.10 | 1 | $1,142.34 |
| short | 19 Aug 2024 58,427.30 | 20 Aug 2024 59,438.50 | 1 | −$1,011.15 |
| long | 22 Aug 2024 61,156.00 | 29 Aug 2024 59,034.90 | 7 | −$2,121.13 |
| short | 4 Sep 2024 57,487.70 | 14 Sep 2024 60,498.00 | 10 | −$3,010.25 |
| long | 18 Sep 2024 60,314.00 | 2 Oct 2024 60,804.90 | 14 | $490.93 |
| short | 8 Oct 2024 62,224.00 | 15 Oct 2024 66,084.00 | 7 | −$3,859.99 |
| long | 27 Oct 2024 67,092.80 | 5 Nov 2024 67,850.00 | 9 | $757.25 |
| short | 5 Nov 2024 67,850.00 | 6 Nov 2024 69,372.00 | 1 | −$1,522.00 |
| long | 6 Nov 2024 69,372.00 | 20 Dec 2024 97,461.90 | 44 | $28,089.90 |
| short | 27 Dec 2024 95,791.60 | 7 Jan 2025 102,236.00 | 11 | −$6,444.00 |
| short | 10 Jan 2025 92,552.50 | 16 Jan 2025 100,497.00 | 6 | −$7,944.86 |
| long | 22 Jan 2025 106,144.00 | 5 Feb 2025 97,763.10 | 14 | −$8,380.68 |
| short | 5 Feb 2025 97,763.10 | 3 Mar 2025 94,270.00 | 26 | $3,493.15 |
| short | 4 Mar 2025 86,221.20 | 5 Mar 2025 87,282.00 | 1 | −$1,060.82 |
| short | 10 Mar 2025 80,734.50 | 24 Mar 2025 86,082.50 | 14 | −$5,348.02 |
| long | 24 Mar 2025 86,082.50 | 25 Mar 2025 87,498.20 | 1 | $1,415.66 |
| long | 28 Mar 2025 87,232.00 | 29 Mar 2025 84,424.40 | 1 | −$2,807.63 |
| long | 2 Apr 2025 85,158.40 | 3 Apr 2025 82,516.30 | 1 | −$2,642.07 |
| short | 3 Apr 2025 82,516.30 | 12 Apr 2025 83,423.80 | 9 | −$907.55 |
| long | 12 Apr 2025 83,423.80 | 13 Apr 2025 85,276.90 | 1 | $1,853.08 |
| long | 15 Apr 2025 84,591.60 | 16 Apr 2025 83,644.00 | 1 | −$947.59 |
| long | 18 Apr 2025 84,947.90 | 19 Apr 2025 84,474.70 | 1 | −$473.22 |
| long | 20 Apr 2025 85,077.00 | 21 Apr 2025 85,179.20 | 1 | $102.24 |
| long | 29 Apr 2025 95,011.20 | 31 May 2025 103,985.00 | 32 | $8,974.29 |
| short | 21 Jun 2025 103,298.00 | 26 Jun 2025 107,341.00 | 5 | −$4,042.61 |
| long | 3 Jul 2025 108,850.00 | 1 Aug 2025 115,764.00 | 29 | $6,914.48 |
| short | 1 Aug 2025 115,764.00 | 11 Aug 2025 119,294.00 | 10 | −$3,530.20 |
| long | 11 Aug 2025 119,294.00 | 20 Aug 2025 112,873.00 | 9 | −$6,421.32 |
| short | 20 Aug 2025 112,873.00 | 23 Aug 2025 116,936.00 | 3 | −$4,063.05 |
| long | 23 Aug 2025 116,936.00 | 24 Aug 2025 115,438.00 | 1 | −$1,497.94 |
| short | 26 Aug 2025 110,112.00 | 11 Sep 2025 113,960.00 | 16 | −$3,848.02 |
| long | 11 Sep 2025 113,960.00 | 24 Sep 2025 111,999.00 | 13 | −$1,961.20 |
| short | 26 Sep 2025 108,994.00 | 30 Sep 2025 114,312.00 | 4 | −$5,317.48 |
| long | 7 Oct 2025 124,659.00 | 11 Oct 2025 112,774.00 | 4 | −$11,884.00 |
| short | 12 Oct 2025 110,644.00 | 3 Dec 2025 91,277.90 | 52 | $19,366.50 |
| long | 3 Dec 2025 91,277.90 | 4 Dec 2025 93,429.90 | 1 | $2,152.07 |
| long | 8 Dec 2025 90,395.30 | 9 Dec 2025 90,634.40 | 1 | $239.03 |
| long | 10 Dec 2025 92,678.80 | 11 Dec 2025 92,015.40 | 1 | −$663.43 |
| short | 13 Dec 2025 90,268.40 | 31 Dec 2025 88,485.50 | 18 | $1,782.93 |
| long | 31 Dec 2025 88,485.50 | 1 Jan 2026 87,648.20 | 1 | −$837.29 |
| short | 1 Jan 2026 87,648.20 | 2 Jan 2026 88,839.10 | 1 | −$1,190.84 |
| long | 2 Jan 2026 88,839.10 | 3 Jan 2026 89,995.10 | 1 | $1,156.09 |
| long | 12 Jan 2026 91,013.70 | 21 Jan 2026 88,427.70 | 9 | −$2,586.00 |
| short | 1 Feb 2026 78,741.10 | 3 Mar 2026 68,830.10 | 30 | $9,911.04 |
| long | 3 Mar 2026 68,830.10 | 4 Mar 2026 68,338.00 | 1 | −$492.05 |
| long | 10 Mar 2026 68,432.20 | 22 Mar 2026 68,918.10 | 12 | $485.96 |
| short | 22 Mar 2026 68,918.10 | 24 Mar 2026 70,906.40 | 2 | −$1,988.33 |
| long | 24 Mar 2026 70,906.40 | 25 Mar 2026 70,556.70 | 1 | −$349.71 |
| short | 27 Mar 2026 68,820.30 | 8 Apr 2026 71,924.20 | 12 | −$3,103.91 |
| long | 8 Apr 2026 71,924.20 | 16 May 2026 79,113.20 | 38 | $7,188.98 |
| short | 16 May 2026 79,113.20 | 17 May 2026 78,148.10 | 1 | $965.15 |
| short | 20 May 2026 76,834.40 | 16 Jun 2026 66,328.70 | 27 | $10,505.60 |
| short | 17 Jun 2026 65,675.00 | 18 Jun 2026 64,509.40 | 1 | $1,165.62 |
| short | 22 Jun 2026 63,312.00 | 23 Jun 2026 64,020.00 | 1 | −$708.01 |
| long | 23 Jun 2026 64,020.00 | 25 Jun 2026 61,078.00 | 2 | −$2,942.01 |
| short | 1 Jul 2026 58,624.70 | 6 Jul 2026 63,650.00 | 5 | −$5,025.30 |
| long | 10 Jul 2026 63,230.00 | 28 Jul 2026 63,755.90 | 18 | $525.85 |
| short | 28 Jul 2026 63,755.90 | 29 Jul 2026 63,915.00 | 1 | −$159.14 |
| long | 31 Jul 2026 64,780.00 | 1 Aug 2026 62,887.90 | 1 | −$1,892.15 |
| short | 1 Aug 2026 62,887.90 | 2 Aug 2026 62,823.70 | 1 | $64.23 |
| short | 7 Aug 2026 64,323.60 | 8 Aug 2026 64,923.20 | 1 | −$599.59 |
| long | 8 Aug 2026 64,923.20 | 15 Aug 2026 63,043.60 | 7 | −$1,879.64 |
| short | 15 Aug 2026 63,043.60 | 16 Aug 2026 63,086.00 | 1 | −$42.45 |
| short | 17 Aug 2026 62,900.00 | 18 Aug 2026 64,532.10 | 1 | −$1,632.11 |
| long | 18 Aug 2026 64,532.10 | 16 Sep 2026 75,644.50 | 29 | $11,112.40 |
| short | 16 Sep 2026 75,644.50 | 17 Sep 2026 76,206.00 | 1 | −$561.52 |
| long | 19 Sep 2026 80,883.90 | 13 Oct 2026 81,850.00 | 24 | $966.15 |
| short | 13 Oct 2026 81,850.00 | 14 Oct 2026 83,169.00 | 1 | −$1,319.00 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Pivots strategy XN this page | — | v3 strategy | −5.7% | 86 | 61.2% |
| I11L - Better Buy Low Volatility or High Volatility- by I11L | atr sma | v5 strategy | +19.2% | 83 | 37.4% |
| Vortex Cross w-MA Confirmation by DraftVenture | atr sma | v5 strategy | +2.4% | 52 | 4.7% |
| Configurable Multi MA Crossover Voting System by levieux | sma atr | v5 strategy | +28.5% | 5 | 39.4% |
| Swing Trend Strategy by Inkedlau | sma atr | v5 strategy | +11.2% | 5 | 16.2% |
| SSL Backtester With ATR SL TP and Money Management by JBTrippin | sma atr | v4 strategy | +8.5% | 55 | 3.9% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 37 ms | With a workaround 1,000 bars in 130 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 197, 202) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © amysojexson//@version=3strategy(title="Pivots strategy", overlay=true)// Input settings// Create a pull-down menu for the pivot typepivotType = input(title="Pivot Type", options=["Daily", "Intraday", "Weekly"], defval="Daily")// Make toggles for pivot level optionsplotPP = input(title="Plot PP", type=bool, defval=true)plotS1R1 = input(title="Plot S1 and R1", type=bool, defval=true)plotS2R2 = input(title="Plot S2 and R2", type=bool, defval=true)plotS3R3 = input(title="Plot S3 and R3", type=bool, defval=true)plotTCBC = input(title="Plot S3 and R3", type=bool, defval=true)// Configure session optionssessRange = input(title="Trading Session", type=session, defval="0800-1600")showSess = input(title="Highlight Session?", type=bool, defval=false)// Enable or disable pivot labelsshowLabels = input(title="Show Labels?", type=bool, defval=false)// Step 2. Calculate indicator values// Create a function to fetch daily and weekly dataGetData(res, data) => security(tickerid, res, data[1], lookahead=barmerge.lookahead_on)// Fetch daily and weekly price datadailyHigh = GetData("D", high)dailyLow = GetData("D", low)dailyClose = GetData("D", close)weeklyHigh = GetData("W", high)weeklyLow = GetData("W", low)weeklyClose = GetData("W", close)// Determine session pivot data// First see how the price bar relates to// the session time rangeinSession = not na(time(period, sessRange)[1])sessStart = inSession and not inSession[1]sessEnd = not inSession and inSession[1]// Determine session price datasessHigh = 0.0sessLow = 0.0sessClose = 0.0sessHigh := sessStart ? high : inSession ? max(high, sessHigh[1]) : nasessLow := sessStart ? low : inSession ? min(low, sessLow[1]) : nasessClose := sessEnd ? close[1] : na// Compute high, low, close from previous intra-day sessionhighPrevSess = 0.0lowPrevSess = 0.0closePrevSess = 0.0highPrevSess := sessEnd ? fixnan(sessHigh) : highPrevSess[1]lowPrevSess := sessEnd ? fixnan(sessLow) : lowPrevSess[1]closePrevSess := sessEnd ? fixnan(sessClose) : closePrevSess[1]// Now figure out which kind of price data// to use for the pivot calculationtheHigh = if (pivotType == "Daily") dailyHighelse if (pivotType == "Intraday") highPrevSess else weeklyHightheLow = if (pivotType == "Daily") dailyLowelse if (pivotType == "Intraday") lowPrevSess else weeklyLowtheClose = if (pivotType == "Daily") dailyCloseelse if (pivotType == "Intraday") closePrevSess else weeklyClose// Finally calculate the pivot levelspp = (theHigh + theLow + theClose) / 3bc= (theHigh + theLow)/2tc= (pp-bc)+ppr1 = pp+(.382*(theHigh-theLow))s1 = pp-(.382*(theHigh-theLow))r2 = pp +(.618*(theHigh-theLow))s2 = pp -(.618*(theHigh-theLow))r3 = pp +(1*(theHigh-theLow))s3 = pp -(1*(theHigh-theLow))// Step 3. Output indicator data// Plot the various pivot levelsplot(series=plotS3R3 ? r3 : na, title="R3", style=circles, linewidth=1, color=#0023FF)plot(series=plotS2R2 ? r2 : na, title="R2", style=circles, linewidth=1, color=#1E90FF)plot(series=plotS1R1 ? r1 : na, title="R1", style=circles, linewidth=1, color=#09E0F3)plot(series=plotTCBC ? tc : na, title="TC", style=circles, linewidth=.75, color=#FF00D1)plot(series=plotPP ? pp : na, title="PP", style=circles, linewidth=1, color=#000000)plot(series=plotTCBC ? bc : na, title="BC", style=circles, linewidth=.75, color=#FF00D1)plot(series=plotS1R1 ? s1 : na, title="S1", style=circles, linewidth=1, color=#09E0F3)plot(series=plotS2R2 ? s2 : na, title="S2", style=circles, linewidth=1, color=#1E90FF)plot(series=plotS3R3 ? s3 : na, title="S3", style=circles, linewidth=1, color=#0023FF)// Display the pivot names on the chart, if applicablenewPivots = (showLabels == false) ? false : (pivotType == "Intraday") ? sessEnd : (pivotType == "Daily") ? dayofmonth != dayofmonth[1] : dayofweek == monday and dayofmonth != dayofmonth[1]plotchar(series=newPivots and plotS3R3 ? r3 : na, char='', text="R3", offset=1, location=location.absolute, color=#0023FF, title="R3 label")plotchar(series=newPivots and plotS2R2 ? r2 : na, char='', text="R2", offset=1, location=location.absolute, color=#1E90FF, title="R2 label")plotchar(series=newPivots and plotS1R1 ? r1 : na, char='', text="R1", offset=1, location=location.absolute, color=#09E0F3, title="R1 label")plotchar(series=newPivots and plotTCBC ? r1 : na, char='', text="TC", offset=1, location=location.absolute, color=#FF00D1, title="TC label") plotchar(series=newPivots and plotTCBC ? r1 : na, char='', text="BC", offset=1, location=location.absolute, color=#FF00D1, title="BC label")plotchar(series=newPivots and plotS1R1 ? s1 : na, char='', text="S1", offset=1, location=location.absolute, color=#09E0F3, title="S1 label")plotchar(series=newPivots and plotS2R2 ? s2 : na, char='', text="S2", offset=1, location=location.absolute, color=#1E90FF, title="S2 label")plotchar(series=newPivots and plotS3R3 ? s3 : na, char='', text="S3", offset=1, location=location.absolute, color=#0023FF, title="S3 label")// Highlight the intra-day price data session on the chartbgcolor(color=showSess and inSession and (pivotType == "Intraday") ? orange : na, transp=95)// Step 4. Create indicator alertsalertcondition(condition=cross(close, s3), title="Pivot S3 Cross", message="Prices crossed Pivot S3 level")alertcondition(condition=cross(close, s2), title="Pivot S2 Cross", message="Prices crossed Pivot S2 level")alertcondition(condition=cross(close, s1), title="Pivot S1 Cross", message="Prices crossed Pivot S1 level") alertcondition(condition=cross(close, tc), title="Pivot TC Cross", message="Prices crossed Pivot TC level")alertcondition(condition=cross(close, pp), title="Pivot PP Cross", message="Prices crossed the main Pivot Point level") alertcondition(condition=cross(close, bc), title="Pivot BC Cross", message="Prices crossed Pivot BC level")alertcondition(condition=cross(close, r1), title="Pivot R1 Cross", message="Prices crossed Pivot R1 level")alertcondition(condition=cross(close, r2), title="Pivot R2 Cross", message="Prices crossed Pivot R2 level")alertcondition(condition=cross(close, r3), title="Pivot R3 Cross", message="Prices crossed Pivot R3 level") MA = sma(close, 20)plot(MA, color=red)Factor = input(2, type=float)Pd = input(10, minval=1,maxval = 100)Up = hl2-(Factor*atr(Pd))Dn = hl2+(Factor*atr(Pd))TrendUp = 0.0TrendUp := close[1]>TrendUp[1]? max(Up,TrendUp[1]) : UpTrendDown = 0.0TrendDown := close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : DnTrend = 0.0Trend := close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1)Tsl = Trend==1? TrendUp: TrendDownplot(Tsl, color=blue)if close>open if open<pp if close>pp if close>MA strategy.entry("long", true) if close<open if open>pp if close<pp if close<MA strategy.entry("short", false) strategy.close("long", when = open<Tsl)strategy.close("short", when = open>Tsl)