Pine Script v4 · Strategy
test_-_down_up
A Pine Script v4 strategy built on Highest (90). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits use a profit target and no stop loss. Each trade commits 1000 in cash and pays 0.1% commission. 4 settings; defaults include Range of candles to find highest value from. 90, Basis points, if asset has two decimals use 100, three decimals 1000, etc. 100 and Percent value retrace from the top. 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 test_-_down_up repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did test_-_down_up do on BTCUSDT 1D with default settings?
- +96.08%
- From 26 Jan 2024 to 21 Oct 2026, over 12 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can test_-_down_up 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 test_-_down_up use a stop loss?
- No
- Its exits set a profit target but no stop.
- Does test_-_down_up run in Zeal Terminal?
- Yes
- It compiles in 7 ms and runs 1,000 bars in 22 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +96.08%
- $960.81
- Buy and hold
- +102.5%
- same period
- Closed trades
- 12
- 12 won · 0 lost
- Profitable
- 100.0%
- of closed trades
- Profit factor
- 490.52
- gross profit ÷ gross loss
- Max drawdown
- 48.85%
- −$958.76
One run with the author's default settings, $1,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.
-
Check
1 setting does nothing
“Percent value retrace from the top.” is declared but never read.
-
Check
No stop loss
strategy.exit is used without a stop, loss or trailing stop.
-
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 16. 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, crossover → ta.crossover.
- 1 strategy call uses the when = argument (line 16). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 12 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: input(type = input.integer) → input.int()
- Line 8: input(type = input.integer) → input.int()
- Line 9: input(type = input.integer) → input.int()
- Line 10: input(type = input.integer) → input.int()
- Line 12: highest → ta.highest
- Line 17: crossover → ta.crossover
⋯// © luboremenar-//@version=4+//@version=5strategy("test_%_down_up", overlay = false, initial_capital = 1000, pyramiding = 0, default_qty_value = 1000,⋯// inputs-range_of_tops = input(title="Range of candles to find highest value from.", defval=90, type=input.integer, minval=1 )+range_of_tops = input.int(title="Range of candles to find highest value from.", defval=90, minval=1 )-basis_points = input(title="Basis points, if asset has two decimals use 100, three decimals 1000, etc.", defval=100, type=input.integer, minval=1)+basis_points = input.int(title="Basis points, if asset has two decimals use 100, three decimals 1000, etc.", defval=100, minval=1)-retrace_percent = input(title="Percent value retrace from the top.", type=input.integer, defval=3, minval = 1, maxval=99)+retrace_percent = input.int(title="Percent value retrace from the top.", defval=3, minval = 1, maxval=99)-take_profit_percent = input(title="Percent value of take profit from entry price.", type=input.integer, defval=6, minval=1)+take_profit_percent = input.int(title="Percent value of take profit from entry price.", defval=6, minval=1)// strategy definition-three_months_top = highest(range_of_tops)+three_months_top = ta.highest(range_of_tops)longCondition1 = (close <= float((three_months_top*(1-(take_profit_percent/100)))) and strategy.position_size == 0)⋯strategy.exit(id="TP1", from_entry="Long1", profit=((close*(1 + take_profit_percent/100)-close)*basis_points),- when= crossover(strategy.position_size, 0))+ when= ta.crossover(strategy.position_size, 0))// plot⋯Same 12 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 16: when = ta.crossover(strategy.position_size, 0) → if block
⋯ strategy.entry("Long1", strategy.long, qty = strategy.equity/close)-strategy.exit(id="TP1", from_entry="Long1", profit=((close*(1 + take_profit_percent/100)-close)*basis_points),- when= ta.crossover(strategy.position_size, 0))+if ta.crossover(strategy.position_size, 0)+ strategy.exit(id="TP1", from_entry="Long1", profit=((close*(1 + take_profit_percent/100)-close)*basis_points))// plot⋯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: 12 before, 485 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.
⋯// © luboremenar-//@version=5+//@version=6strategy("test_%_down_up", overlay = false, initial_capital = 1000, pyramiding = 0, default_qty_value = 1000,⋯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 |
|---|---|---|---|
| Range of candles to find highest value from. | 90 | int (written input.integer) · min 1 | three_months_top |
| Basis points, if asset has two decimals use 100, three decimals 1000, etc. | 100 | int (written input.integer) · min 1 | exit TP1 |
| Percent value retrace from the top. | 3 | int (written input.integer) · min 1 · max 99 | unused |
| Percent value of take profit from entry price. | 6 | int (written input.integer) · min 1 | longCondition1 exit TP1 |
What it calculates
- Highest (
highest,ta.highestin v5)Range of candles to find highest value from. (90)three_months_top · line 12
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 Long1 long | (longCondition1) | On | 15 |
| Exit TP1 limit | crossover(strategy.position_size, 0) | On | 16 |
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.
- 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 | +96.1% | +102.5% | 12 | 100% | 490.52 | 48.8% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +11.8% | +5.5% | 2 | 100% | 106.60 | 22.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +74.9% | +9.8% | 10 | 100% | 428.77 | 66.7% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +25.3% | +8.4% | 4 | 100% | 202.99 | 25.9% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +56.0% | +16.7% | 8 | 100% | 359.72 | 76.7% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +32.4% | +21.5% | 5 | 100% | 245.60 | 30.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +46.6% | +148.3% | 7 | 100% | 318.59 | 55.6% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +25.4% | +17.1% | 4 | 100% | 203.19 | 21.8% | 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 | 10 | 100% | $766.77 |
| Sideways market | 2 | 100% | $196.00 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
0.0%
The 95th percentile of the worst drawdown when the same 12 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.0% to 0.0%; the tick is what actually happened, 0.0%. Order luck alone moves it this much.
All 12 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 25 Apr 2024 64,289.60 | 20 May 2024 68,159.50 | 25 | $58.13 |
| long | 23 May 2024 69,166.60 | 29 Oct 2024 73,244.80 | 159 | $60.21 |
| long | 4 Nov 2024 68,776.00 | 6 Nov 2024 72,847.00 | 2 | $63.89 |
| long | 15 Nov 2024 87,325.60 | 19 Nov 2024 92,787.50 | 4 | $71.51 |
| long | 26 Nov 2024 93,010.00 | 29 Nov 2024 98,527.90 | 3 | $71.80 |
| long | 6 Dec 2024 96,945.60 | 15 Dec 2024 102,930.00 | 9 | $79.09 |
| long | 19 Dec 2024 100,204.00 | 19 Jan 2025 106,052.00 | 31 | $79.08 |
| long | 20 Jan 2025 101,332.00 | 21 May 2025 107,467.00 | 121 | $86.78 |
| long | 31 May 2025 103,985.00 | 9 Jun 2025 110,261.00 | 9 | $91.54 |
| long | 18 Jun 2025 104,551.00 | 9 Jul 2025 110,844.00 | 21 | $96.62 |
| long | 1 Aug 2025 115,764.00 | 13 Aug 2025 122,562.00 | 12 | $99.65 |
| long | 19 Aug 2025 116,227.00 | 3 Oct 2025 122,999.00 | 45 | $104.46 |
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 |
|---|---|---|---|---|---|
| test_-_down_up this page | — | v4 strategy | +96.1% | 12 | 48.8% |
| ATR Trailing Stoploss Strategy by ceyhun | highest | v4 strategy | −17.6% | 102 | 65.4% |
| Ichimoku Cloud by Zeal Terminal | highest | v5 indicator | indicator | ||
| Alex Days HiLo Rajib by 14rajib | highest | v4 strategy | No trades on this market | ||
| Donchian Strat EXMO by pskoroplas | highest | v4 strategy | +12.1% | 22 | 68.0% |
| Average Highest High and Lowest Low Swinger Strategy by exlux99 | highest | v4 strategy | +6.4% | 20 | 49.6% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 7 ms | Yes 1,000 bars in 22 ms | Not measured |
| PineTS | No 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/// © luboremenar//@version=4strategy("test_%_down_up", overlay = false, initial_capital = 1000, pyramiding = 0, default_qty_value = 1000, default_qty_type = strategy.cash, precision = 8, commission_type = strategy.commission.percent, commission_value = 0.1)// inputsrange_of_tops = input(title="Range of candles to find highest value from.", defval=90, type=input.integer, minval=1 )basis_points = input(title="Basis points, if asset has two decimals use 100, three decimals 1000, etc.", defval=100, type=input.integer, minval=1)retrace_percent = input(title="Percent value retrace from the top.", type=input.integer, defval=3, minval = 1, maxval=99)take_profit_percent = input(title="Percent value of take profit from entry price.", type=input.integer, defval=6, minval=1)// strategy definitionthree_months_top = highest(range_of_tops)longCondition1 = (close <= float((three_months_top*(1-(take_profit_percent/100)))) and strategy.position_size == 0)if (longCondition1) strategy.entry("Long1", strategy.long, qty = strategy.equity/close)strategy.exit(id="TP1", from_entry="Long1", profit=((close*(1 + take_profit_percent/100)-close)*basis_points), when= crossover(strategy.position_size, 0))// plotplot(strategy.equity)// for testing, debugging//test=0.0 //if(crossover(strategy.position_size, 0))// test := (close*1.06-close)*basis_points//plot(test)