Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (1)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$973,259$2,025,273Equity from $1,000,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. Lines, boxes and labels are the script's own drawings, the most recent ones its limits keep.
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.

SettingDefaultType and rangeFeeds
Len (no label in the script)5intph pl currphb currplb plotshape

What it calculates

  • PivothighLen (5), Len (5)ph · line 11
  • PivotlowLen (5), Len (5)pl · line 12
  • TRlongsl · line 73
  • TRshortsl · 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.

lenLensetting · 5high · low · closehigh · low · closeprice dataclosecloseprice dataphPivothigh→ phplPivotlow→ pllongslTR→ longslshortslTR→ shortslrise, runrise · run2 valuesavgavgvalueishighishighvaluecurrphcurrphvaluecurrphbcurrphbvalueoldpholdphvalueoldphboldphbvaluecurrplcurrplvaluecurrplbcurrplbvalueoldploldplvalueoldplboldplbvalueendHighPointendHighPointvalueendLowPointendLowPointvaluelnhigherlnhighervaluelnlowerlnlowervaluelongratio1longratio1valuelongratio2longratio2valueshortratio1shortratio1valueshortratio2shortratio2valuesignalidsignalidvaluelongtplongtpvalueshorttpshorttpvaluelongCondlongCondconditionshortCondshortCondconditionformlong, formshortformlong · formshort2 conditionsentry:LongOpen Longstrategy.entryexit:Exit Longexit Exit Longstrategy.exitentry:ShortOpen Shortstrategy.entryexit:Exit Shortexit Exit Shortstrategy.exitplotshape:46plotshapeplotshapeplotshape:47plotshapeplotshape

Order rules

OrderFires whenBy defaultLine
Open Long long(longCond)On75
Exit Exit Long stop and limit(longCond)On76
Open Short short(shortCond)On89
Exit Exit Short stop and limit(shortCond)On90

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.

1/1trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−2.7%+102.5%425%0.103.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.1%+9.8%475%2.630.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.0%+8.4%20%0.000.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%757%1.480.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%617%0.310.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.0%+148.3%520%0.140.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%3100%—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 barsTradesWonP&L
Rising market250%−$6,359.49
Sideways market10%−$9,954.04
Falling market10%−$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.

0%3%
All 4 trades
SideEntryExitBarsP&L
short14 Apr 2024 63,924.5017 Apr 2024 60,775.003$3,099.64
long7 May 2024 63,165.205 Jul 2024 53,752.8059−$9,459.13
long10 Nov 2025 104,723.0014 Nov 2025 94,848.704−$9,954.04
short23 Mar 2026 67,859.0017 Apr 2026 78,228.1025−$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.

ScriptSharesTypeNetTradesMax drawdown
ABCD Strategy this page—v5 strategy−2.7%43.0%
Pivot Point Breakout by EduardoMattjepivotlow pivothighv5 strategy+93.0%2532.3%
Monthly Returns of a Strategy in a Chart by QuantNomadpivothigh pivotlowv5 strategy+21.0%7613.0%
ZigZag by Zeal Terminalpivothigh pivotlowv5 indicatorindicator
RSI Centered Pivots by OztheWozpivotlow pivothighv4 strategy+98.0%4160.2%
Steven Primo's bollinger bands strategy by EduardoMattjepivothigh pivotlowv5 strategy−17.7%1528.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.

Clean v5

VerifiedDownload the v5 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 38 msYes 1,000 bars in 57 msNot measured
PineTSNot testedNot testedNot 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)