Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (4)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctPlot$1,472$2,025Equity from $1,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
+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

Verified

Same 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⋯

Clean v5

VerifiedDownload the v5 script

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.

SettingDefaultType and rangeFeeds
Range of candles to find highest value from.90int (written input.integer) · min 1three_months_top
Basis points, if asset has two decimals use 100, three decimals 1000, etc.100int (written input.integer) · min 1exit TP1
Percent value retrace from the top.3int (written input.integer) · min 1 · max 99unused
Percent value of take profit from entry price.6int (written input.integer) · min 1longCondition1 exit TP1

What it calculates

  • Highest (highest, ta.highest in 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.

range_of_topsRange of candles to fin…setting · 90closecloseprice datatake_profit_percentPercent value of take p…setting · 6three_months_topHighest→ three_months_toplongCondition1longCondition1conditionentry:Long1Open Long1strategy.entryexit:TP1exit TP1strategy.exitplot:19plotplot

Order rules

OrderFires whenBy defaultLine
Open Long1 long(longCondition1)On15
Exit TP1 limitcrossover(strategy.position_size, 0)On16

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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+96.1%+102.5%12100%490.5248.8%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+11.8%+5.5%2100%106.6022.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+74.9%+9.8%10100%428.7766.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+25.3%+8.4%4100%202.9925.9%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+56.0%+16.7%8100%359.7276.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+32.4%+21.5%5100%245.6030.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+46.6%+148.3%7100%318.5955.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+25.4%+17.1%4100%203.1921.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 barsTradesWonP&L
Rising market10100%$766.77
Sideways market2100%$196.00
Falling market0—$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.

0%1%
All 12 trades
SideEntryExitBarsP&L
long25 Apr 2024 64,289.6020 May 2024 68,159.5025$58.13
long23 May 2024 69,166.6029 Oct 2024 73,244.80159$60.21
long4 Nov 2024 68,776.006 Nov 2024 72,847.002$63.89
long15 Nov 2024 87,325.6019 Nov 2024 92,787.504$71.51
long26 Nov 2024 93,010.0029 Nov 2024 98,527.903$71.80
long6 Dec 2024 96,945.6015 Dec 2024 102,930.009$79.09
long19 Dec 2024 100,204.0019 Jan 2025 106,052.0031$79.08
long20 Jan 2025 101,332.0021 May 2025 107,467.00121$86.78
long31 May 2025 103,985.009 Jun 2025 110,261.009$91.54
long18 Jun 2025 104,551.009 Jul 2025 110,844.0021$96.62
long1 Aug 2025 115,764.0013 Aug 2025 122,562.0012$99.65
long19 Aug 2025 116,227.003 Oct 2025 122,999.0045$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.

ScriptSharesTypeNetTradesMax drawdown
test_-_down_up this page—v4 strategy+96.1%1248.8%
ATR Trailing Stoploss Strategy by ceyhunhighestv4 strategy−17.6%10265.4%
Ichimoku Cloud by Zeal Terminalhighestv5 indicatorindicator
Alex Days HiLo Rajib by 14rajibhighestv4 strategyNo trades on this market
Donchian Strat EXMO by pskoroplashighestv4 strategy+12.1%2268.0%
Average Highest High and Lowest Low Swinger Strategy by exlux99highestv4 strategy+6.4%2049.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 7 msYes 1,000 bars in 22 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/// © 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)