Pine Script v5 · Strategy
Previous Day High Low Strategy only for Long
A Pine Script v5 strategy built on RMA (ta.tr, len). It has 3 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade is 50 contracts and pays no commission. 4 settings; defaults include ADX period 9, DMI Length 11 and Max Profit 150.00.
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 Previous Day High Low Strategy only for Long repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did Previous Day High Low Strategy only for Long do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. On ETHUSDT 4h it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
- Does Previous Day High Low Strategy only for Long 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: 6 before, 5 after on ETHUSDT 4h, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Previous Day High Low Strategy only for Long use a stop loss?
- Yes
- strategy.exit sets a stop on line 77.
- Does Previous Day High Low Strategy only for Long run in Zeal Terminal?
- Yes
- It compiles in 61 ms and runs 1,000 bars in 88 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. 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 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.
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 |
|---|---|---|---|
| ADX period | 9 | int | up down adx ADX |
| DMI Length | 11 | int | up down plus minus ADX |
| Max Profit | 150.00 | float | T1 T2 T3 SL CP exit Exit Long Max Profit |
| Max SL | 15 | int | line 53 exit Exit Long Stop Loss |
What it calculates
- RMAta.tr, len
truerange · line 26 - RMAmath.abs(plus - minus) / (sum == 0 ? 1 : sum), ADX period (9)
adx · line 33
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 | (longCondition and TradeTime) | On | 62 |
| Exit Exit Long stop and limit | (strategy.position_size > 0) | On | 77 |
| Close Long | (strategy.position_size > 0 and time > CloseTime) | On | 79 |
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.
- ClearHigher-timeframe data1 request.security call(s), none with lookahead on.
- 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 | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.1% | +8.4% | 6 | 50% | 0.54 | 0.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 4 | 0% | 0.00 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 3 | 0% | 0.00 | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
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 |
|---|---|---|---|---|---|
| Previous Day High Low Strategy only for Long this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Wilder's Volatility Trailing Stop Strategy with various MA's by SparkyFlary | rma highest | v4 strategy | +16.9% | 15 | 41.6% |
| Simple RSI strategy by RafaelZioni | rma highest | v4 strategy | −11.0% | 119 | 24.4% |
| volume rsi strategy by pro trader123 by VSlip | highest rma | v5 strategy | −0.0% | 20 | 0.0% |
| HiLo Extension by Saravanan_Ragavan | highest rma | v4 strategy | No trades on this market | ||
| Directional Movement Index by wojak_bogdanoff | highest rma | v5 strategy | +49.7% | 35 | 19.4% |
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 settings use the untyped input() (line 21, 22, 42, 67). 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 6 trades and the same P&L on ETHUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 21: input() → input.int()
- Line 22: input() → input.int()
- Line 42: input() → input.float()
- Line 67: input() → input.int()
⋯//============================================= Market Strength ============================-LWadxlength = input(9, title='ADX period')+LWadxlength = input.int(9, title='ADX period')-LWdilength = input(11, title='DMI Length')+LWdilength = input.int(11, title='DMI Length')dirmov(len) =>⋯//========================== POSITIONS ================================-float MaxProfit = input(150.00,"Max Profit")+float MaxProfit = input.float(150.00,"Max Profit")float T1 = MaxProfit * 0.3⋯ CP := EP- SL := math.min(input(15,"Max SL"), MaxProfit * 0.4)+ SL := math.min(input.int(15,"Max SL"), MaxProfit * 0.4) if (high >= EP + T1) and CP < EP + T1⋯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: 6 before, 5 after on ETHUSDT 4h, 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.
⋯// © mangeshabhang19-//@version=5+//@version=6strategy("Previous Day High Low Strategy only for Long", overlay=true, margin_long=100, margin_short=0, calc_on_every_tick=true, default_qty_value = 50)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 61 ms | With a workaround 1,000 bars in 88 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
The engine and this page's reading of the source count a different number of settings, so one of them has missed one.
“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/// © mangeshabhang19//@version=5strategy("Previous Day High Low Strategy only for Long", overlay=true, margin_long=100, margin_short=0, calc_on_every_tick=true, default_qty_value = 50)[HH, LL] = request.security(syminfo.tickerid, '1D', [high, low], barmerge.gaps_off, barmerge.lookahead_off)OpenTime = timestamp(year, month, dayofmonth , 09, 30) CloseTime = timestamp(year, month, dayofmonth, 15, 10) ExitTime = timestamp(year, month, dayofmonth, 15, 15) TradeTime = time >= OpenTime and time <= CloseTimeUW = open > close ? high - open : high - closeLW = open > close ? close - low : open - lowBody = open > close ? open - close : close - openUWP = (UW / (LW + UW)) * 100LWP = (LW / (LW + UW)) * 100longCondition = ta.crossover(close, HH)longCondition := longCondition or ta.crossover(close, LL)longCondition := longCondition //and high == closeplot(HH, color=color.red,linewidth = 1)plot(LL, color=color.red,linewidth = 1) //============================================= Market Strength ============================LWadxlength = input(9, title='ADX period')LWdilength = input(11, title='DMI Length')dirmov(len) => up = ta.change(high) down = -ta.change(low) truerange = ta.rma(ta.tr, len) plus = fixnan(100 * ta.rma(up > down and up > 0 ? up : 0, len) / truerange) minus = fixnan(100 * ta.rma(down > up and down > 0 ? down : 0, len) / truerange) [plus, minus]adx(LWdilength, LWadxlength) => [plus, minus] = dirmov(LWdilength) sum = plus + minus adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), LWadxlength) [adx, plus, minus][ADX, up, down] = adx(LWdilength, LWadxlength)LWADX = (ADX - 15) * 2.5adxcolor = up > down ? color.green : color.redstrength_up = LWADX > 11 and up > down and LWADX > ta.highest(LWADX[1],4)longCondition := longCondition and strength_up // and close>= high-input(15,'LW Size') plotshape(longCondition, title="Buy Signal", location=location.belowbar, color=color.green, textcolor = color.white, style=shape.labelup, text="BUY")//========================== POSITIONS ================================float MaxProfit = input(150.00,"Max Profit")float T1 = MaxProfit * 0.3float T2 = MaxProfit * 0.5float T3 = MaxProfit * 0.8float SL = nafloat CP = nafloat EP = naif not na(EP[1]) EP := EP[1]if not na(CP[1]) CP := CP[1]if not na(SL[1]) SL := SL[1]// Execute strategy on tickif (barstate.isconfirmed) if (strategy.position_size == 0) EP := na CP := na SL := na if (longCondition and TradeTime) strategy.entry("Long", strategy.long)if (strategy.position_size > 0) if na(EP[1]) EP := strategy.position_avg_price CP := EP SL := math.min(input(15,"Max SL"), MaxProfit * 0.4) if (high >= EP + T1) and CP < EP + T1 CP := EP + T1 SL := CP-EP//SL * 0.8 if (high >= EP + T2) and CP < EP + T2 CP := EP + T2 SL := CP-EP-T1//SL * 0.8 if (high >= EP + T3) and CP < EP + T3 CP := EP + MaxProfit SL := CP-EP-T2//SL * 0.8 strategy.exit("Exit Long", "Long", limit = EP + MaxProfit, stop =CP-SL)if (strategy.position_size > 0 and time > CloseTime) strategy.close("Long")//PLOTplot(CP, title="Stop Loss", color=color.yellow, linewidth=1, style = plot.style_linebr)plot(EP, title="Stop Loss", color=color.white, linewidth=1, style = plot.style_linebr)plot(CP - SL, title="Stop Loss", color=color.red, linewidth=1, style = plot.style_linebr)plot(EP + T1, title="Target 1", color=color.blue, linewidth=1, style = plot.style_linebr)plot(EP + T2, title="Target 2", color=color.blue, linewidth=1, style = plot.style_linebr)plot(EP + T3, title="Target 3", color=color.blue, linewidth=1, style = plot.style_linebr)plot(EP + MaxProfit, title="Max Profit", color=color.green, linewidth=1, style = plot.style_linebr)