Pine Script v5 · Strategy
ABCD Strategy
A Pine Script v5 strategy built on Pivothigh (5, 5), Pivotlow (5, 5) and TR. It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays 0.04 commission. 1 setting; defaults include Len 5.
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 ABCD Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
- How did ABCD Strategy do on BTCUSDT 1D with default settings?
- −2.67%
- From 26 Jan 2024 to 21 Oct 2026, over 4 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does ABCD Strategy run in Pine Script v6?
- No
- The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 4 before, 6 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does ABCD Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 76, 90.
- Does ABCD Strategy run in Zeal Terminal?
- Yes
- It compiles in 38 ms and runs 1,000 bars in 57 ms, in the browser.
BTCUSDT · 1D · default settings
- Shape
- Shape
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −2.67%
- −$26,741.10
- Buy and hold
- +102.5%
- same period
- Closed trades
- 4
- 1 won · 3 lost
- Profitable
- 25.0%
- of closed trades
- Profit factor
- 0.10
- gross profit ÷ gross loss
- Max drawdown
- 2.97%
- −$29,840.70
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. 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.
-
Note
1 setting has no label
In the settings dialog len (line 10) shows 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.
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 |
|---|---|---|---|
| Len (no label in the script) | 5 | int | ph pl currphb currplb plotshape |
What it calculates
- PivothighLen (5), Len (5)
ph · line 11 - PivotlowLen (5), Len (5)
pl · line 12 - TR
longsl · line 73 - TR
shortsl · line 87
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | (longCond) | On | 75 |
| Exit Exit Long stop and limit | (longCond) | On | 76 |
| Open Short short | (shortCond) | On | 89 |
| Exit Exit Short stop and limit | (shortCond) | On | 90 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. 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 | −2.7% | +102.5% | 4 | 25% | 0.10 | 3.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.1% | +9.8% | 4 | 75% | 2.63 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.0% | +8.4% | 2 | 0% | 0.00 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 7 | 57% | 1.48 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 6 | 17% | 0.31 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.0% | +148.3% | 5 | 20% | 0.14 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 3 | 100% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
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 | 2 | 50% | −$6,359.49 |
| Sideways market | 1 | 0% | −$9,954.04 |
| Falling market | 1 | 0% | −$10,427.60 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
3.0%
The 95th percentile of the worst drawdown when the same 4 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.7% to 3.0%; the tick is what actually happened, 3.0%. Order luck alone moves it this much.
All 4 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 14 Apr 2024 63,924.50 | 17 Apr 2024 60,775.00 | 3 | $3,099.64 |
| long | 7 May 2024 63,165.20 | 5 Jul 2024 53,752.80 | 59 | −$9,459.13 |
| long | 10 Nov 2025 104,723.00 | 14 Nov 2025 94,848.70 | 4 | −$9,954.04 |
| short | 23 Mar 2026 67,859.00 | 17 Apr 2026 78,228.10 | 25 | −$10,427.60 |
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 |
|---|---|---|---|---|---|
| ABCD Strategy this page | — | v5 strategy | −2.7% | 4 | 3.0% |
| Pivot Point Breakout by EduardoMattje | pivotlow pivothigh | v5 strategy | +93.0% | 25 | 32.3% |
| Monthly Returns of a Strategy in a Chart by QuantNomad | pivothigh pivotlow | v5 strategy | +21.0% | 76 | 13.0% |
| ZigZag by Zeal Terminal | pivothigh pivotlow | v5 indicator | indicator | ||
| RSI Centered Pivots by OztheWoz | pivotlow pivothigh | v4 strategy | +98.0% | 4 | 160.2% |
| Steven Primo's bollinger bands strategy by EduardoMattje | pivothigh pivotlow | v5 strategy | −17.7% | 15 | 28.2% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 1 setting uses the untyped input() (line 10). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 4 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 10: input() → input.int()
⋯ ((bar_index - lbars) * avg) + lprice-len = input(5)+len = input.int(5)ph = ta.pivothigh(len, len)⋯Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 4 before, 6 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © kerok3g-//@version=5+//@version=6strategy("ABCD Strategy", shorttitle="ABCDS", overlay=true, commission_value=0.04)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 38 ms | Yes 1,000 bars in 57 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“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.
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/// © kerok3g//@version=5strategy("ABCD Strategy", shorttitle="ABCDS", overlay=true, commission_value=0.04)calcdev(fprice, lprice, fbars, lbars) => rise = lprice - fprice run = lbars - fbars avg = rise/run ((bar_index - lbars) * avg) + lpricelen = input(5)ph = ta.pivothigh(len, len)pl = ta.pivotlow(len, len)var bool ishigh = falseishigh := ishigh[1]var float currph = 0.0var int currphb = 0currph := nz(currph)currphb := nz(currphb)var float oldph = 0.0var int oldphb = 0oldph := nz(oldph)oldphb := nz(oldphb)var float currpl = 0.0var int currplb = 0currpl := nz(currpl)currplb := nz(currplb)var float oldpl = 0.0var int oldplb = 0oldpl := nz(oldpl)oldplb := nz(oldplb)if (not na(ph)) ishigh := true oldph := currph oldphb := currphb currph := ph currphb := bar_index[len]else if (not na(pl)) ishigh := false oldpl := currpl oldplb := currplb currpl := pl currplb := bar_index[len]endHighPoint = calcdev(oldph, currph, oldphb, currphb)endLowPoint = calcdev(oldpl, currpl, oldplb, currplb)plotshape(ph, style=shape.triangledown, color=color.red, location=location.abovebar, offset=-len)plotshape(pl, style=shape.triangleup, color=color.green, location=location.belowbar, offset=-len)var line lnhigher = navar line lnlower = nalnhigher := line.new(oldphb, oldph, bar_index, endHighPoint)lnlower := line.new(oldplb, oldpl, bar_index, endLowPoint)line.delete(lnhigher[1])line.delete(lnlower[1])formlong = oldphb < oldplb and oldplb < currphb and currphb < currplblongratio1 = (currph - oldpl) / (oldph - oldpl)longratio2 = (currph - currpl) / (currph - oldpl)formshort = oldplb < oldphb and oldphb < currplb and currplb < currphbshortratio1 = (oldph - currpl) / (oldph - oldpl)shortratio2 = (currph - currpl) / (oldph - currpl)// prevent multiple entry for one patternvar int signalid = 0signalid := nz(signalid[1])longCond = formlong and longratio1 < 0.786 and longratio1 > 0.5 and longratio2 > 1 and longratio2 < 1.414 and close < oldph and close > currpl and signalid != oldplbif (longCond) signalid := oldplb longsl = currpl - ta.tr longtp = ((close - longsl) * 1.5) + close strategy.entry("Long", strategy.long) strategy.exit("Exit Long", "Long", limit=math.min(longtp, oldph), stop=longsl)shortCond = formshort and shortratio1 < 0.786 and shortratio1 > 0.5 and shortratio2 > 1.1 and shortratio2 < 1.414 and close > oldpl and close < currph and signalid != oldphbif (shortCond) signalid := oldphb shortsl = currph + ta.tr shorttp = close - ((shortsl - close) * 1.5) strategy.entry("Short", strategy.short) strategy.exit("Exit Short", "Short", limit=math.max(shorttp, oldpl), stop=shortsl)