Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (22)
50,00075,000100,000125,000AprJulOct2025AprJulOct2026AprJulOct$103,606$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
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

Differs

Trades 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

Verified

Same 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.

SettingDefaultType and rangeFeeds
Fast Length12int (written input.integer)macdLine signalLine
Slow Length26int (written input.integer)macdLine signalLine
Signal Length9int (written input.integer)macdLine signalLine
Entry TrueLevel Band12int (written input.integer) · min 1 · max 14selected_entry_lowerband
Exit TrueLevel Band12int (written input.integer) · min 1 · max 14selected_exit_upperband
Enable Long and Shortfalseboolentry Short
Length 1126int (written input.integer)upperband_1 lowerband_1
Length 2189int (written input.integer)upperband_2 lowerband_2
Length 3252int (written input.integer)upperband_3 lowerband_3
Length 4378int (written input.integer)upperband_4 lowerband_4
Length 5504int (written input.integer)upperband_5 lowerband_5
Length 6630int (written input.integer)upperband_6 lowerband_6
Length 7756int (written input.integer)upperband_7 lowerband_7
Length 81008int (written input.integer)upperband_8 lowerband_8
Length 91260int (written input.integer)upperband_9 lowerband_9
Length 101638int (written input.integer)upperband_10 lowerband_10
Length 112016int (written input.integer)upperband_11 lowerband_11
Length 122646int (written input.integer)upperband_12 lowerband_12
Length 133276int (written input.integer)upperband_13 lowerband_13
Length 144284int (written input.integer)upperband_14 lowerband_14
Fill Colorcolor.rgb(0, 191, 255, 95)colorFill 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
Multiple1float · step 0.2 · options [0.6, 0.8, 1, 1.2, 1.4]stddev
Sourceclosesourcelinreg stddev

What it calculates

  • MACD (macd, ta.macd in v5)close, Fast Length (12), Slow Length (26), Signal Length (9)macdLine · line 15
  • MACD (macd, ta.macd in v5)close, Fast Length (12), Slow Length (26), Signal Length (9)signalLine · line 15
  • Linreg (linreg, ta.linreg in v5)Source (close), length, 0linreg · line 42
  • Stdev (stdev, ta.stdev in v5)Source (close), lengthstddev · line 43
  • Highest (highest, ta.highest in v5)trueLevelUpperBand, 1highestUpperBand · line 126
  • Lowest (lowest, ta.lowest in 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

OrderFires whenBy defaultLine
Open Long longlongConditioncrossover(macdLine, signalLine) or crossover(close, selected_entry_lowerband)On169
Open Short shortshortCondition and long_and_shortOn170
Close LongexitLongConditioncrossunder(macdLine, signalLine) or crossunder(close, selected_exit_upperband)On171
Close ShortexitShortConditioncrossover(macdLine, signalLine) or crossover(close, selected_entry_lowerband)On172

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.

11/11trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+3.6%+102.5%3837%1.403.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.7%+5.5%3435%1.630.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.0%+9.8%3631%1.007.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+1.2%+8.4%3826%1.241.7%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+7.1%+16.7%3250%1.476.9%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+1.5%+21.5%3534%1.341.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+1.5%+148.3%3450%1.233.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+1.0%+17.1%3834%1.281.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.

Before 26 Dec 2025 · in-sample
Slow Length ↓ · Fast Length →6781012141720
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%
From 26 Dec 2025 · out-of-sample
Slow Length ↓ · Fast Length →6781012141720
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 barsTradesWonP&L
Rising market1331%$1,341.83
Sideways market1844%$3,148.78
Falling market729%−$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.

0%6%
All 38 trades
SideEntryExitBarsP&L
long6 May 2024 64,012.0012 May 2024 60,826.006−$497.72
long13 May 2024 61,484.0031 May 2024 68,352.2018$1,111.51
long6 Jun 2024 71,108.009 Jun 2024 69,310.503−$254.34
long13 Jul 2024 57,889.101 Aug 2024 64,628.0019$1,168.29
long20 Aug 2024 59,438.5031 Aug 2024 59,124.0011−$53.72
long13 Sep 2024 58,132.302 Oct 2024 60,804.9019$466.52
long15 Oct 2024 66,084.0027 Oct 2024 67,092.8012$155.61
long29 Oct 2024 69,962.204 Nov 2024 68,776.006−$173.11
long7 Nov 2024 75,572.0027 Nov 2024 91,965.2020$2,210.93
long17 Dec 2024 106,059.0019 Dec 2024 100,204.002−$574.84
long6 Jan 2025 98,363.6010 Jan 2025 92,552.504−$611.81
long16 Jan 2025 100,497.0029 Jan 2025 101,336.0013$85.86
long21 Feb 2025 98,305.0025 Feb 2025 91,552.904−$707.69
long7 Mar 2025 89,931.909 Mar 2025 86,222.502−$422.06
long16 Mar 2025 84,338.407 Apr 2025 78,430.0022−$713.90
long12 Apr 2025 83,423.8018 May 2025 103,127.0036$2,389.87
long19 May 2025 106,454.0020 May 2025 105,574.001−$85.68
long22 May 2025 109,644.0025 May 2025 107,762.003−$177.65
long11 Jun 2025 110,274.0013 Jun 2025 105,672.002−$431.22
long27 Jun 2025 106,947.0022 Jul 2025 117,380.0025$1,003.70
long23 Jul 2025 119,954.0024 Jul 2025 118,756.001−$103.79
long12 Aug 2025 118,686.0018 Aug 2025 117,405.006−$112.02
long7 Sep 2025 110,188.0024 Sep 2025 111,999.0017$170.38
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$509.65
long27 Oct 2025 114,559.004 Nov 2025 106,583.008−$719.47
long28 Nov 2025 91,333.9018 Dec 2025 86,243.2020−$571.94
long21 Dec 2025 88,360.9021 Jan 2026 88,427.7031$7.71
long16 Feb 2026 68,832.6023 Mar 2026 67,859.0035−$144.34
long26 Mar 2026 71,336.5027 Mar 2026 68,820.301−$359.45
long7 Apr 2026 68,853.7029 Apr 2026 76,342.8022$1,104.50
long5 May 2026 79,861.0013 May 2026 80,504.508$82.71
long14 Jun 2026 64,458.0028 Jun 2026 60,029.0014−$705.89
long30 Jun 2026 60,260.201 Jul 2026 58,624.701−$276.91
long2 Jul 2026 60,024.0028 Jul 2026 63,755.9026$632.61
long8 Aug 2026 64,923.2012 Aug 2026 63,600.004−$208.66
long19 Aug 2026 64,725.403 Sep 2026 77,340.0015$1,991.32
long4 Sep 2026 81,270.405 Sep 2026 79,660.801−$206.31
long22 Sep 2026 86,620.0030 Sep 2026 83,663.708−$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.

ScriptSharesTypeNetTradesMax drawdown
MACD TrueLevel Strategy this page—v4 strategy+3.6%383.0%
VixFixLinReg-Strategy by Trendoscopehighest stdev lowest linregv4 strategy−49.3%1251.1%
RSI TrueLevel Strategy by Julien_Echelinreg stdev highest lowestv4 strategy+2.8%105.1%
Lawyers Trend Pro Strategy by ErdemDemirstdev lowest highestv4 strategy+12.1%10241.7%
BTC Volatility Band Strategy by gary_tradesstdev lowest highestv4 strategy−33.5%8045.0%
Chandelier Exit ZLSMA Strategy by simwaihighest lowest linregv5 strategy+2.4%82.2%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 49 msYes 1,000 bars in 268 msNot measured
PineTSNo 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)