Pine Script v4 · Strategy
longWickStrategy
A Pine Script v4 strategy with no technical-analysis calculation. It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 0.1% of equity and pays no commission. 7 settings; defaults include Backtest Start Year 2020, Backtest Start Month 01 and Backtest Start Day 01.
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 longWickStrategy repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did longWickStrategy do on BTCUSDT 1D with default settings?
- −0.01%
- From 26 Jan 2024 to 21 Oct 2026, over 37 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can longWickStrategy be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
- Does longWickStrategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 38, 39.
- Does longWickStrategy run in Zeal Terminal?
- Yes
- It compiles in 14 ms and runs 1,000 bars in 43 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Plot
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −0.01%
- −$7.90
- Buy and hold
- +102.5%
- same period
- Closed trades
- 37
- 15 won · 22 lost
- Profitable
- 40.5%
- of closed trades
- Profit factor
- 0.82
- gross profit ÷ gross loss
- Max drawdown
- 0.02%
- −$20.24
One run with the author's default settings, $100,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.
-
Note
Uses an argument v6 removed
when = on line 32, 33. 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 max → math.max, atr → ta.atr, abs → math.abs.
- 2 strategy calls use the when = argument (line 32, 33). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
DiffersTrades differ: 37 before, 37 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 24: max → math.max
- Line 27: atr → ta.atr
- Line 45: abs → math.abs
- Line 47: abs → math.abs
⋯// © ondrej17-//@version=4+//@version=5strategy("longWickstrategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=0.1)⋯upperWick = (open > close) ? high-open : high-close-wickLength = max(lowerWick,upperWick)+wickLength = math.max(lowerWick,upperWick)candleLength = high-lowwickToCandleRatio = wickLength / candleLength-entryFilterCandleLength = candleLength > 0.75*atr(48)+entryFilterCandleLength = candleLength > 0.75*ta.atr(48)// Entries and Exits⋯plot(shortTP, color=color.green, style=plot.style_linebr, linewidth=2)-plotLongCondition = longCondition ? high+abs(open-close) : na+plotLongCondition = longCondition ? high+math.abs(open-close) : naplot(plotLongCondition, style=plot.style_circles, linewidth=4, color=color.green)-plotShortCondition = shortCondition ? high+abs(open-close) : na+plotShortCondition = shortCondition ? high+math.abs(open-close) : naplot(plotShortCondition, style=plot.style_circles, linewidth=4, color=color.red)Clean v5
VerifiedSame 37 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 7: input() → input.int()
- Line 8: input() → input.int()
- Line 9: input() → input.int()
- Line 10: input() → input.int()
- Line 11: input() → input.int()
- Line 12: input() → input.int()
3 more edits
- Line 13: input() → input.float()
- Line 32: when = longCondition → if block
- Line 33: when = shortCondition → if block
⋯// Inputs-st_yr_inp = input(defval=2020, title='Backtest Start Year')+st_yr_inp = input.int(defval=2020, title='Backtest Start Year')-st_mn_inp = input(defval=01, title='Backtest Start Month')+st_mn_inp = input.int(defval=01, title='Backtest Start Month')-st_dy_inp = input(defval=01, title='Backtest Start Day')+st_dy_inp = input.int(defval=01, title='Backtest Start Day')-en_yr_inp = input(defval=2025, title='Backtest End Year')+en_yr_inp = input.int(defval=2025, title='Backtest End Year')-en_mn_inp = input(defval=01, title='Backtest End Month')+en_mn_inp = input.int(defval=01, title='Backtest End Month')-en_dy_inp = input(defval=01, title='Backtest End Day')+en_dy_inp = input.int(defval=01, title='Backtest End Day')-sltp_inp = input(defval=0.8, title='N - % offset for N*SL and (2N)*TP')/100+sltp_inp = input.float(defval=0.8, title='N - % offset for N*SL and (2N)*TP')/100 ⋯shortCondition = entryFilterCandleLength and wickToCandleRatio > 0.5 and lowerWick < upperWick and canTrade and strategy.position_size == 0-strategy.entry("pendingLong", strategy.long, limit=low+wickLength/2, when = longCondition)+if longCondition+ strategy.entry("pendingLong", strategy.long, limit=low+wickLength/2)-strategy.entry("pendingShort", strategy.short, limit=high-wickLength/2, when = shortCondition)+if shortCondition+ strategy.entry("pendingShort", strategy.short, limit=high-wickLength/2)longStop = strategy.position_size > 0 ? strategy.position_avg_price*(1-sltp_inp) : na⋯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: 37 before, 37 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.
⋯// © ondrej17-//@version=5+//@version=6strategy("longWickstrategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=0.1)⋯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 |
|---|---|---|---|
| Backtest Start Year | 2020 | int | start |
| Backtest Start Month | 01 | int | start |
| Backtest Start Day | 01 | int | start |
| Backtest End Year | 2025 | int | end |
| Backtest End Month | 01 | int | end |
| Backtest End Day | 01 | int | end |
| N - % offset for N*SL and (2N)*TP | 0.8 | float | longStop longTP shortStop shortTP |
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 pendingLong long | longConditionentryFilterCandleLength and wickToCandleRatio > 0.5 and lowerWick > upperWick and canTrade and strategy.position_size == 0 | On | 32 |
| Open pendingShort short | shortConditionentryFilterCandleLength and wickToCandleRatio > 0.5 and lowerWick < upperWick and canTrade and strategy.position_size == 0 | On | 33 |
| Exit longSLTP stop and limit | every bar | On | 38 |
| Exit shortSLTP stop and limit | every bar | On | 39 |
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 | −0.0% | +102.5% | 37 | 41% | 0.82 | 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% | 38 | 42% | 0.86 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.0% | +16.7% | 35 | 40% | 0.64 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 37 | 38% | 1.09 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 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 | 17 | 35% | −$0.93 |
| Sideways market | 17 | 47% | −$7.28 |
| Falling market | 3 | 33% | $0.31 |
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 37 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 37 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 15 Mar 2024 69,972.00 | 16 Mar 2024 69,412.20 | 1 | −$0.80 |
| short | 24 Mar 2024 64,994.50 | 25 Mar 2024 67,210.00 | 1 | −$3.41 |
| short | 27 Mar 2024 70,774.60 | 28 Mar 2024 69,470.00 | 1 | $1.84 |
| long | 12 Apr 2024 66,886.60 | 13 Apr 2024 66,351.50 | 1 | −$0.80 |
| long | 17 Apr 2024 62,510.00 | 18 Apr 2024 61,277.40 | 1 | −$1.97 |
| long | 26 Apr 2024 63,541.80 | 27 Apr 2024 63,033.40 | 1 | −$0.80 |
| long | 30 Apr 2024 62,442.10 | 1 May 2024 60,672.00 | 1 | −$2.83 |
| short | 15 May 2024 64,756.00 | 16 May 2024 66,206.50 | 1 | −$2.24 |
| long | 28 May 2024 67,284.90 | 29 May 2024 68,398.40 | 1 | $1.65 |
| short | 3 Jun 2024 70,062.00 | 4 Jun 2024 68,809.90 | 1 | $1.79 |
| long | 18 Jun 2024 65,817.20 | 19 Jun 2024 65,175.30 | 1 | −$0.98 |
| long | 8 Jul 2024 55,057.40 | 9 Jul 2024 56,714.60 | 1 | $3.01 |
| short | 11 Jul 2024 58,760.00 | 12 Jul 2024 57,339.90 | 1 | $2.42 |
| long | 18 Jul 2024 63,548.70 | 19 Jul 2024 64,565.40 | 1 | $1.60 |
| long | 23 Jul 2024 67,046.00 | 24 Jul 2024 65,936.00 | 1 | −$1.66 |
| short | 26 Jul 2024 66,519.00 | 27 Jul 2024 67,908.00 | 1 | −$2.09 |
| short | 29 Jul 2024 68,654.00 | 30 Jul 2024 66,784.70 | 1 | $2.72 |
| long | 1 Aug 2024 64,416.30 | 2 Aug 2024 65,447.00 | 1 | $1.60 |
| short | 8 Aug 2024 56,879.00 | 9 Aug 2024 61,686.00 | 1 | −$8.45 |
| long | 11 Aug 2024 60,186.50 | 12 Aug 2024 58,712.60 | 1 | −$2.45 |
| short | 21 Aug 2024 60,419.30 | 22 Aug 2024 61,156.00 | 1 | −$1.22 |
| long | 1 Sep 2024 58,412.50 | 2 Sep 2024 57,301.80 | 1 | −$1.90 |
| long | 5 Sep 2024 56,546.90 | 6 Sep 2024 56,094.50 | 1 | −$0.80 |
| short | 13 Sep 2024 60,263.00 | 15 Sep 2024 59,298.80 | 2 | $1.60 |
| short | 24 Sep 2024 64,162.30 | 25 Sep 2024 64,675.60 | 1 | −$0.80 |
| short | 4 Oct 2024 61,597.60 | 5 Oct 2024 62,090.40 | 1 | −$0.80 |
| short | 14 Oct 2024 63,649.10 | 15 Oct 2024 66,084.00 | 1 | −$3.82 |
| long | 25 Oct 2024 65,964.30 | 26 Oct 2024 67,019.80 | 1 | $1.60 |
| long | 4 Nov 2024 68,127.40 | 5 Nov 2024 67,582.30 | 1 | −$0.80 |
| long | 13 Nov 2024 86,512.00 | 14 Nov 2024 90,375.20 | 1 | $4.46 |
| short | 19 Nov 2024 91,529.00 | 20 Nov 2024 92,310.80 | 1 | −$0.85 |
| long | 25 Nov 2024 96,703.60 | 26 Nov 2024 93,010.00 | 1 | −$3.82 |
| long | 4 Dec 2024 94,709.40 | 5 Dec 2024 98,587.30 | 1 | $4.09 |
| long | 20 Dec 2024 95,424.80 | 21 Dec 2024 97,805.40 | 1 | $2.49 |
| long | 24 Dec 2024 93,700.70 | 24 Dec 2024 98,673.00 | 0 | $5.04 |
| long | 24 Dec 2024 93,700.70 | 25 Dec 2024 98,663.60 | 1 | $0.27 |
| short | 1 Jan 2025 94,913.00 | 2 Jan 2025 95,672.30 | 1 | −$0.80 |
Similar scripts
No other indicator or strategy here shares enough of its calculations.
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 14 ms | Yes 1,000 bars in 43 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/// © ondrej17//@version=4strategy("longWickstrategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=0.1) // Inputsst_yr_inp = input(defval=2020, title='Backtest Start Year')st_mn_inp = input(defval=01, title='Backtest Start Month')st_dy_inp = input(defval=01, title='Backtest Start Day')en_yr_inp = input(defval=2025, title='Backtest End Year')en_mn_inp = input(defval=01, title='Backtest End Month')en_dy_inp = input(defval=01, title='Backtest End Day')sltp_inp = input(defval=0.8, title='N - % offset for N*SL and (2N)*TP')/100 // Datesstart = timestamp(st_yr_inp, st_mn_inp, st_dy_inp,00,00)end = timestamp(en_yr_inp, en_mn_inp, en_dy_inp,00,00)canTrade = time >= start and time <= end// Indicators Setup // Strategy CalcuationslowerWick = (open > close) ? close-low : open - lowupperWick = (open > close) ? high-open : high-closewickLength = max(lowerWick,upperWick)candleLength = high-lowwickToCandleRatio = wickLength / candleLengthentryFilterCandleLength = candleLength > 0.75*atr(48)// Entries and Exits longCondition = entryFilterCandleLength and wickToCandleRatio > 0.5 and lowerWick > upperWick and canTrade and strategy.position_size == 0shortCondition = entryFilterCandleLength and wickToCandleRatio > 0.5 and lowerWick < upperWick and canTrade and strategy.position_size == 0strategy.entry("pendingLong", strategy.long, limit=low+wickLength/2, when = longCondition)strategy.entry("pendingShort", strategy.short, limit=high-wickLength/2, when = shortCondition)longStop = strategy.position_size > 0 ? strategy.position_avg_price*(1-sltp_inp) : nalongTP = strategy.position_size > 0 ? strategy.position_avg_price*(1+2*sltp_inp) : nashortStop = strategy.position_size < 0 ? strategy.position_avg_price*(1+sltp_inp) : nashortTP = strategy.position_size < 0 ? strategy.position_avg_price*(1-2*sltp_inp) : nastrategy.exit("longSLTP","pendingLong", stop=longStop, limit = longTP)strategy.exit("shortSLTP","pendingShort", stop=shortStop, limit = shortTP) plot(longStop, color=color.red, style=plot.style_linebr, linewidth=2)plot(shortStop, color=color.red, style=plot.style_linebr, linewidth=2)plot(longTP, color=color.green, style=plot.style_linebr, linewidth=2)plot(shortTP, color=color.green, style=plot.style_linebr, linewidth=2)plotLongCondition = longCondition ? high+abs(open-close) : naplot(plotLongCondition, style=plot.style_circles, linewidth=4, color=color.green)plotShortCondition = shortCondition ? high+abs(open-close) : naplot(plotShortCondition, style=plot.style_circles, linewidth=4, color=color.red)