Pine Script v5 · Strategy
Trendelicious Strategy
A Pine Script v5 strategy built on Highest or Lowest (hl2, 30), Change (PP, 1) and Crossover (hl2, PP). It has 3 order rules, 1 entry 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 0.1% commission. 5 settings; defaults include Length 30 and Price Source hl2.
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 Trendelicious Strategy repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did Trendelicious Strategy do on BTCUSDT 1D with default settings?
- −12.83%
- From 26 Jan 2024 to 21 Oct 2026, over 9 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Trendelicious 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: 9 before, 18 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 Trendelicious Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Trendelicious Strategy run in Zeal Terminal?
- Yes
- It compiles in 40 ms and runs 1,000 bars in 65 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Up Trend
- Down Trend
- Winning trade
- Losing trade
- Equity
- Buy and hold
| Net Profit | -128 -13 % |
| Buy & Hold | 386 39 % |
| Win / Loss | 4 / 5 |
| Open PnL | 263 |
- Net profit
- −12.83%
- −$128.27
- Buy and hold
- +102.5%
- same period
- Closed trades
- 9
- 4 won · 5 lost
- Profitable
- 44.4%
- of closed trades
- Profit factor
- 0.81
- gross profit ÷ gross loss
- Max drawdown
- 41.43%
- −$546.75
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
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
1 setting has no label
In the settings dialog length (line 5) shows an empty name. The labels on this page come from the variable names.
-
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 |
|---|---|---|---|
| Length (no label in the script) | 30 | int | uptrend PP trendline |
| Price Source | hl2 | source | uptrend PP priceOverPP priceUnderPP risingPrice fallingPrice uptrendCondition1 downtrendCondition1 trendline |
| Aggressive Mode | false | bool | uptrend uptrendCondition1 uptrendCondition2 uptrendCondition3 downtrendCondition1 downtrendCondition2 downtrendCondition3 trendline |
| Start Time | timestamp("01 Jan 1900 00:00 +0000") | time | line 11 |
| End Time | timestamp("31 Dec 2050 23:59 +0000") | time | line 11 |
What it calculates
- Highest / LowestPrice Source (hl2), Length (30)
PP · line 16 - ChangePP, 1
ppChange · line 17 - CrossoverPrice Source (hl2), PP
priceOverPP · line 19 - CrossunderPrice Source (hl2), PP
priceUnderPP · line 20 - RisingPrice Source (hl2), 5
risingPrice · line 21 - RisingPP, 5
risingPP · line 22 - FallingPrice Source (hl2), 5
fallingPrice · line 23 - FallingPP, 5
fallingPP · line 24
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 |
|---|---|---|---|
| cancel_all | not window() | On | 13 |
| Open Long long | buyCondition | On | 49 |
| Close Long | sellCondition | On | 53 |
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 dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- CheckIntrabar recalculationreads realtime-only state. 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 | −12.8% | +102.5% | 9 | 44% | 0.81 | 41.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +13.6% | +5.5% | 8 | 50% | 2.08 | 7.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −1.3% | +9.8% | 7 | 43% | 0.98 | 40.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +46.7% | +8.4% | 7 | 57% | 4.18 | 7.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −56.6% | +16.7% | 9 | 33% | 0.28 | 63.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +22.3% | +21.5% | 7 | 43% | 2.14 | 9.8% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +20.6% | +148.3% | 7 | 43% | 1.28 | 38.6% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −19.4% | +17.1% | 10 | 40% | 0.39 | 27.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 3 | 33% | −$69.48 |
| Sideways market | 5 | 40% | −$82.53 |
| Falling market | 1 | 100% | $24.61 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
46.1%
The 95th percentile of the worst drawdown when the same 9 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 24.7% to 46.1%; the tick is what actually happened, 35.7%. Order luck alone moves it this much.
All 9 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 1 Mar 2024 61,131.00 | 15 Apr 2024 65,661.90 | 45 | $71.97 |
| long | 23 May 2024 69,166.60 | 21 Jun 2024 64,870.00 | 29 | −$68.60 |
| long | 23 Jul 2024 67,532.00 | 1 Sep 2024 58,974.00 | 40 | −$128.90 |
| long | 30 Sep 2024 65,602.00 | 26 Feb 2025 88,680.40 | 149 | $305.27 |
| long | 25 Apr 2025 93,980.50 | 24 Jun 2025 105,334.00 | 60 | $139.88 |
| long | 12 Jul 2025 117,528.00 | 28 Aug 2025 111,262.00 | 47 | −$72.85 |
| long | 4 Oct 2025 122,232.00 | 7 Nov 2025 101,346.00 | 34 | −$215.10 |
| long | 16 Jan 2026 95,604.80 | 1 Feb 2026 78,741.10 | 16 | −$183.67 |
| long | 19 Mar 2026 71,246.60 | 30 May 2026 73,460.80 | 72 | $24.61 |
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 |
|---|---|---|---|---|---|
| Trendelicious Strategy this page | — | v5 strategy | −12.8% | 9 | 41.4% |
| ICHIMOKU Crypto Swing Strategy by exlux99 | highest lowest rising falling | v4 strategy | does not run in Zeal Terminal | ||
| Alex Days HiLo Rajib by 14rajib | highest lowest | v4 strategy | No trades on this market | ||
| Donchian Strat EXMO by pskoroplas | highest lowest | v4 strategy | +12.1% | 22 | 68.0% |
| Average Highest High and Lowest Low Swinger Strategy by exlux99 | lowest highest | v4 strategy | +6.4% | 20 | 49.6% |
| Highest High and Lowest Low Channel Strategy by ceyhun | highest lowest | v5 strategy | −3.7% | 26 | 7.9% |
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.
- 3 settings use the untyped input() (line 5, 6, 7). 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 9 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.int()
- Line 6: input() → input.source()
- Line 7: input() → input.bool()
⋯strategy(title='Trendelicious Strategy', shorttitle='Trendelicious Strategy', initial_capital=1000, overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)-length=input(defval=30)+length=input.int(defval=30)-price=input(defval=hl2, title="Price Source")+price=input.source(defval=hl2, title="Price Source")-aggressiveMode=input(defval=false,title="Aggressive Mode")+aggressiveMode=input.bool(defval=false,title="Aggressive Mode")start = input.time(defval = timestamp("01 Jan 1900 00:00 +0000"), title = "Start Time")⋯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: 9 before, 18 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.
⋯// © levieux-//@version=5+//@version=6strategy(title='Trendelicious Strategy', shorttitle='Trendelicious Strategy', initial_capital=1000, overlay=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 40 ms | Yes 1,000 bars in 65 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/// © levieux//@version=5strategy(title='Trendelicious Strategy', shorttitle='Trendelicious Strategy', initial_capital=1000, overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)length=input(defval=30)price=input(defval=hl2, title="Price Source")aggressiveMode=input(defval=false,title="Aggressive Mode")start = input.time(defval = timestamp("01 Jan 1900 00:00 +0000"), title = "Start Time")end = input.time(defval = timestamp("31 Dec 2050 23:59 +0000"), title = "End Time")window() => time >= start and time < endif not window() strategy.cancel_all()isUptrend(price,length,aggressiveMode) => uptrend= false PP= (ta.highest(price,length)+ta.lowest(price,length))/2 ppChange= ta.change(PP,1) ppFlat= ppChange==0 priceOverPP=ta.crossover(price,PP) priceUnderPP=ta.crossunder(price,PP) risingPrice= ta.rising(price,5) risingPP= ta.rising(PP,5) fallingPrice= ta.falling(price,5) fallingPP= ta.falling(PP,5) uptrendCondition1= price>PP and (ppChange>0 or (ppChange==0 and aggressiveMode)) and (ppChange[1]>0 or (ppChange[1]==0 and aggressiveMode)) and ppChange[2]>=0 and ppChange[3]>=0 uptrendCondition2= (priceOverPP or risingPrice) and ppFlat and aggressiveMode uptrendCondition3= risingPrice and fallingPP and aggressiveMode downtrendCondition1= price < PP and (ppChange<0 or (ppChange==0 and aggressiveMode)) and (ppChange[1]<0 or (ppChange[1]==0 and aggressiveMode)) and ppChange[2]<=0 and ppChange[3]<=0 downtrendCondition2= (priceUnderPP or fallingPrice) and ppFlat and aggressiveMode downtrendCondition3= fallingPrice and risingPP and aggressiveMode if uptrendCondition1 or uptrendCondition2 or uptrendCondition3 uptrend:= true else if downtrendCondition1 or downtrendCondition2 or downtrendCondition3 uptrend:= false else uptrend:= uptrend[1] [PP,uptrend][trendline,uptrend]= isUptrend(price,length,aggressiveMode)baseLinePlot = plot((open + close) / 2, display=display.none)upTrendPlot = plot(uptrend ? trendline : na, "Up Trend", color = color.green, style=plot.style_linebr)downTrendPlot = plot(not uptrend ? trendline : na, "Down Trend", color = color.red, style=plot.style_linebr)fill(baseLinePlot, upTrendPlot, color.new(color.green, 90), fillgaps=false)fill(baseLinePlot, downTrendPlot, color.new(color.red, 90), fillgaps=false)buyCondition= window() and uptrend and uptrend[1] and strategy.position_size<=0sellCondition= window() and not uptrend and not uptrend[1] and strategy.position_size>=0firstTradePrice= close-closefirstTradePrice:= nz(firstTradePrice[1],0)if buyCondition strategy.entry("Long", strategy.long) if firstTradePrice==0 firstTradePrice:= closeelse if sellCondition strategy.close("Long")end_time= time_close>timenowend_time:= time_close + (time_close - time_close[1]) > timenow or barstate.islastconfirmedhistoryprecision= 0if end_time netprofit=math.round(strategy.netprofit,precision) netprofitPercent=math.round(100*netprofit/strategy.initial_capital,precision) bhprofit= math.round((strategy.initial_capital/firstTradePrice)*close-strategy.initial_capital,precision) bhprofitPercent= math.round(100*bhprofit/strategy.initial_capital,precision) openprofit=math.round(strategy.openprofit,precision) trades= strategy.closedtrades wins= strategy.wintrades losses= strategy.losstrades winColor= color.new(color.green, transp = 20) loseColor= color.new(color.red, transp = 20) neutralColor= color.new(color.silver, transp = 70) testTable = table.new(position = position.bottom_right, columns = 2, rows = 4, border_width = 1) table.cell(table_id = testTable, column = 0, row = 0, text = "Net Profit", bgcolor = #cccccc) table.cell(table_id = testTable, column = 1, row = 0, text = str.tostring(netprofit)+"\n"+str.tostring(netprofitPercent)+" %", bgcolor= netprofit>0?winColor:loseColor) table.cell(table_id = testTable, column = 0, row = 1, text = "Buy & Hold", bgcolor = #cccccc) table.cell(table_id = testTable, column = 1, row = 1, text = str.tostring(bhprofit)+"\n"+str.tostring(bhprofitPercent)+" %", bgcolor= bhprofitPercent>0?winColor:loseColor) table.cell(table_id = testTable, column = 0, row = 2, text = "Win / Loss", bgcolor = #cccccc) table.cell(table_id = testTable, column = 1, row = 2, text = str.tostring(wins)+" / "+str.tostring(losses), bgcolor=neutralColor) table.cell(table_id = testTable, column = 0, row = 3, text = "Open PnL", bgcolor = #cccccc) table.cell(table_id = testTable, column = 1, row = 3, text = str.tostring(openprofit), bgcolor= openprofit==0?neutralColor:openprofit>0?winColor:loseColor)