Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

PB Trend Scalper

A Pine Script v5 strategy built on EMA (high, 55), RMA (high, 100) and Stoch (close, high). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a profit target and no stop loss. Each trade is one contract and pays no commission. 7 settings; defaults include quick ma's 55, long ma's 100 and leverage 3.

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 PB Trend Scalper repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
How did PB Trend Scalper do on BTCUSDT 1D with default settings?
−16.93%
From 26 Jan 2024 to 21 Oct 2026, over 10 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does PB Trend Scalper 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: 10 before, 0 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 PB Trend Scalper use a stop loss?
No
Its exits set a profit target but no stop.
Does PB Trend Scalper run in Zeal Terminal?
Yes
It compiles in 27 ms and runs 1,000 bars in 54 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • Winning trade
  • Losing trade
  • Exit at a stop or limit price
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (7)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctLimit exit at 84,349.90Limit exit at 78,338.00$830,510$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, and squares exits filled at a stop or limit price. Lines are what the script plots. 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.
Net profit
−16.93%
−$169,337.00
Buy and hold
+102.5%
same period
Closed trades
10
8 won · 2 lost
Profitable
80.0%
of closed trades
Profit factor
0.92
gross profit ÷ gross loss
Max drawdown
68.30%
−$1,530,180.00

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.

  • Check

    No stop loss

    strategy.exit is used without a stop, loss or trailing stop.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • 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 57, 63. The upgraded version below moves each call inside an if block.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
quick ma's55intema55h ema55l
long ma's100intema200h ema200l
leverage3intpositionSize
Highest high period170inthh
Lowest low period170intll
no trade zone3.0floatemadistlong emadistshort
take profit %6.9floatexit long exit exit short exit

What it calculates

  • EMAhigh, quick ma's (55)ema55h · line 8
  • EMAlow, quick ma's (55)ema55l · line 9
  • RMAhigh, long ma's (100)ema200h · line 10
  • RMAlow, long ma's (100)ema200l · line 11
  • Stochclose, high, low, 14stock · line 12
  • Highesthigh, Highest high period (170)hh · line 16
  • Lowestlow, Lowest low period (170)ll · line 17

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.

highhighprice datashortmaquick ma'ssetting · 55lowlowprice datalongmalong ma'ssetting · 100closecloseprice datahhValHighest high periodsetting · 170llValLowest low periodsetting · 170pno trade zonesetting · 3.0levleveragesetting · 3ema55hEMA→ ema55hema55lEMA→ ema55lema200hRMA→ ema200hema200lRMA→ ema200lstockStoch→ stockhhHighest→ hhllLowest→ llemadistlongemadistlongvalueemadistshortemadistshortvalueEntryPriceEntryPricevaluepositionSizepositionSizevaluelongclose2longclose2conditionshortclose2shortclose2conditionentry:shortOpen shortstrategy.entryentry:longOpen longstrategy.entryexit:long exitexit long exitstrategy.exitclose:longClose longstrategy.closeexit:short exitexit short exitstrategy.exitclose:shortClose shortstrategy.closeplot:19plotplotplot:20plotplotplot:26plotplotplot:27plotplotplot:28plotplotplot:29plotplotfill:30Fillfill

Order rules

OrderFires whenBy defaultLine
Open short shortema55h < ema200l and close[2] < ema55l and close[1] > ema55l and high[1] < ema55h and close < ema55h and ema55h < emadistshort and strategy.opentrades == 0On38
Open long longema55l > ema200h and close[2] > ema55h and close[1] < ema55h and low[1] > ema55l and close > ema55l and ema55l > emadistlong and strategy.opentrades <= 1On45
Exit long exit limitevery barOn56
Close longlongclose2low < ll[1] or low < emadistshortOn57
Exit short exit limitevery barOn62
Close shortshortclose2high > hh[1] or high>emadistlongOn63

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.

4/4trades 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−16.9%+102.5%1080%0.9268.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+5.1%+5.5%367%1.1539.8%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−136.4%+9.8%475%0.36123.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−18.8%+8.4%560%0.7537.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−97.6%+16.7%956%0.2298.6%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−49.7%+21.5%333%0.1955.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−90.2%+148.3%956%0.3493.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−6.5%+17.1%450%0.8430.2%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 market580%$55,520.10
Sideways market3100%$800,525.00
Falling market250%−$1,025,380.00

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

81.6%

The 95th percentile of the worst drawdown when the same 10 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 62.9% to 81.6%; the tick is what actually happened, 62.9%. Order luck alone moves it this much.

0%94%
All 10 trades
SideEntryExitBarsP&L
long31 Dec 2024 92,792.106 Jan 2025 99,194.706$207,000.00
long10 Jan 2025 92,552.5015 Jan 2025 98,938.605$249,849.00
long4 Feb 2025 101,329.001 Mar 2025 84,349.90 limit25−$732,327.00
long7 Jun 2025 104,288.009 Jul 2025 111,484.0032$149,976.00
long3 Aug 2025 112,546.0011 Aug 2025 120,312.008$181,021.00
long25 Aug 2025 113,494.003 Oct 2025 121,325.0039$218,493.00
short13 Jan 2026 91,296.2029 Jan 2026 84,996.8016$263,721.00
short17 Mar 2026 74,884.7019 Mar 2026 69,717.602$318,311.00
short27 Mar 2026 68,820.304 Jun 2026 64,071.7069$384,202.00
short16 Jul 2026 64,756.3022 Aug 2026 78,338.00 limit37−$1,409,580.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.

ScriptSharesTypeNetTradesMax drawdown
PB Trend Scalper this page—v5 strategy−16.9%1068.3%
Jigga - Survival Level by jigneshjcrma highest lowest emav5 strategyNo trades on this market
Bagheri IG Ether by Bagheri_IGema highest lowest rmav4 strategy+0.0%30.0%
Bagheri IG Ether v2 by Bagheri_IGema highest lowest rmav4 strategy−0.0%20.0%
Dillon's Double VWAP Strategy by jordanfrayrma ema lowest highestv5 strategyNo trades on this market
Strategy Myth-Busting #8 - TrendSurfers+TrendOsc - [MYN] by myncryptohighest lowest ema rmav5 strategyNo trades on this market

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.

  • 2 strategy calls use the when = argument (line 57, 63). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

Same 10 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 57: when = longclose2 → if block
  • Line 63: when = shortclose2 → if block
⋯strategy.exit("long exit", "long", profit = (strategy.position_avg_price*(tp)))//, loss = (strategy.position_avg_price*(sl)))-strategy.close("long", when = longclose2, comment = "long exit")+if longclose2+    strategy.close("long", comment = "long exit")//strategy.close("long", when = (downtrade == 1), comment = "long exit")⋯strategy.exit("short exit", "short", profit = (strategy.position_avg_price*(tp)))//, loss = (strategy.position_avg_price*(sl)))//, loss = 300)-strategy.close("short", when = shortclose2, comment = "short exit")+if shortclose2+    strategy.close("short", comment = "short exit")//strategy.close("short", when = (downtrade == 0), comment = "short exit")⋯

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: 10 before, 0 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.

⋯// © PatrickGwynBuckley-//@version=5+//@version=6//var initialCapital = strategy.equity⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 27 msWith a workaround 1,000 bars in 54 msNot measured
PineTSNot testedNot testedNot measured

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.

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/// © PatrickGwynBuckley//@version=5//var initialCapital = strategy.equitystrategy("PB Trend Scalper", "PB Trend Scalper", overlay = true)shortma = input.int(55, title="quick ma's")longma = input.int(100, title="long ma's")ema55h = ta.ema(high, shortma)ema55l = ta.ema(low, shortma)ema200h = ta.rma(high, longma)ema200l = ta.rma(low, longma)stock = ta.stoch(close, high, low, 14)lev = input.int(3, title="leverage")hhVal = input.int(170, title="Highest high period")llVal = input.int(170, title="Lowest low period")hh = ta.highest(high, hhVal)ll = ta.lowest(low, llVal)//plot(stock)plot(hh, color=color.new(color.green, 50))plot(ll, color=color.new(color.red, 50))var float downtrade = 0p = input.float(3.0, title="no trade zone")l = 3emadistlong = ema200h + ((ema200h/100)*p)emadistshort = ema200l - ((ema200h/100)*p)plot(ema55h)plot(ema55l)ntl = plot(emadistlong, color=color.new(color.red, 10))nts = plot(emadistshort, color=color.new(color.red, 10))fill(ntl, nts, color=color.new(color.red, 90))//position sizeEntryPrice = close//positionValue = initialCapitalpositionSize = (strategy.equity*lev) / EntryPrice//plot(strategy.equity)//standard shortif ema55h < ema200l and close[2] < ema55l and close[1] > ema55l and high[1] < ema55h and close < ema55h and ema55h < emadistshort and strategy.opentrades == 0// and stock > 85     strategy.entry("short", strategy.short, qty=positionSize, comment="short")    downtrade := 1//reset count    if (ta.crossunder(ema55h, ema200l)) and downtrade == 1    downtrade := 0//standard long    if ema55l > ema200h and close[2] > ema55h and close[1] < ema55h and low[1] > ema55l and close > ema55l and ema55l > emadistlong and strategy.opentrades <= 1// and stock < 15     strategy.entry("long", strategy.long, qty=positionSize, comment="long")    downtrade := 0//RESET COUNT ON MA CROSSif (ta.crossover(ema55l, ema200h)) and downtrade == 0    downtrade := 1    longclose2 = low < ll[1] or low < emadistshort //close < open and open<open[1] and open[2] < open[3] and open[3] < emadistshort//close < ta.lowest(low, 20)//shortclose2 = high > hh[1] or high>emadistlong//close > open and open>open[1] and open[2]>open[3] and open[3] > emadistlong//high > emadistlong//close > ta.highest(high, 20)//sl = 3.5tp = input.float(6.9, title="take profit %")tp2 = 10strategy.exit("long exit", "long", profit = (strategy.position_avg_price*(tp)))//, loss = (strategy.position_avg_price*(sl)))strategy.close("long", when = longclose2, comment = "long exit")//strategy.close("long", when = (downtrade == 1), comment = "long exit")//strategy.exit("long exit", "long2", profit = (strategy.position_avg_price*(tp2)))//, loss = (strategy.position_avg_price*(sl)))//strategy.close ("long2", when = longclose2, comment = "long exit")//strategy.close("long", when = (downtrade == 1), comment = "long exit")strategy.exit("short exit", "short", profit = (strategy.position_avg_price*(tp)))//, loss = (strategy.position_avg_price*(sl)))//, loss = 300)strategy.close("short", when = shortclose2, comment = "short exit")//strategy.close("short", when = (downtrade == 0), comment = "short exit")//strategy.exit("short exit", "short2", profit = (strategy.position_avg_price*(tp2)))//, loss = (strategy.position_avg_price*(sl)))//strategy.close ("short2", when = shortclose2, comment = "short exit")//strategy.close("short2", when = (downtrade == 0), comment = "short exit")//if (strategy.exit("long exit", "long"))    //downtrade := 1//else    // downtrade := 0