Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Trend Bounce [racer8]

A Pine Script v4 strategy built on Highest (high, 7), Lowest (low, 7) and SMA (close, 200). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade is one contract and pays no commission. 3 settings; defaults include Channel Length 7, Ma Length 200 and ATR Stop Loss 2.0.

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 Trend Bounce [racer8] repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 8 of 8 trades.
How did Trend Bounce [racer8] do on BTCUSDT 1D with default settings?
+2.36%
From 26 Jan 2024 to 21 Oct 2026, over 22 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Trend Bounce [racer8] be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does Trend Bounce [racer8] use a stop loss?
Yes
strategy.exit sets a stop on line 35, 37.
Does Trend Bounce [racer8] run in Zeal Terminal?
Yes
It compiles in 14 ms and runs 1,000 bars in 32 ms, in the browser.

BTCUSDT · 1D · default settings

  • high
  • low
  • sma
  • ATR Stop Loss Long
  • ATR Stop Loss Short
  • 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 (3)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$105,311$202,527Equity from $100,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.
Net profit
+2.36%
$2,362.72
Buy and hold
+102.5%
same period
Closed trades
22
12 won · 10 lost
Profitable
54.5%
of closed trades
Profit factor
1.04
gross profit ÷ gross loss
Max drawdown
32.20%
−$32,204.90

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A long 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.

  • Likely bug

    sma(tr, 10) ignores the settings line 24

    Line 24 hard-codes 10 where line 10 uses “Ma Length”. Changing those settings moves one band but not this one.

    sma(tr,10)sma(tr, n2)
  • 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.

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, 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 highest → ta.highest, lowest → ta.lowest, sma → ta.sma, valuewhen → ta.valuewhen.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 7: highest → ta.highest
  • Line 8: lowest → ta.lowest
  • Line 10: sma → ta.sma
  • Line 24: sma → ta.sma
  • Line 24: tr → ta.tr
  • Line 30: valuewhen → ta.valuewhen
  • Line 31: valuewhen → ta.valuewhen
⋯// © racer8-//@version=4+//@version=5// This Algo Strategy Has Only 3 rules and 62% Win Rate (Youtube) ⋯nn = input(7,"Channel Length")-hi = highest(high,nn)+hi = ta.highest(high,nn)-lo = lowest(low,nn)+lo = ta.lowest(low,nn)n2 = input(200,"Ma Length")-ma = sma(close,n2)+ma = ta.sma(close,n2)if close>ma and close<lo[1]⋯//-----------------------------------------Stop Loss-------------------------------------------------------atr = sma(tr,10)[1]+atr = ta.sma(ta.tr,10)[1]bought = strategy.position_size[0] > strategy.position_size[1]⋯StopPrice_Short  = strategy.position_avg_price + slm*atr              // determines stop loss's price -FixedStopPrice_Long = valuewhen(bought,StopPrice_Long,0)                  // stores original StopPrice  +FixedStopPrice_Long = ta.valuewhen(bought,StopPrice_Long,0)                  // stores original StopPrice  -FixedStopPrice_Short = valuewhen(sold,StopPrice_Short,0)                  // stores original StopPrice  +FixedStopPrice_Short = ta.valuewhen(sold,StopPrice_Short,0)                  // stores original StopPrice  plot(FixedStopPrice_Long,"ATR Stop Loss Long",color=color.blue,linewidth=1,style=plot.style_cross)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 6: input() → input.int()
  • Line 9: input() → input.int()
  • Line 27: input() → input.float()
⋯strategy("Trend Bounce", overlay=true)-nn = input(7,"Channel Length")+nn = input.int(7,"Channel Length")hi = ta.highest(high,nn)lo = ta.lowest(low,nn)-n2 = input(200,"Ma Length")+n2 = input.int(200,"Ma Length")ma = ta.sma(close,n2)⋯sold = strategy.position_size[0] < strategy.position_size[1]-slm = input(2.0,"ATR Stop Loss",minval=0)+slm = input.float(2.0,"ATR Stop Loss",minval=0)StopPrice_Long  = strategy.position_avg_price - slm*atr              // determines stop loss's price ⋯

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: 22 before, 28 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.

⋯// © racer8-//@version=5+//@version=6// This Algo Strategy Has Only 3 rules and 62% Win Rate (Youtube) ⋯

Settings

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

SettingDefaultType and rangeFeeds
Channel Length7inthi lo
Ma Length200intma
ATR Stop Loss2.0float · min 0StopPrice_Long StopPrice_Short

What it calculates

  • Highest (highest, ta.highest in v5)high, Channel Length (7)hi · line 7
  • Lowest (lowest, ta.lowest in v5)low, Channel Length (7)lo · line 8
  • SMA (sma, ta.sma in v5)close, Ma Length (200)ma · line 10
  • SMA (sma, ta.sma in v5)tr, 10atr · line 24
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, StopPrice_Long, 0FixedStopPrice_Long · line 30
  • Valuewhen (valuewhen, ta.valuewhen in v5)sold, StopPrice_Short, 0FixedStopPrice_Short · line 31

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 datannChannel Lengthsetting · 7lowlowprice dataclosecloseprice datan2Ma Lengthsetting · 200slmATR Stop Losssetting · 2.0hiHighest→ hiloLowest→ lomaSMA→ maatrSMA→ atrFixedStopPrice_LongValuewhen→ FixedStopPrice_LongFixedStopPrice_ShortValuewhen→ FixedStopPrice_ShortStopPrice_Long, StopPrice_ShortStopPrice_Long · StopPr…2 valuesbought, soldbought · sold2 conditionsentry:BuyOpen Buystrategy.entryclose:BuyClose Buystrategy.closeentry:SellOpen Sellstrategy.entryclose:SellClose Sellstrategy.closeexit:Stopexit Stopstrategy.exitplot:20highplotplot:21lowplotplot:22smaplotplot:32ATR Stop Loss Longplotplot:33ATR Stop Loss Shortplot

Order rules

OrderFires whenBy defaultLine
Open Buy longclose>ma and close<lo[1]On12
Close Buyclose>hi[1]On14
Open Sell shortclose<ma and close>hi[1]On17
Close Sellclose<lo[1]On19
Exit Stop stopstrategy.position_size > 0On35
Exit Stop stopstrategy.position_size < 0On37

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.

8/8trades 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.4%+102.5%2255%1.0432.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+6.3%+5.5%3152%1.355.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+2.5%+9.8%2962%1.990.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.5%+8.4%2864%1.980.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.1%+16.7%2861%1.310.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%3053%0.990.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.1%+148.3%2152%1.200.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%2450%1.090.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 market683%$13,630.40
Sideways market1145%−$9,580.30
Falling market540%−$1,687.42

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

How bad could the drawdown be?

33.4%

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

0%38%
All 22 trades
SideEntryExitBarsP&L
short14 Sep 2024 60,498.0026 Sep 2024 65,436.9012−$4,938.96
long20 Dec 2024 97,461.904 Jan 2025 98,174.2015$712.31
long3 Feb 2025 97,700.6025 Feb 2025 90,413.4022−$7,287.19
long26 Feb 2025 88,680.4028 Feb 2025 82,699.002−$5,981.41
short13 Apr 2025 85,276.9025 Apr 2025 94,769.0012−$9,492.13
long30 May 2025 105,590.0010 Jun 2025 110,263.0011$4,673.27
long22 Jun 2025 102,120.0026 Jun 2025 107,341.004$5,220.57
long2 Aug 2025 113,298.0011 Aug 2025 119,294.009$5,996.35
long19 Aug 2025 116,227.0025 Aug 2025 110,145.006−$6,082.51
long26 Aug 2025 110,112.0011 Sep 2025 113,960.0016$3,848.02
long23 Sep 2025 112,651.0025 Sep 2025 108,959.002−$3,691.93
long26 Sep 2025 108,994.002 Oct 2025 118,595.006$9,600.50
long11 Oct 2025 112,774.0027 Oct 2025 114,559.0016$1,784.92
short4 Dec 2025 93,429.9016 Dec 2025 86,432.1012$6,997.87
short5 Jan 2026 91,529.7013 Jan 2026 95,322.008−$3,792.28
short14 Jan 2026 95,414.0021 Jan 2026 88,427.707$6,986.33
short5 Mar 2026 72,666.8023 Mar 2026 67,859.0018$4,807.77
short8 Apr 2026 71,924.2017 Apr 2026 76,573.009−$4,648.79
short18 Apr 2026 77,072.006 May 2026 82,124.0018−$5,051.99
short14 Jun 2026 64,458.0025 Jun 2026 61,078.0011$3,380.01
short4 Jul 2026 62,583.3019 Aug 2026 67,576.4046−$4,993.14
long11 Sep 2026 76,568.7019 Sep 2026 80,883.908$4,315.13

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
Trend Bounce [racer8] this page—v4 strategy+2.4%2232.2%
TradingGroundhog - Strategy & Fractal V1 by UnknownUnicorn27666852highest lowest valuewhen smav4 strategy−2.9%85.9%
Buying Dip Strategy With Take Profit And Stop Loss [racer8] by racer8sma valuewhen lowestv4 strategy−22.3%3434.7%
ChBrkOutStrategySMA by anshuanshu333sma highest lowestv4 strategy−4.5%4220.9%
Swing Points Breakouts by tweakerIDlowest highest valuewhenv4 strategy+29.9%9252.0%
KDJ Strategy @ionvolution by ionvolutionsma highest lowestv5 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 14 msYes 1,000 bars in 32 msNot measured
PineTSNo v5 and v6 only—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. 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/// © racer8//@version=4// This Algo Strategy Has Only 3 rules and 62% Win Rate (Youtube) strategy("Trend Bounce", overlay=true)nn = input(7,"Channel Length")hi = highest(high,nn)lo = lowest(low,nn)n2 = input(200,"Ma Length")ma = sma(close,n2)if close>ma and close<lo[1]    strategy.entry("Buy",strategy.long)if close>hi[1]    strategy.close("Buy")     if close<ma and close>hi[1]    strategy.entry("Sell",strategy.short)if close<lo[1]    strategy.close("Sell")plot(hi,"high",color=color.aqua)plot(lo,"low",color=color.aqua)plot(ma,"sma",color=color.yellow)       //-----------------------------------------Stop Loss------------------------------------------------------atr = sma(tr,10)[1]bought = strategy.position_size[0] > strategy.position_size[1]sold = strategy.position_size[0] < strategy.position_size[1]slm = input(2.0,"ATR Stop Loss",minval=0)StopPrice_Long  = strategy.position_avg_price - slm*atr              // determines stop loss's price StopPrice_Short  = strategy.position_avg_price + slm*atr              // determines stop loss's price FixedStopPrice_Long = valuewhen(bought,StopPrice_Long,0)                  // stores original StopPrice  FixedStopPrice_Short = valuewhen(sold,StopPrice_Short,0)                  // stores original StopPrice  plot(FixedStopPrice_Long,"ATR Stop Loss Long",color=color.blue,linewidth=1,style=plot.style_cross)plot(FixedStopPrice_Short,"ATR Stop Loss Short",color=color.red,linewidth=1,style=plot.style_cross)if strategy.position_size > 0    strategy.exit(id="Stop", stop=FixedStopPrice_Long)    // commands stop loss order to exit!if strategy.position_size < 0    strategy.exit(id="Stop", stop=FixedStopPrice_Short)    // commands stop loss order to exit!