Pine Script v5 · Strategy
Daily HIGH-LOW strategy
A Pine Script v5 strategy built on EMA (close, 24). 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 commits 100% of equity and pays 0.1% commission. 3 settings; defaults include Length MA 24, Source MA close and CMF Length 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 Daily HIGH-LOW strategy repaint?
- Yes
- At least one pattern in the source can repaint: higher-timeframe data, intrabar recalculation.
- How did Daily HIGH-LOW strategy do on BTCUSDT 1D with default settings?
- +53.90%
- From 26 Jan 2024 to 21 Oct 2026, over 25 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Daily HIGH-LOW strategy 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: 25 before, 62 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Daily HIGH-LOW strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Daily HIGH-LOW strategy run in Zeal Terminal?
- Yes
- It compiles in 14 ms and runs 1,000 bars in 46 ms, in the browser.
BTCUSDT · 1D · default settings
- Previous Daily High
- Previous Daily Low
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +53.90%
- $5,389.76
- Buy and hold
- +102.5%
- same period
- Closed trades
- 25
- 9 won · 16 lost
- Profitable
- 36.0%
- of closed trades
- Profit factor
- 1.30
- gross profit ÷ gross loss
- Max drawdown
- 35.95%
- −$7,924.68
One run with the author's default settings, $10,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
Every trade uses all the equity
default_qty_value is 100% of equity.
-
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 21, 22, 24, 25. 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 |
|---|---|---|---|
| Optimization paramters | |||
| Length MA | 24 | int · min 1 | out |
| Source MA | close | source | out |
| CMF Length | 20 | int · min 1 | mf |
What it calculates
- EMASource MA (close), Length MA (24)
out · line 8
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 short short | barstate.isconfirmed | On | 21 |
| Close short | close > out | On | 22 |
| Open long long | barstate.isconfirmed | On | 24 |
| Close long | close < out | On | 25 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- CheckHigher-timeframe data1 request.security call(s) use lookahead_on (line 13). Without a [1] offset this reads future bars in history.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- CheckIntrabar recalculationcalc_on_every_tick = true. Live values can differ from history.
- 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 | +53.9% | +102.5% | 25 | 36% | 1.30 | 35.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +38.9% | +5.5% | 18 | 50% | 2.59 | 8.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +11.4% | +9.8% | 33 | 33% | 1.04 | 64.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −4.5% | +8.4% | 29 | 28% | 0.95 | 32.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +511.7% | +16.7% | 29 | 52% | 3.47 | 42.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +18.6% | +21.5% | 21 | 43% | 1.31 | 25.3% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +34.8% | +148.3% | 31 | 32% | 1.18 | 46.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +22.7% | +17.1% | 25 | 44% | 1.73 | 15.2% | 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 | 2 | 100% | $4,115.40 |
| Sideways market | 13 | 46% | $10,086.30 |
| Falling market | 10 | 10% | −$8,796.49 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
55.2%
The 95th percentile of the worst drawdown when the same 25 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 29.1% to 55.2%; the tick is what actually happened, 32.3%. Order luck alone moves it this much.
All 25 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 20 Feb 2024 52,572.10 | 12 Jun 2024 67,314.20 | 113 | $2,778.60 |
| short | 12 Jun 2024 67,314.20 | 20 Jul 2024 66,660.00 | 38 | $98.76 |
| long | 20 Jul 2024 66,660.00 | 12 Aug 2024 58,712.60 | 23 | −$1,559.47 |
| short | 12 Aug 2024 58,712.60 | 24 Aug 2024 64,037.20 | 12 | −$1,050.08 |
| long | 24 Aug 2024 64,037.20 | 1 Sep 2024 57,860.00 | 8 | −$1,010.21 |
| short | 1 Sep 2024 57,860.00 | 18 Sep 2024 60,395.80 | 17 | −$433.94 |
| long | 18 Sep 2024 60,395.80 | 7 Feb 2025 96,150.00 | 142 | $5,209.21 |
| short | 7 Feb 2025 96,150.00 | 20 Mar 2025 86,845.90 | 41 | $1,336.81 |
| long | 20 Mar 2025 86,845.90 | 3 Apr 2025 81,278.50 | 14 | −$1,014.88 |
| short | 3 Apr 2025 81,278.50 | 12 Apr 2025 83,588.00 | 9 | −$443.66 |
| long | 12 Apr 2025 83,588.00 | 19 Aug 2025 116,227.00 | 129 | $5,410.52 |
| short | 19 Aug 2025 116,227.00 | 16 Sep 2025 116,299.00 | 28 | −$50.58 |
| long | 16 Sep 2025 116,299.00 | 30 Oct 2025 107,403.00 | 44 | −$1,523.57 |
| short | 30 Oct 2025 107,403.00 | 12 Jan 2026 92,082.60 | 74 | $2,502.45 |
| long | 12 Jan 2026 92,082.60 | 26 Jan 2026 86,670.40 | 14 | −$1,239.94 |
| short | 26 Jan 2026 86,670.40 | 5 Mar 2026 72,666.80 | 38 | $3,036.59 |
| long | 5 Mar 2026 72,666.80 | 22 Mar 2026 68,793.40 | 17 | −$1,217.75 |
| short | 22 Mar 2026 68,793.40 | 17 Apr 2026 76,038.00 | 26 | −$2,241.41 |
| long | 17 Apr 2026 76,038.00 | 23 May 2026 75,539.50 | 36 | −$161.24 |
| short | 23 May 2026 75,539.50 | 11 Jul 2026 64,161.70 | 49 | $2,741.33 |
| long | 11 Jul 2026 64,161.70 | 28 Jul 2026 63,755.90 | 17 | −$176.05 |
| short | 28 Jul 2026 63,755.90 | 8 Aug 2026 65,025.20 | 11 | −$460.34 |
| long | 8 Aug 2026 65,025.20 | 14 Aug 2026 63,238.00 | 6 | −$605.81 |
| short | 14 Aug 2026 63,238.00 | 25 Aug 2026 78,992.80 | 11 | −$5,029.00 |
| long | 25 Aug 2026 78,992.80 | 13 Oct 2026 81,850.00 | 49 | $508.83 |
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 |
|---|---|---|---|---|---|
| Daily HIGH-LOW strategy this page | — | v5 strategy | +53.9% | 25 | 35.9% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
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 21, 22, 24, 25). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- No v6-only features. v6 is not needed to run this script.
Same 25 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 21: when = barstate.isconfirmed → if block
- Line 22: when = close > out → if block
- Line 24: when = barstate.isconfirmed → if block
- Line 25: when = close < out → if block
⋯if short and barstate.isconfirmed- strategy.entry('short', strategy.short, when=barstate.isconfirmed, stop=pricelow[1])+ if barstate.isconfirmed+ strategy.entry('short', strategy.short, stop=pricelow[1])- strategy.close('short', when=close > out)+ if close > out+ strategy.close('short')if long and barstate.isconfirmed- strategy.entry('long', strategy.long, when=barstate.isconfirmed, stop=pricehigh[1])+ if barstate.isconfirmed+ strategy.entry('long', strategy.long, stop=pricehigh[1])- strategy.close('long', when=close < out)+ if close < out+ strategy.close('long')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: 25 before, 62 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.
⋯// © exlux99-//@version=5+//@version=6strategy(title='Daily HIGH/LOW strategy', overlay=true, initial_capital=10000, calc_on_every_tick=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 14 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/// © exlux99//@version=5strategy(title='Daily HIGH/LOW strategy', overlay=true, initial_capital=10000, calc_on_every_tick=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)////////////////////////////GENERAL INPUTS//////////////////////////////////////len = input.int(24, minval=1, title='Length MA', group='Optimization paramters')src = input.source(close, title='Source MA', group='Optimization paramters')out = ta.ema(src, len)length = input.int(20, minval=1, title='CMF Length', group='Optimization paramters')ad = close == high and close == low or high == low ? 0 : (2 * close - low - high) / (high - low) * volumemf = math.sum(ad, length) / math.sum(volume, length)f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[1], lookahead=barmerge.lookahead_on)pricehigh = f_secureSecurity(syminfo.tickerid, 'D', high)pricelow = f_secureSecurity(syminfo.tickerid, 'D', low)plot(pricehigh, title='Previous Daily High', style=plot.style_linebr, linewidth=2, color=color.new(color.white, 0))plot(pricelow, title='Previous Daily Low', style=plot.style_linebr, linewidth=2, color=color.new(color.white, 0))short = ta.crossunder(low, pricelow) and close < out and mf < 0long = ta.crossover(high, pricehigh) and close > out and mf > 0if short and barstate.isconfirmed strategy.entry('short', strategy.short, when=barstate.isconfirmed, stop=pricelow[1]) strategy.close('short', when=close > out)if long and barstate.isconfirmed strategy.entry('long', strategy.long, when=barstate.isconfirmed, stop=pricehigh[1]) strategy.close('long', when=close < out)