Pine Script v5 · Strategy
Low-High-Trend Strategy
A Pine Script v5 strategy with no technical-analysis calculation. It has 5 order rules, 2 entries among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 1 commission. 8 settings; defaults include Lowest Price Lookback 20, Highest Price Lookback 10 and Take Profit % 8.
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 Low-High-Trend Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
- How did Low-High-Trend Strategy do on BTCUSDT 1D with default settings?
- +57.96%
- From 26 Jan 2024 to 21 Oct 2026, over 5 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Low-High-Trend Strategy run in Pine Script v6?
- Yes
- Same 5 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
- Does Low-High-Trend Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Low-High-Trend Strategy run in Zeal Terminal?
- Yes
- It compiles in 16 ms and runs 1,000 bars in 46 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +57.96%
- $57,963,000.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 5
- 5 won · 0 lost
- Profitable
- 100.0%
- of closed trades
- Profit factor
- 57,963,000.00
- gross profit ÷ gross loss
- Max drawdown
- 24.48%
- −$26,471,500.00
One run with the author's default settings, $100,000,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
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
Uses an argument v6 removed
when = on line 24, 26, 28, 30. 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Start Time | timestamp('01 Jan 2000 05:00 +0000') | time | InDateRange |
| End Time | timestamp('01 Jan 2099 00:00 +0000') | time | InDateRange |
| Lowest Price LookbackThe strategy will BUY when the price crosses over the lowest it has been in the last X amount of bars | 20 | int | plot entry Long |
| Highest Price LookbackIf Take-Profit is not checked, the strategy will SELL when the price crosses under the highest it has been in the last X amount of bars | 10 | int | plot close Long |
| Sell with Take-Profit % intead of highest price cross? | true | bool | close Long close Long line 27 line 29 |
| Take Profit % | 8 | float · step .25 | close Long |
| Only buy when price is above EMA trend? | true | bool | entry Long entry Long line 23 line 25 |
| EMA Length | 200 | int | TrendisLong plot |
What it calculates
No technical-analysis calculation: the script works on prices and settings directly.
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 Long long | ta.crossover(close, lowcriteria) and TrendisLong | On | 24 |
| Open Long long | ta.crossover(close, lowcriteria) | On | 26 |
| Close Long | TakeProfit | On | 28 |
| Close Long | ta.crossunder(close, highcriteria) | On | 30 |
| Close | (not InDateRange) | On | 32 |
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.
- 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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 | +58.0% | +102.5% | 5 | 100% | 57,963,000.00 | 24.5% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +20.5% | +5.5% | 2 | 100% | 20,482,700.00 | 4.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +20.3% | +9.8% | 2 | 100% | 20,322,900.00 | 63.7% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +30.5% | +8.4% | 3 | 100% | 30,473,400.00 | 13.6% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +39.3% | +16.7% | 3 | 100% | 39,278,100.00 | 69.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +19.2% | +21.5% | 2 | 100% | 19,154,200.00 | 16.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +21.3% | +148.3% | 2 | 100% | 21,255,800.00 | 44.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +29.0% | +17.1% | 3 | 100% | 29,014,600.00 | 7.6% | 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 | 4 | 100% | $49,840,200.00 |
| Sideways market | 1 | 100% | $8,122,780.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 5 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 5 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 11 Oct 2024 62,540.00 | 16 Oct 2024 67,620.00 | 5 | $8,122,780.00 |
| long | 24 Dec 2024 98,663.60 | 20 May 2025 106,850.00 | 147 | $8,971,240.00 |
| long | 6 Jun 2025 104,288.00 | 10 Jul 2025 116,010.00 | 34 | $13,160,800.00 |
| long | 3 Aug 2025 114,209.00 | 5 Oct 2025 123,482.00 | 63 | $10,576,400.00 |
| long | 11 Sep 2026 77,225.70 | 21 Sep 2026 86,620.00 | 10 | $17,131,700.00 |
Similar scripts
No other indicator or strategy here shares enough of its calculations.
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.
- 4 strategy calls use the when = argument (line 24, 26, 28, 30). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 5 settings use the untyped input() (line 10, 11, 15, 18, 19). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 5 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 10: input() → input.int()
- Line 11: input() → input.int()
- Line 15: input() → input.bool()
- Line 18: input() → input.bool()
- Line 19: input() → input.int()
- Line 24: when = ta.crossover(close, lowcriteria) and TrendisLong → if block
3 more edits
- Line 26: when = ta.crossover(close, lowcriteria) → if block
- Line 28: when = TakeProfit → if block
- Line 30: when = ta.crossunder(close, highcriteria) → if block
⋯// Strategy Calculations //-lowcriteria = ta.lowest(close, input(20, "Lowest Price Lookback", tooltip="The strategy will BUY when the price crosses over the lowest it has been in the last X amount of bars"))[1]+lowcriteria = ta.lowest(close, input.int(20, "Lowest Price Lookback", tooltip="The strategy will BUY when the price crosses over the lowest it has been in the last X amount of bars"))[1]-highcriteria = ta.highest(close, input(10, "Highest Price Lookback", tooltip="If Take-Profit is not checked, the strategy will SELL when the price crosses under the highest it has been in the last X amount of bars"))[1]+highcriteria = ta.highest(close, input.int(10, "Highest Price Lookback", tooltip="If Take-Profit is not checked, the strategy will SELL when the price crosses under the highest it has been in the last X amount of bars"))[1]plot(highcriteria, color=color.green)⋯// Take Profit //-TakeProfitInput = input(true, "Sell with Take-Profit % intead of highest price cross?")+TakeProfitInput = input.bool(true, "Sell with Take-Profit % intead of highest price cross?")TakeProfit = ta.crossover(close,strategy.position_avg_price*(1+(.01*input.float(8, title="Take Profit %", step=.25))))// Operational Functions //-TrendFilterInput = input(true, "Only buy when price is above EMA trend?")+TrendFilterInput = input.bool(true, "Only buy when price is above EMA trend?")-ema = ta.ema(close, input(200, "EMA Length"))+ema = ta.ema(close, input.int(200, "EMA Length"))TrendisLong = (close>ema)⋯if (InDateRange and TrendFilterInput==true)- strategy.entry("Long", strategy.long, when = ta.crossover(close, lowcriteria) and TrendisLong)+ if ta.crossover(close, lowcriteria) and TrendisLong+ strategy.entry("Long", strategy.long)if (InDateRange and TrendFilterInput==false)- strategy.entry("Long", strategy.long, when = ta.crossover(close, lowcriteria))+ if ta.crossover(close, lowcriteria)+ strategy.entry("Long", strategy.long)if (InDateRange and TakeProfitInput==true)- strategy.close("Long", when = TakeProfit)+ if TakeProfit+ strategy.close("Long")if (InDateRange and TakeProfitInput==false)- strategy.close("Long", when = ta.crossunder(close, highcriteria))+ if ta.crossunder(close, highcriteria)+ strategy.close("Long")if (not InDateRange)⋯Does it run in Pine Script v6?
Yes
Same 5 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-// @version=5+// @version=6// Author = TradeAutomation⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 16 ms | Yes 1,000 bars in 46 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
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/// @version=5// Author = TradeAutomationstrategy(title="Low-High-Trend Strategy", shorttitle="Low-High-Trend Strategy", process_orders_on_close=true, overlay=true, commission_type=strategy.commission.cash_per_order, commission_value=1, slippage=1, initial_capital = 100000000, margin_long=50, margin_short=50, default_qty_type=strategy.percent_of_equity, default_qty_value=100)// Backtest Date Range Inputs // StartTime = input.time(defval=timestamp('01 Jan 2000 05:00 +0000'), title='Start Time')EndTime = input.time(defval=timestamp('01 Jan 2099 00:00 +0000'), title='End Time')InDateRange = time>=StartTime and time<=EndTime// Strategy Calculations //lowcriteria = ta.lowest(close, input(20, "Lowest Price Lookback", tooltip="The strategy will BUY when the price crosses over the lowest it has been in the last X amount of bars"))[1]highcriteria = ta.highest(close, input(10, "Highest Price Lookback", tooltip="If Take-Profit is not checked, the strategy will SELL when the price crosses under the highest it has been in the last X amount of bars"))[1]plot(highcriteria, color=color.green)plot(lowcriteria, color=color.red)// Take Profit //TakeProfitInput = input(true, "Sell with Take-Profit % intead of highest price cross?")TakeProfit = ta.crossover(close,strategy.position_avg_price*(1+(.01*input.float(8, title="Take Profit %", step=.25))))// Operational Functions //TrendFilterInput = input(true, "Only buy when price is above EMA trend?")ema = ta.ema(close, input(200, "EMA Length"))TrendisLong = (close>ema)plot(ema)// Entry & Exit Functions//if (InDateRange and TrendFilterInput==true) strategy.entry("Long", strategy.long, when = ta.crossover(close, lowcriteria) and TrendisLong)if (InDateRange and TrendFilterInput==false) strategy.entry("Long", strategy.long, when = ta.crossover(close, lowcriteria))if (InDateRange and TakeProfitInput==true) strategy.close("Long", when = TakeProfit)if (InDateRange and TakeProfitInput==false) strategy.close("Long", when = ta.crossunder(close, highcriteria))if (not InDateRange) strategy.close_all()