Pine Script v4 · Strategy
MACD TrueLevel Strategy
A Pine Script v4 strategy built on MACD (close, 12), Linreg (close, length) and Stdev (close, length). 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 10% of equity and pays no commission. 23 settings; defaults include Fast Length 12, Slow Length 26 and Signal Length 9.
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 MACD TrueLevel Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 11 of 11 trades.
- How did MACD TrueLevel Strategy do on BTCUSDT 1D with default settings?
- +3.60%
- From 26 Jan 2024 to 21 Oct 2026, over 38 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can MACD TrueLevel Strategy 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 MACD TrueLevel Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does MACD TrueLevel Strategy run in Zeal Terminal?
- Yes
- It compiles in 49 ms and runs 1,000 bars in 268 ms, in the browser.
BTCUSDT · 1D · default settings
- Upper Band 1
- Lower Band 1
- Upper Band 2
- Lower Band 2
- Upper Band 3
- Lower Band 3
- Upper Band 4
- Lower Band 4
- Upper Band 5
- Lower Band 5
- Upper Band 6
- Lower Band 6
- Upper Band 7
- Lower Band 7
- Winning trade
- Losing trade
- Net profit
- +3.60%
- $3,604.53
- Buy and hold
- +102.5%
- same period
- Closed trades
- 38
- 14 won · 24 lost
- Profitable
- 36.8%
- of closed trades
- Profit factor
- 1.40
- gross profit ÷ gross loss
- Max drawdown
- 2.98%
- −$3,098.63
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 stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
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 169, 170, 171, 172. 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 macd → ta.macd, linreg → ta.linreg, stdev → ta.stdev, max → math.max, min → math.min, highest → ta.highest, lowest → ta.lowest, crossover → ta.crossover, crossunder → ta.crossunder.
- 4 strategy calls use the when = argument (line 169, 170, 171, 172). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
DiffersTrades differ: 38 before, 38 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 6: input(type = input.integer) → input.int()
- Line 7: input(type = input.integer) → input.int()
- Line 8: input(type = input.integer) → input.int()
- Line 10: input(type = input.integer) → input.int()
- Line 11: input(type = input.integer) → input.int()
59 more edits
- Line 13: input(type = input.bool) → input.bool()
- Line 15: macd → ta.macd
- Line 17: input(type = input.integer) → input.int()
- Line 18: input(type = input.integer) → input.int()
- Line 19: input(type = input.integer) → input.int()
- Line 20: input(type = input.integer) → input.int()
- Line 21: input(type = input.integer) → input.int()
- Line 22: input(type = input.integer) → input.int()
- Line 23: input(type = input.integer) → input.int()
- Line 24: input(type = input.integer) → input.int()
- Line 25: input(type = input.integer) → input.int()
- Line 26: input(type = input.integer) → input.int()
- Line 27: input(type = input.integer) → input.int()
- Line 28: input(type = input.integer) → input.int()
- Line 29: input(type = input.integer) → input.int()
- Line 30: input(type = input.integer) → input.int()
- Line 31: input(type = input.color) → input.color()
- Line 32: input(type = input.float) → input.float()
- Line 33: input(type = input.source) → input.source()
- Line 36: linreg → ta.linreg
- Line 37: stdev → ta.stdev
- Line 42: linreg → ta.linreg
- Line 43: stdev → ta.stdev
- Line 123: max → math.max
- Line 123: max → math.max
- Line 123: max → math.max
- Line 123: max → math.max
- Line 123: max → math.max
- Line 123: max → math.max
- Line 123: max → math.max
- Line 123: max → math.max
- Line 123: max → math.max
- Line 123: max → math.max
- Line 123: max → math.max
- Line 123: max → math.max
- Line 123: max → math.max
- Line 124: min → math.min
- Line 124: min → math.min
- Line 124: min → math.min
- Line 124: min → math.min
- Line 124: min → math.min
- Line 124: min → math.min
- Line 124: min → math.min
- Line 124: min → math.min
- Line 124: min → math.min
- Line 124: min → math.min
- Line 124: min → math.min
- Line 124: min → math.min
- Line 124: min → math.min
- Line 126: highest → ta.highest
- Line 127: lowest → ta.lowest
- Line 163: crossover → ta.crossover
- Line 163: crossover → ta.crossover
- Line 164: crossunder → ta.crossunder
- Line 164: crossunder → ta.crossunder
- Line 166: crossunder → ta.crossunder
- Line 166: crossunder → ta.crossunder
- Line 167: crossover → ta.crossover
- Line 167: crossover → ta.crossover
⋯// © Julien_Eche-//@version=4+//@version=5strategy("MACD TrueLevel Strategy", shorttitle="MACD TL", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)// Input parameters for MACD-fastLength = input(12, title="Fast Length", type=input.integer)+fastLength = input.int(12, title="Fast Length")-slowLength = input(26, title="Slow Length", type=input.integer)+slowLength = input.int(26, title="Slow Length")-signalLength = input(9, title="Signal Length", type=input.integer)+signalLength = input.int(9, title="Signal Length")// Inputs for selecting bands-entry_band = input(12, title="Entry TrueLevel Band", type=input.integer, minval=1, maxval=14)+entry_band = input.int(12, title="Entry TrueLevel Band", minval=1, maxval=14)-exit_band = input(12, title="Exit TrueLevel Band", type=input.integer, minval=1, maxval=14)+exit_band = input.int(12, title="Exit TrueLevel Band", minval=1, maxval=14)// Input for long and short mode-long_and_short = input(false, title="Enable Long and Short", type=input.bool)+long_and_short = input.bool(false, title="Enable Long and Short")// Calculate the MACD-[macdLine, signalLine, _] = macd(close, fastLength, slowLength, signalLength)+[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalLength)// User inputs-len1 = input(title="Length 1", type=input.integer, defval=126)+len1 = input.int(title="Length 1", defval=126)-len2 = input(title="Length 2", type=input.integer, defval=189)+len2 = input.int(title="Length 2", defval=189)-len3 = input(title="Length 3", type=input.integer, defval=252)+len3 = input.int(title="Length 3", defval=252)-len4 = input(title="Length 4", type=input.integer, defval=378)+len4 = input.int(title="Length 4", defval=378)-len5 = input(title="Length 5", type=input.integer, defval=504)+len5 = input.int(title="Length 5", defval=504)-len6 = input(title="Length 6", type=input.integer, defval=630)+len6 = input.int(title="Length 6", defval=630)-len7 = input(title="Length 7", type=input.integer, defval=756)+len7 = input.int(title="Length 7", defval=756)-len8 = input(title="Length 8", type=input.integer, defval=1008)+len8 = input.int(title="Length 8", defval=1008)-len9 = input(title="Length 9", type=input.integer, defval=1260)+len9 = input.int(title="Length 9", defval=1260)-len10 = input(title="Length 10", type=input.integer, defval=1638)+len10 = input.int(title="Length 10", defval=1638)-len11 = input(title="Length 11", type=input.integer, defval=2016)+len11 = input.int(title="Length 11", defval=2016)-len12 = input(title="Length 12", type=input.integer, defval=2646)+len12 = input.int(title="Length 12", defval=2646)-len13 = input(title="Length 13", type=input.integer, defval=3276)+len13 = input.int(title="Length 13", defval=3276)-len14 = input(title="Length 14", type=input.integer, defval=4284)+len14 = input.int(title="Length 14", defval=4284)-fill_color = input(title="Fill Color", type=input.color, defval=color.rgb(0, 191, 255, 95))+fill_color = input.color(title="Fill Color", defval=color.rgb(0, 191, 255, 95))-mult = input(title="Multiple", type=input.float, defval=1, step=0.2, options=[0.6, 0.8, 1, 1.2, 1.4])+mult = input.float(title="Multiple", defval=1, step=0.2, options=[0.6, 0.8, 1, 1.2, 1.4])-src = input(title="Source", type=input.source, defval=close)+src = input.source(title="Source", defval=close)// Upper band calculation functionupperBand(length) =>- linreg = linreg(src, length, 0)+ linreg = ta.linreg(src, length, 0)- stddev = mult * stdev(src, length)+ stddev = mult * ta.stdev(src, length) upperband = linreg + stddev⋯lowerBand(length) =>- linreg = linreg(src, length, 0)+ linreg = ta.linreg(src, length, 0)- stddev = mult * stdev(src, length)+ stddev = mult * ta.stdev(src, length) lowerband = linreg - stddev⋯// Calculate the trueLevelUpperBand and trueLevelLowerBand-trueLevelUpperBand = max(upperband_1, max(upperband_2, max(upperband_3, max(upperband_4, max(upperband_5, max(upperband_6, max(upperband_7, max(upperband_8, max(upperband_9, max(upperband_10, max(upperband_11, max(upperband_12, max(upperband_13, upperband_14)))))))))))))+trueLevelUpperBand = math.max(upperband_1, math.max(upperband_2, math.max(upperband_3, math.max(upperband_4, math.max(upperband_5, math.max(upperband_6, math.max(upperband_7, math.max(upperband_8, math.max(upperband_9, math.max(upperband_10, math.max(upperband_11, math.max(upperband_12, math.max(upperband_13, upperband_14)))))))))))))-trueLevelLowerBand = min(lowerband_1, min(lowerband_2, min(lowerband_3, min(lowerband_4, min(lowerband_5, min(lowerband_6, min(lowerband_7, min(lowerband_8, min(lowerband_9, min(lowerband_10, min(lowerband_11, min(lowerband_12, min(lowerband_13, lowerband_14)))))))))))))+trueLevelLowerBand = math.min(lowerband_1, math.min(lowerband_2, math.min(lowerband_3, math.min(lowerband_4, math.min(lowerband_5, math.min(lowerband_6, math.min(lowerband_7, math.min(lowerband_8, math.min(lowerband_9, math.min(lowerband_10, math.min(lowerband_11, math.min(lowerband_12, math.min(lowerband_13, lowerband_14)))))))))))))// Update the highest upper band and lowest lower band-highestUpperBand := highest(trueLevelUpperBand, 1)+highestUpperBand := ta.highest(trueLevelUpperBand, 1)-lowestLowerBand := lowest(trueLevelLowerBand, 1)+lowestLowerBand := ta.lowest(trueLevelLowerBand, 1)// Store the upper and lower bands in an array for easy access⋯// Entry conditions-longCondition = crossover(macdLine, signalLine) or crossover(close, selected_entry_lowerband)+longCondition = ta.crossover(macdLine, signalLine) or ta.crossover(close, selected_entry_lowerband)-shortCondition = crossunder(macdLine, signalLine) or crossunder(close, selected_exit_upperband)+shortCondition = ta.crossunder(macdLine, signalLine) or ta.crossunder(close, selected_exit_upperband)// Exit conditions-exitLongCondition = crossunder(macdLine, signalLine) or crossunder(close, selected_exit_upperband)+exitLongCondition = ta.crossunder(macdLine, signalLine) or ta.crossunder(close, selected_exit_upperband)-exitShortCondition = crossover(macdLine, signalLine) or crossover(close, selected_entry_lowerband)+exitShortCondition = ta.crossover(macdLine, signalLine) or ta.crossover(close, selected_entry_lowerband)// Strategy execution⋯Clean v5
VerifiedSame 38 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 169: when = longCondition → if block
- Line 170: when = shortCondition and long_and_short → if block
- Line 171: when = exitLongCondition → if block
- Line 172: when = exitShortCondition → if block
⋯// Strategy execution-strategy.entry("Long", strategy.long, when = longCondition)+if longCondition+ strategy.entry("Long", strategy.long)-strategy.entry("Short", strategy.short, when = shortCondition and long_and_short)+if shortCondition and long_and_short+ strategy.entry("Short", strategy.short)-strategy.close("Long", when = exitLongCondition)+if exitLongCondition+ strategy.close("Long")-strategy.close("Short", when = exitShortCondition)+if exitShortCondition+ strategy.close("Short")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: 38 before, 38 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.
⋯// © Julien_Eche-//@version=5+//@version=6strategy("MACD TrueLevel Strategy", shorttitle="MACD TL", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)⋯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 |
|---|---|---|---|
| Fast Length | 12 | int (written input.integer) | macdLine signalLine |
| Slow Length | 26 | int (written input.integer) | macdLine signalLine |
| Signal Length | 9 | int (written input.integer) | macdLine signalLine |
| Entry TrueLevel Band | 12 | int (written input.integer) · min 1 · max 14 | selected_entry_lowerband |
| Exit TrueLevel Band | 12 | int (written input.integer) · min 1 · max 14 | selected_exit_upperband |
| Enable Long and Short | false | bool | entry Short |
| Length 1 | 126 | int (written input.integer) | upperband_1 lowerband_1 |
| Length 2 | 189 | int (written input.integer) | upperband_2 lowerband_2 |
| Length 3 | 252 | int (written input.integer) | upperband_3 lowerband_3 |
| Length 4 | 378 | int (written input.integer) | upperband_4 lowerband_4 |
| Length 5 | 504 | int (written input.integer) | upperband_5 lowerband_5 |
| Length 6 | 630 | int (written input.integer) | upperband_6 lowerband_6 |
| Length 7 | 756 | int (written input.integer) | upperband_7 lowerband_7 |
| Length 8 | 1008 | int (written input.integer) | upperband_8 lowerband_8 |
| Length 9 | 1260 | int (written input.integer) | upperband_9 lowerband_9 |
| Length 10 | 1638 | int (written input.integer) | upperband_10 lowerband_10 |
| Length 11 | 2016 | int (written input.integer) | upperband_11 lowerband_11 |
| Length 12 | 2646 | int (written input.integer) | upperband_12 lowerband_12 |
| Length 13 | 3276 | int (written input.integer) | upperband_13 lowerband_13 |
| Length 14 | 4284 | int (written input.integer) | upperband_14 lowerband_14 |
| Fill Color | color.rgb(0, 191, 255, 95) | color | Fill 1 Fill 2 Fill 3 Fill 4 Fill 5 Fill 6 Fill 7 Fill 8 Fill 9 Fill 10 Fill 11 Fill 12 Fill 13 Fill 14 |
| Multiple | 1 | float · step 0.2 · options [0.6, 0.8, 1, 1.2, 1.4] | stddev |
| Source | close | source | linreg stddev |
What it calculates
- MACD (
macd,ta.macdin v5)close, Fast Length (12), Slow Length (26), Signal Length (9)macdLine · line 15 - MACD (
macd,ta.macdin v5)close, Fast Length (12), Slow Length (26), Signal Length (9)signalLine · line 15 - Linreg (
linreg,ta.linregin v5)Source (close), length, 0linreg · line 42 - Stdev (
stdev,ta.stdevin v5)Source (close), lengthstddev · line 43 - Highest (
highest,ta.highestin v5)trueLevelUpperBand, 1highestUpperBand · line 126 - Lowest (
lowest,ta.lowestin v5)trueLevelLowerBand, 1lowestLowerBand · line 127
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.
The script has 96 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | longConditioncrossover(macdLine, signalLine) or crossover(close, selected_entry_lowerband) | On | 169 |
| Open Short short | shortCondition and long_and_short | On | 170 |
| Close Long | exitLongConditioncrossunder(macdLine, signalLine) or crossunder(close, selected_exit_upperband) | On | 171 |
| Close Short | exitShortConditioncrossover(macdLine, signalLine) or crossover(close, selected_entry_lowerband) | On | 172 |
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 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 | +3.6% | +102.5% | 38 | 37% | 1.40 | 3.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.7% | +5.5% | 34 | 35% | 1.63 | 0.9% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.0% | +9.8% | 36 | 31% | 1.00 | 7.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +1.2% | +8.4% | 38 | 26% | 1.24 | 1.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +7.1% | +16.7% | 32 | 50% | 1.47 | 6.9% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +1.5% | +21.5% | 35 | 34% | 1.34 | 1.6% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +1.5% | +148.3% | 34 | 50% | 1.23 | 3.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +1.0% | +17.1% | 38 | 34% | 1.28 | 1.1% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (Fast Length 14, Slow Length 13) made +6.1% before 26 Dec 2025 and −3.8% after it, worse than the defaults' +1.6% after. Tuning on the past did not carry forward. 94% of the 64 combinations made money in-sample and 91% out-of-sample.
| Slow Length ↓ · Fast Length → | 6 | 7 | 8 | 10 | 12 | 14 | 17 | 20 |
|---|---|---|---|---|---|---|---|---|
| 13 | +2% | +3% | +4% | +5% | +2% | +6% | +4% | +4% |
| 16 | +5% | +4% | +4% | +2% | +1% | +1% | +3% | +2% |
| 18 | +5% | +4% | +3% | +2% | +1% | +1% | +2% | +2% |
| 22 | +3% | +1% | +0% | +1% | +1% | +3% | +4% | +4% |
| 26 | −0% | +0% | −0% | +0% | +2% | +2% | +4% | +5% |
| 31 | −1% | +0% | −0% | +2% | +2% | +4% | +5% | +4% |
| 36 | +1% | +1% | +2% | +3% | +4% | +5% | +4% | +4% |
| 44 | +2% | +2% | +3% | +3% | +4% | +4% | +3% | +3% |
| Slow Length ↓ · Fast Length → | 6 | 7 | 8 | 10 | 12 | 14 | 17 | 20 |
|---|---|---|---|---|---|---|---|---|
| 13 | +3% | +3% | +4% | +3% | +3% | −4% | −3% | −2% |
| 16 | +4% | +4% | +4% | +4% | +3% | +3% | −2% | −1% |
| 18 | +4% | +4% | +4% | +4% | +3% | +3% | +2% | −2% |
| 22 | +4% | +4% | +4% | +3% | +3% | +1% | +2% | +1% |
| 26 | +3% | +4% | +3% | +3% | +2% | +2% | +2% | +2% |
| 31 | +3% | +3% | +3% | +2% | +2% | +2% | +2% | +3% |
| 36 | +3% | +3% | +2% | +2% | +2% | +3% | +2% | +2% |
| 44 | +2% | +2% | +2% | +2% | +2% | +2% | +2% | +2% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. 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 | 13 | 31% | $1,341.83 |
| Sideways market | 18 | 44% | $3,148.78 |
| Falling market | 7 | 29% | −$886.08 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
4.8%
The 95th percentile of the worst drawdown when the same 38 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.0% to 4.8%; the tick is what actually happened, 2.8%. Order luck alone moves it this much.
All 38 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 6 May 2024 64,012.00 | 12 May 2024 60,826.00 | 6 | −$497.72 |
| long | 13 May 2024 61,484.00 | 31 May 2024 68,352.20 | 18 | $1,111.51 |
| long | 6 Jun 2024 71,108.00 | 9 Jun 2024 69,310.50 | 3 | −$254.34 |
| long | 13 Jul 2024 57,889.10 | 1 Aug 2024 64,628.00 | 19 | $1,168.29 |
| long | 20 Aug 2024 59,438.50 | 31 Aug 2024 59,124.00 | 11 | −$53.72 |
| long | 13 Sep 2024 58,132.30 | 2 Oct 2024 60,804.90 | 19 | $466.52 |
| long | 15 Oct 2024 66,084.00 | 27 Oct 2024 67,092.80 | 12 | $155.61 |
| long | 29 Oct 2024 69,962.20 | 4 Nov 2024 68,776.00 | 6 | −$173.11 |
| long | 7 Nov 2024 75,572.00 | 27 Nov 2024 91,965.20 | 20 | $2,210.93 |
| long | 17 Dec 2024 106,059.00 | 19 Dec 2024 100,204.00 | 2 | −$574.84 |
| long | 6 Jan 2025 98,363.60 | 10 Jan 2025 92,552.50 | 4 | −$611.81 |
| long | 16 Jan 2025 100,497.00 | 29 Jan 2025 101,336.00 | 13 | $85.86 |
| long | 21 Feb 2025 98,305.00 | 25 Feb 2025 91,552.90 | 4 | −$707.69 |
| long | 7 Mar 2025 89,931.90 | 9 Mar 2025 86,222.50 | 2 | −$422.06 |
| long | 16 Mar 2025 84,338.40 | 7 Apr 2025 78,430.00 | 22 | −$713.90 |
| long | 12 Apr 2025 83,423.80 | 18 May 2025 103,127.00 | 36 | $2,389.87 |
| long | 19 May 2025 106,454.00 | 20 May 2025 105,574.00 | 1 | −$85.68 |
| long | 22 May 2025 109,644.00 | 25 May 2025 107,762.00 | 3 | −$177.65 |
| long | 11 Jun 2025 110,274.00 | 13 Jun 2025 105,672.00 | 2 | −$431.22 |
| long | 27 Jun 2025 106,947.00 | 22 Jul 2025 117,380.00 | 25 | $1,003.70 |
| long | 23 Jul 2025 119,954.00 | 24 Jul 2025 118,756.00 | 1 | −$103.79 |
| long | 12 Aug 2025 118,686.00 | 18 Aug 2025 117,405.00 | 6 | −$112.02 |
| long | 7 Sep 2025 110,188.00 | 24 Sep 2025 111,999.00 | 17 | $170.38 |
| long | 2 Oct 2025 118,595.00 | 11 Oct 2025 112,774.00 | 9 | −$509.65 |
| long | 27 Oct 2025 114,559.00 | 4 Nov 2025 106,583.00 | 8 | −$719.47 |
| long | 28 Nov 2025 91,333.90 | 18 Dec 2025 86,243.20 | 20 | −$571.94 |
| long | 21 Dec 2025 88,360.90 | 21 Jan 2026 88,427.70 | 31 | $7.71 |
| long | 16 Feb 2026 68,832.60 | 23 Mar 2026 67,859.00 | 35 | −$144.34 |
| long | 26 Mar 2026 71,336.50 | 27 Mar 2026 68,820.30 | 1 | −$359.45 |
| long | 7 Apr 2026 68,853.70 | 29 Apr 2026 76,342.80 | 22 | $1,104.50 |
| long | 5 May 2026 79,861.00 | 13 May 2026 80,504.50 | 8 | $82.71 |
| long | 14 Jun 2026 64,458.00 | 28 Jun 2026 60,029.00 | 14 | −$705.89 |
| long | 30 Jun 2026 60,260.20 | 1 Jul 2026 58,624.70 | 1 | −$276.91 |
| long | 2 Jul 2026 60,024.00 | 28 Jul 2026 63,755.90 | 26 | $632.61 |
| long | 8 Aug 2026 64,923.20 | 12 Aug 2026 63,600.00 | 4 | −$208.66 |
| long | 19 Aug 2026 64,725.40 | 3 Sep 2026 77,340.00 | 15 | $1,991.32 |
| long | 4 Sep 2026 81,270.40 | 5 Sep 2026 79,660.80 | 1 | −$206.31 |
| long | 22 Sep 2026 86,620.00 | 30 Sep 2026 83,663.70 | 8 | −$354.81 |
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 |
|---|---|---|---|---|---|
| MACD TrueLevel Strategy this page | — | v4 strategy | +3.6% | 38 | 3.0% |
| VixFixLinReg-Strategy by Trendoscope | highest stdev lowest linreg | v4 strategy | −49.3% | 12 | 51.1% |
| RSI TrueLevel Strategy by Julien_Eche | linreg stdev highest lowest | v4 strategy | +2.8% | 10 | 5.1% |
| Lawyers Trend Pro Strategy by ErdemDemir | stdev lowest highest | v4 strategy | +12.1% | 102 | 41.7% |
| BTC Volatility Band Strategy by gary_trades | stdev lowest highest | v4 strategy | −33.5% | 80 | 45.0% |
| Chandelier Exit ZLSMA Strategy by simwai | highest lowest linreg | v5 strategy | +2.4% | 8 | 2.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 49 ms | Yes 1,000 bars in 268 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/// © Julien_Eche//@version=4strategy("MACD TrueLevel Strategy", shorttitle="MACD TL", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)// Input parameters for MACDfastLength = input(12, title="Fast Length", type=input.integer)slowLength = input(26, title="Slow Length", type=input.integer)signalLength = input(9, title="Signal Length", type=input.integer)// Inputs for selecting bandsentry_band = input(12, title="Entry TrueLevel Band", type=input.integer, minval=1, maxval=14)exit_band = input(12, title="Exit TrueLevel Band", type=input.integer, minval=1, maxval=14)// Input for long and short modelong_and_short = input(false, title="Enable Long and Short", type=input.bool)// Calculate the MACD[macdLine, signalLine, _] = macd(close, fastLength, slowLength, signalLength)// User inputslen1 = input(title="Length 1", type=input.integer, defval=126)len2 = input(title="Length 2", type=input.integer, defval=189)len3 = input(title="Length 3", type=input.integer, defval=252)len4 = input(title="Length 4", type=input.integer, defval=378)len5 = input(title="Length 5", type=input.integer, defval=504)len6 = input(title="Length 6", type=input.integer, defval=630)len7 = input(title="Length 7", type=input.integer, defval=756)len8 = input(title="Length 8", type=input.integer, defval=1008)len9 = input(title="Length 9", type=input.integer, defval=1260)len10 = input(title="Length 10", type=input.integer, defval=1638)len11 = input(title="Length 11", type=input.integer, defval=2016)len12 = input(title="Length 12", type=input.integer, defval=2646)len13 = input(title="Length 13", type=input.integer, defval=3276)len14 = input(title="Length 14", type=input.integer, defval=4284)fill_color = input(title="Fill Color", type=input.color, defval=color.rgb(0, 191, 255, 95))mult = input(title="Multiple", type=input.float, defval=1, step=0.2, options=[0.6, 0.8, 1, 1.2, 1.4])src = input(title="Source", type=input.source, defval=close)// Upper band calculation functionupperBand(length) => linreg = linreg(src, length, 0) stddev = mult * stdev(src, length) upperband = linreg + stddev upperband// Lower band calculation functionlowerBand(length) => linreg = linreg(src, length, 0) stddev = mult * stdev(src, length) lowerband = linreg - stddev lowerband// Calculate upper and lower bands for each lengthupperband_1 = upperBand(len1)upperband_2 = upperBand(len2)upperband_3 = upperBand(len3)upperband_4 = upperBand(len4)upperband_5 = upperBand(len5)upperband_6 = upperBand(len6)upperband_7 = upperBand(len7)upperband_8 = upperBand(len8)upperband_9 = upperBand(len9)upperband_10 = upperBand(len10)upperband_11 = upperBand(len11)upperband_12 = upperBand(len12)upperband_13 = upperBand(len13)upperband_14 = upperBand(len14)lowerband_1 = lowerBand(len1)lowerband_2 = lowerBand(len2)lowerband_3 = lowerBand(len3)lowerband_4 = lowerBand(len4)lowerband_5 = lowerBand(len5)lowerband_6 = lowerBand(len6)lowerband_7 = lowerBand(len7)lowerband_8 = lowerBand(len8)lowerband_9 = lowerBand(len9)lowerband_10 = lowerBand(len10)lowerband_11 = lowerBand(len11)lowerband_12 = lowerBand(len12)lowerband_13 = lowerBand(len13)lowerband_14 = lowerBand(len14)// Plot envelope bands for each lengthupperband_1_plot = plot(upperband_1, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Upper Band 1")lowerband_1_plot = plot(lowerband_1, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Lower Band 1")upperband_2_plot = plot(upperband_2, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Upper Band 2")lowerband_2_plot = plot(lowerband_2, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Lower Band 2")upperband_3_plot = plot(upperband_3, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Upper Band 3")lowerband_3_plot = plot(lowerband_3, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Lower Band 3")upperband_4_plot = plot(upperband_4, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Upper Band 4")lowerband_4_plot = plot(lowerband_4, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Lower Band 4")upperband_5_plot = plot(upperband_5, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Upper Band 5")lowerband_5_plot = plot(lowerband_5, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Lower Band 5")upperband_6_plot = plot(upperband_6, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Upper Band 6")lowerband_6_plot = plot(lowerband_6, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Lower Band 6")upperband_7_plot = plot(upperband_7, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Upper Band 7")lowerband_7_plot = plot(lowerband_7, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Lower Band 7")upperband_8_plot = plot(upperband_8, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Upper Band 8")lowerband_8_plot = plot(lowerband_8, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Lower Band 8")upperband_9_plot = plot(upperband_9, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Upper Band 9")lowerband_9_plot = plot(lowerband_9, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Lower Band 9")upperband_10_plot = plot(upperband_10, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Upper Band 10")lowerband_10_plot = plot(lowerband_10, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Lower Band 10")upperband_11_plot = plot(upperband_11, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Upper Band 11")lowerband_11_plot = plot(lowerband_11, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Lower Band 11")upperband_12_plot = plot(upperband_12, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Upper Band 12")lowerband_12_plot = plot(lowerband_12, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Lower Band 12")upperband_13_plot = plot(upperband_13, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Upper Band 13")lowerband_13_plot = plot(lowerband_13, color=color.rgb(14, 139, 212, 95), linewidth=1, title="Lower Band 13")upperband_14_plot = plot(upperband_14, color=color.rgb(14, 116, 212, 95), linewidth=1, title="Upper Band 14")lowerband_14_plot = plot(lowerband_14, color=color.rgb(14, 139, 212, 95), linewidth=1, title="Lower Band 14")// Plot fills for each lengthfill(upperband_1_plot, lowerband_1_plot, color=fill_color, title="Fill 1")fill(upperband_2_plot, lowerband_2_plot, color=fill_color, title="Fill 2")fill(upperband_3_plot, lowerband_3_plot, color=fill_color, title="Fill 3")fill(upperband_4_plot, lowerband_4_plot, color=fill_color, title="Fill 4")fill(upperband_5_plot, lowerband_5_plot, color=fill_color, title="Fill 5")fill(upperband_6_plot, lowerband_6_plot, color=fill_color, title="Fill 6")fill(upperband_7_plot, lowerband_7_plot, color=fill_color, title="Fill 7")fill(upperband_8_plot, lowerband_8_plot, color=fill_color, title="Fill 8")fill(upperband_9_plot, lowerband_9_plot, color=fill_color, title="Fill 9")fill(upperband_10_plot, lowerband_10_plot, color=fill_color, title="Fill 10")fill(upperband_11_plot, lowerband_11_plot, color=fill_color, title="Fill 11")fill(upperband_12_plot, lowerband_12_plot, color=fill_color, title="Fill 12")fill(upperband_13_plot, lowerband_13_plot, color=fill_color, title="Fill 13")fill(upperband_14_plot, lowerband_14_plot, color=fill_color, title="Fill 14")// Add variables to store the highest upper band and lowest lower band valuesvar float highestUpperBand = navar float lowestLowerBand = na// Calculate the trueLevelUpperBand and trueLevelLowerBandtrueLevelUpperBand = max(upperband_1, max(upperband_2, max(upperband_3, max(upperband_4, max(upperband_5, max(upperband_6, max(upperband_7, max(upperband_8, max(upperband_9, max(upperband_10, max(upperband_11, max(upperband_12, max(upperband_13, upperband_14)))))))))))))trueLevelLowerBand = min(lowerband_1, min(lowerband_2, min(lowerband_3, min(lowerband_4, min(lowerband_5, min(lowerband_6, min(lowerband_7, min(lowerband_8, min(lowerband_9, min(lowerband_10, min(lowerband_11, min(lowerband_12, min(lowerband_13, lowerband_14)))))))))))))// Update the highest upper band and lowest lower bandhighestUpperBand := highest(trueLevelUpperBand, 1)lowestLowerBand := lowest(trueLevelLowerBand, 1)// Store the upper and lower bands in an array for easy accessupperbands = array.new_float(14)lowerbands = array.new_float(14)array.set(upperbands, 0, upperband_1)array.set(upperbands, 1, upperband_2)array.set(upperbands, 2, upperband_3)array.set(upperbands, 3, upperband_4)array.set(upperbands, 4, upperband_5)array.set(upperbands, 5, upperband_6)array.set(upperbands, 6, upperband_7)array.set(upperbands, 7, upperband_8)array.set(upperbands, 8, upperband_9)array.set(upperbands, 9, upperband_10)array.set(upperbands, 10, upperband_11)array.set(upperbands, 11, upperband_12)array.set(upperbands, 12, upperband_13)array.set(upperbands, 13, upperband_14)array.set(lowerbands, 0, lowerband_1)array.set(lowerbands, 1, lowerband_2)array.set(lowerbands, 2, lowerband_3)array.set(lowerbands, 3, lowerband_4)array.set(lowerbands, 4, lowerband_5)array.set(lowerbands, 5, lowerband_6)array.set(lowerbands, 6, lowerband_7)array.set(lowerbands, 7, lowerband_8)array.set(lowerbands, 8, lowerband_9)array.set(lowerbands, 9, lowerband_10)array.set(lowerbands, 10, lowerband_11)array.set(lowerbands, 11, lowerband_12)array.set(lowerbands, 12, lowerband_13)array.set(lowerbands, 13, lowerband_14)// Get the selected bands for entry and exitselected_entry_lowerband = array.get(lowerbands, entry_band - 1)selected_exit_upperband = array.get(upperbands, exit_band - 1)// Entry conditionslongCondition = crossover(macdLine, signalLine) or crossover(close, selected_entry_lowerband)shortCondition = crossunder(macdLine, signalLine) or crossunder(close, selected_exit_upperband)// Exit conditionsexitLongCondition = crossunder(macdLine, signalLine) or crossunder(close, selected_exit_upperband)exitShortCondition = crossover(macdLine, signalLine) or crossover(close, selected_entry_lowerband)// Strategy executionstrategy.entry("Long", strategy.long, when = longCondition)strategy.entry("Short", strategy.short, when = shortCondition and long_and_short)strategy.close("Long", when = exitLongCondition)strategy.close("Short", when = exitShortCondition)