Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Richard's Strategy

A Pine Script v4 strategy built on Highest (close[1], 20), Lowest (close[1], 20) and ATR (20). 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. 2 settings; defaults include stop loss var 4 and lenght 20.

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 Richard's Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 21 of 21 trades.
How did Richard's Strategy do on BTCUSDT 1D with default settings?
+34.59%
From 26 Jan 2024 to 21 Oct 2026, over 70 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Richard's Strategy 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 Richard's Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Richard's Strategy run in Zeal Terminal?
Yes
It compiles in 15 ms and runs 1,000 bars in 28 ms, in the browser.

BTCUSDT · 1D · default settings

  • Shape
  • Shape
  • 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 (2)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$131,387$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
+34.59%
$34,593.90
Buy and hold
+102.5%
same period
Closed trades
70
49 won · 21 lost
Profitable
70.0%
of closed trades
Profit factor
1.30
gross profit ÷ gross loss
Max drawdown
26.29%
−$30,111.70

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

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

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, atr → ta.atr, ema → ta.ema, round → math.round.
  • 1 strategy call uses the when = argument (line 25). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 9: highest → ta.highest
  • Line 10: lowest → ta.lowest
  • Line 11: lowest → ta.lowest
  • Line 12: highest → ta.highest
  • Line 14: atr → ta.atr
3 more edits
  • Line 15: ema → ta.ema
  • Line 28: round → math.round
  • Line 36: round → math.round
⋯// © melodyera0822-//@version=4+//@version=5strategy("Richard Strategy", overlay=true)⋯// high_low-_20_day_highest = highest(nz(close[1]), lenght)+_20_day_highest = ta.highest(nz(close[1]), lenght)-_20_day_lowest = lowest(nz(close[1]), lenght)+_20_day_lowest = ta.lowest(nz(close[1]), lenght)-_10_day_low = lowest(nz(close[1]), lenght/2)+_10_day_low = ta.lowest(nz(close[1]), lenght/2)-_10_day_high = highest(nz(close[1]), lenght/2)+_10_day_high = ta.highest(nz(close[1]), lenght/2)//indicators-atr20 = atr(20)+atr20 = ta.atr(20)-ema_atr20 = ema(atr20,20)+ema_atr20 = ta.ema(atr20,20)//vars⋯    buy_sell := "buy"-    stoploss := round(close - variable_for_stoploss * ema_atr20)+    stoploss := math.round(close - variable_for_stoploss * ema_atr20)    ⋯    buy_sell := "sell"-    stoploss := round(close - variable_for_stoploss * ema_atr20)+    stoploss := math.round(close - variable_for_stoploss * ema_atr20)if traded == "true"⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 6: input() → input.int()
  • Line 7: input() → input.int()
  • Line 25: when = buyCon → if block
⋯// User input-variable_for_stoploss = input(4,title="stop loss var")+variable_for_stoploss = input.int(4,title="stop loss var")-lenght = input(20,title="lenght")+lenght = input.int(20,title="lenght")// high_low⋯if (buyCon)-    strategy.entry("long", strategy.long, when = buyCon)+    if buyCon+        strategy.entry("long", strategy.long)    traded := "true"⋯

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: 70 before, 84 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.

⋯// © melodyera0822-//@version=5+//@version=6strategy("Richard Strategy", overlay=true)⋯

Settings

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

SettingDefaultType and rangeFeeds
stop loss var4intstoploss
lenght20int_20_day_highest _20_day_lowest _10_day_low _10_day_high

What it calculates

  • Highest (highest, ta.highest in v5)nz(close[1]), lenght (20)_20_day_highest · line 9
  • Lowest (lowest, ta.lowest in v5)nz(close[1]), lenght (20)_20_day_lowest · line 10
  • Lowest (lowest, ta.lowest in v5)nz(close[1]), lenght/2_10_day_low · line 11
  • Highest (highest, ta.highest in v5)nz(close[1]), lenght/2_10_day_high · line 12
  • ATR (atr, ta.atr in v5)20atr20 · line 14
  • EMA (ema, ta.ema in v5)atr20, 20ema_atr20 · line 15

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.

closecloseprice datalenghtlenghtsetting · 20high · low · closehigh · low · closeprice datavariable_for_stoplossstop loss varsetting · 4_20_day_highestHighest→ _20_day_highest_20_day_lowestLowest→ _20_day_lowest_10_day_lowLowest→ _10_day_low_10_day_highHighest→ _10_day_highatr20ATR→ atr20ema_atr20EMA→ ema_atr20stoplossstoplossvaluebuyConbuyConconditionsellConsellConconditionentry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entryclose:longClose longstrategy.closeclose:shortClose shortstrategy.closeplotshape:23plotshapeplotshapeplotshape:31plotshapeplotshapeplotshape:48plotshapeplotshapeplotshape:50plotshapeplotshape

Order rules

OrderFires whenBy defaultLine
Open long longbuyConclose > _20_day_highest and traded == "false"On25
Open short short(sellCon)On33
Close longbuy_sell == "buy" and ((close<stoploss)or(close<_10_day_low))On39
Close shortbuy_sell == "sell" and ((close>stoploss)or(close>_10_day_high))On44

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.

21/21trades 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+34.6%+102.5%7070%1.3026.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+7.1%+5.5%7272%1.2111.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.3%+9.8%7474%0.953.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.1%+8.4%6461%0.930.6%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.2%+16.7%7679%1.750.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%7265%1.120.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.0%+148.3%7061%1.030.5%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.1%+17.1%7066%1.600.1%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 market1968%−$5,228.75
Sideways market3370%$27,278.20
Falling market1872%$12,544.40

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

How bad could the drawdown be?

38.6%

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

0%44%
All 70 trades
SideEntryExitBarsP&L
long15 Feb 2024 51,795.2017 Mar 2024 65,300.6031$13,505.50
long9 Apr 2024 71,620.0014 Apr 2024 63,924.505−$7,695.48
short16 Apr 2024 63,420.0018 Apr 2024 61,277.402$2,142.61
short1 May 2024 60,672.002 May 2024 58,365.001$2,307.04
long16 May 2024 66,206.501 Jun 2024 67,540.0016$1,333.50
short12 Jun 2024 67,314.2014 Jun 2024 66,773.002$541.22
short15 Jun 2024 66,044.0019 Jun 2024 65,175.304$868.67
short20 Jun 2024 64,974.4021 Jun 2024 64,870.001$104.38
short22 Jun 2024 64,143.6024 Jun 2024 63,210.002$933.55
short25 Jun 2024 60,293.304 Jul 2024 60,208.609$84.73
short5 Jul 2024 57,050.006 Jul 2024 56,628.801$421.23
short8 Jul 2024 55,857.8016 Jul 2024 64,724.108−$8,866.25
long16 Jul 2024 64,724.101 Aug 2024 64,628.0016−$96.05
short4 Aug 2024 60,698.005 Aug 2024 58,161.001$2,536.99
short6 Aug 2024 54,018.8024 Aug 2024 64,037.2018−$10,018.40
long24 Aug 2024 64,037.201 Sep 2024 58,974.008−$5,063.24
short2 Sep 2024 57,301.806 Sep 2024 56,180.004$1,121.77
short7 Sep 2024 53,963.0019 Sep 2024 61,760.0012−$7,797.01
long19 Sep 2024 61,760.002 Oct 2024 60,804.9013−$955.06
short10 Oct 2024 60,636.0011 Oct 2024 60,326.401$309.61
long15 Oct 2024 66,084.0022 Dec 2024 97,292.0068$31,208.00
short23 Dec 2024 95,186.3024 Dec 2024 94,881.501$304.81
short28 Dec 2024 94,299.0030 Dec 2024 93,738.202$560.84
short31 Dec 2024 92,792.1010 Jan 2025 92,552.5010$239.56
long18 Jan 2025 104,077.002 Feb 2025 100,636.0015−$3,441.81
short6 Feb 2025 96,612.407 Feb 2025 96,554.401$58.09
short8 Feb 2025 96,506.809 Feb 2025 96,444.801$62.05
short12 Feb 2025 95,778.2019 Feb 2025 95,671.707$106.47
short25 Feb 2025 91,552.9026 Feb 2025 88,680.401$2,872.49
short27 Feb 2025 84,250.1010 Mar 2025 80,734.5011$3,515.61
short11 Mar 2025 78,595.907 Apr 2025 78,430.0027$165.86
short9 Apr 2025 76,322.4022 Apr 2025 87,516.2013−$11,193.80
long22 Apr 2025 87,516.2031 May 2025 103,985.0039$16,469.30
short6 Jun 2025 101,509.0023 Jun 2025 100,964.0017$544.82
long3 Jul 2025 108,850.001 Aug 2025 115,764.0029$6,914.48
short2 Aug 2025 113,298.003 Aug 2025 112,546.001$751.57
long13 Aug 2025 120,134.0019 Aug 2025 116,227.006−$3,907.04
short22 Aug 2025 112,500.0026 Aug 2025 110,112.004$2,388.02
short30 Aug 2025 108,377.001 Sep 2025 108,246.002$131.04
long13 Sep 2025 116,029.0022 Sep 2025 115,232.009−$797.12
short26 Sep 2025 108,994.002 Oct 2025 118,595.006−$9,600.50
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$5,820.50
short17 Oct 2025 108,194.0018 Oct 2025 106,432.001$1,762.59
short5 Nov 2025 101,497.007 Nov 2025 101,346.002$151.19
short14 Nov 2025 99,692.0015 Nov 2025 94,594.001$5,098.03
short17 Nov 2025 94,261.4018 Nov 2025 92,215.101$2,046.31
short20 Nov 2025 91,555.0021 Nov 2025 86,637.201$4,917.74
short22 Nov 2025 85,129.4023 Nov 2025 84,739.801$389.67
short18 Dec 2025 86,243.2019 Dec 2025 85,516.401$726.82
long4 Jan 2026 90,628.0021 Jan 2026 88,427.7017−$2,200.35
short26 Jan 2026 86,670.4030 Jan 2026 84,650.204$2,020.20
short31 Jan 2026 84,260.501 Feb 2026 78,741.101$5,519.40
short2 Feb 2026 76,968.204 Feb 2026 75,770.202$1,198.01
short5 Feb 2026 73,165.806 Feb 2026 62,909.901$10,256.00
long5 Mar 2026 72,666.8022 Mar 2026 68,918.1017−$3,748.65
short30 Mar 2026 66,010.908 Apr 2026 71,924.209−$5,913.29
long8 Apr 2026 71,924.2016 May 2026 79,113.2038$7,188.98
short23 May 2026 75,539.5028 May 2026 74,449.305$1,090.19
short29 May 2026 73,617.5030 May 2026 73,460.801$156.74
short2 Jun 2026 71,408.903 Jun 2026 66,760.801$4,648.06
short4 Jun 2026 64,142.805 Jun 2026 63,886.001$256.76
short6 Jun 2026 61,056.507 Jun 2026 60,884.601$171.85
short26 Jun 2026 59,794.6029 Jun 2026 59,577.003$217.63
short1 Jul 2026 58,624.7015 Jul 2026 65,044.0014−$6,419.28
long15 Jul 2026 65,044.0028 Jul 2026 63,755.9013−$1,288.13
long20 Aug 2026 69,334.803 Sep 2026 77,340.0014$8,005.23
long4 Sep 2026 81,270.4011 Sep 2026 76,568.707−$4,701.64
short16 Sep 2026 75,644.5022 Sep 2026 86,620.006−$10,975.50
long22 Sep 2026 86,620.008 Oct 2026 83,321.8016−$3,298.20
short15 Oct 2026 81,682.0017 Oct 2026 81,615.902$66.11

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
Richard's Strategy this page—v4 strategy+34.6%7026.3%
Classic Long Term Trend Following System by Robrecht99ema highest lowest atrv5 strategy+2.9%51.1%
Strategy Myth-Busting #1 - UT Bot+STC+Hull [MYN] by myncryptoatr ema lowest highestv5 strategy−30.7%1063.5%
Strategy for UT Bot Alerts indicator by StrategiesForEveryoneema atr highest lowestv5 strategy−4.5%4215.7%
Simple and Profitable Scalping Strategy (ForexSignals TV) by kevinmck100ema atr highest lowestv5 strategyNo trades on this market
ATR + STC + MA by Romediusema lowest highest atrv5 strategy−1.2%153.3%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 15 msYes 1,000 bars in 28 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/// © melodyera0822//@version=4strategy("Richard Strategy", overlay=true)// User inputvariable_for_stoploss = input(4,title="stop loss var")lenght = input(20,title="lenght")// high_low_20_day_highest = highest(nz(close[1]), lenght)_20_day_lowest = lowest(nz(close[1]), lenght)_10_day_low = lowest(nz(close[1]), lenght/2)_10_day_high = highest(nz(close[1]), lenght/2)//indicatorsatr20 = atr(20)ema_atr20 = ema(atr20,20)//varsvar traded = "false"var buy_sell = "none"var buyExit = falsevar sellExit = falsevar stoploss = 0buyCon = close > _20_day_highest and traded == "false"plotshape(buyCon,style = shape.triangleup,location = location.belowbar, color = color.green )if (buyCon)    strategy.entry("long", strategy.long, when = buyCon)    traded := "true"    buy_sell := "buy"    stoploss := round(close - variable_for_stoploss * ema_atr20)    sellCon = close < _20_day_lowest and  traded == "false"plotshape(sellCon,style = shape.triangledown, color = color.red )if (sellCon)    strategy.entry("short", strategy.short)    traded := "true"    buy_sell := "sell"    stoploss := round(close - variable_for_stoploss * ema_atr20)if traded == "true"    if buy_sell == "buy" and ((close<stoploss)or(close<_10_day_low))        strategy.close("long")        buyExit := true        traded := "false"            if buy_sell == "sell" and ((close>stoploss)or(close>_10_day_high))        strategy.close("short")        sellExit := true        traded := "false"        plotshape(buyExit,style = shape.triangleup,location = location.belowbar, color = color.yellow )buyExit := falseplotshape(sellExit,style = shape.triangledown, color = color.yellow )sellExit := false