Pine Script v5 · Strategy
[MACLEN] TRUE RANGE
A Pine Script v5 strategy built on TR and WMA (sube, 10). It has 8 order rules, 5 entries among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is 0.1 contracts and pays 0.08% commission. 10 settings; defaults include Corto 10, Largo 30 and Suavizado 10.
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 [MACLEN] TRUE RANGE repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did [MACLEN] TRUE RANGE do on BTCUSDT 1D with default settings?
- +2.51%
- From 26 Jan 2024 to 21 Oct 2026, over 27 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does [MACLEN] TRUE RANGE 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: 27 before, 27 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 [MACLEN] TRUE RANGE use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does [MACLEN] TRUE RANGE run in Zeal Terminal?
- Yes
- It compiles in 77 ms and runs 1,000 bars in 69 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
| Open P/L= 0 Price Change = NaN% Capital Usado = 0 |
- Net profit
- +2.51%
- $25.11
- Buy and hold
- +102.5%
- same period
- Closed trades
- 27
- 15 won · 12 lost
- Profitable
- 55.6%
- of closed trades
- Profit factor
- 1.30
- gross profit ÷ gross loss
- Max drawdown
- 3.48%
- −$35.04
One run with the author's default settings, $1,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
1 setting does nothing
“Porc tp” is declared but never read.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Note
6 settings have no label
In the settings dialog corto (line 12), largo (line 13), suavizado (line 14), lev (line 26), porc_tp (line 38), safe (line 39) show an empty name. The labels on this page come from the variable names.
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 Window | |||
| Start Time | timestamp("01 Jan 2022 00:00 -0700") | time | window |
| End Time | timestamp("31 Dec 2025 00:00 -0700") | time | window |
| Largo (no label in the script) | 30 | int | slowDiff |
| Suavizado (no label in the script) | 10 | int | ind |
| Lev (no label in the script) | 2 | int | contrato1 labelText close_all close_all line 61 |
| Porc tp (no label in the script) | 6.5 | float · step 0.1 | unused |
| Safe (no label in the script) | -6.0 | float · step 0.1 | entry SAFE1 entry SAFE2 entry SAFE3 entry SAFE4 line 45 line 48 line 51 line 54 |
| StopLoss | -5.0 | float · step 0.1 | close_all line 65 |
| Configuración | |||
| Corto (no label in the script) | 10 | int | fastDiff |
| Gestión de Riesgo | |||
| Capital Inicial | 1000 | int | contrato1 |
What it calculates
- TR
sube · line 10 - TR
baja · line 11 - WMAsube, Corto (10)
fastDiff · line 15 - WMAsube, Largo (30)
slowDiff · line 16 - WMAfastDiff - slowDiff, Suavizado (10)
ind · line 17
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 BUY long | strategy.opentrades == 0 and long and not long[1] and window | On | 43 |
| Open SAFE1 long | strategy.opentrades == 1 and long and not long[1] and window and change<safe | On | 46 |
| Open SAFE2 long | strategy.opentrades == 2 and long and not long[1] and window and change<safe | On | 49 |
| Open SAFE3 long | strategy.opentrades == 3 and long and not long[1] and window and change<safe | On | 52 |
| Open SAFE4 long | strategy.opentrades == 4 and long and not long[1] and window and change<safe | On | 55 |
| Close | (short and min_prof) | On | 59 |
| Close | math.abs(strategy.openprofit) >= (used/lev) | On | 62 |
| Close | change<=sl | On | 66 |
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 | +2.5% | +102.5% | 27 | 56% | 1.30 | 3.5% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −6.6% | +9.8% | 30 | 33% | 0.63 | 10.6% | 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.6% | +16.7% | 30 | 43% | 0.97 | 7.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +4.9% | +148.3% | 33 | 58% | 1.41 | 2.5% | 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 | 9 | 56% | $23.44 |
| Sideways market | 14 | 50% | −$12.70 |
| Falling market | 4 | 75% | $14.36 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
5.2%
The 95th percentile of the worst drawdown when the same 27 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.1% to 5.2%; the tick is what actually happened, 3.1%. Order luck alone moves it this much.
All 27 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 25 Mar 2024 67,210.00 | 5 Apr 2024 68,487.80 | 11 | $2.17 |
| long | 21 Apr 2024 64,940.60 | 1 May 2024 60,672.00 | 10 | −$8.41 |
| long | 5 May 2024 63,892.00 | 23 May 2024 69,166.60 | 18 | $10.11 |
| long | 3 Jun 2024 67,765.60 | 9 Jun 2024 69,310.50 | 6 | $2.65 |
| long | 18 Jun 2024 66,504.30 | 25 Jun 2024 60,293.30 | 7 | −$11.86 |
| long | 27 Jun 2024 60,865.00 | 5 Jul 2024 57,050.00 | 8 | −$8.03 |
| long | 10 Aug 2024 60,838.00 | 16 Aug 2024 57,541.10 | 6 | −$6.97 |
| long | 6 Sep 2024 56,180.00 | 25 Sep 2024 64,262.70 | 19 | $17.77 |
| long | 13 Oct 2024 63,206.20 | 23 Oct 2024 67,426.00 | 10 | $8.14 |
| long | 8 Nov 2024 75,857.90 | 17 Nov 2024 90,588.00 | 9 | $24.05 |
| long | 5 Dec 2024 98,587.30 | 31 Dec 2024 92,792.10 | 26 | −$7.54 |
| long | 2 Jan 2025 94,591.80 | 11 Jan 2025 94,726.10 | 9 | −$0.02 |
| long | 19 Jan 2025 104,556.00 | 31 Jan 2025 104,723.00 | 12 | −$0.00 |
| long | 11 Feb 2025 97,430.80 | 25 Feb 2025 91,552.90 | 14 | −$7.74 |
| long | 4 Mar 2025 86,221.20 | 10 Mar 2025 80,734.50 | 6 | −$8.15 |
| long | 5 Apr 2025 83,889.90 | 7 Apr 2025 78,430.00 | 2 | −$8.33 |
| long | 9 Apr 2025 76,322.40 | 19 Apr 2025 84,474.70 | 10 | $13.14 |
| long | 8 May 2025 97,030.50 | 19 Jun 2025 104,887.00 | 42 | $9.91 |
| long | 26 Jun 2025 107,341.00 | 6 Jul 2025 108,198.00 | 10 | $0.80 |
| long | 5 Aug 2025 115,055.00 | 16 Aug 2025 117,342.00 | 11 | $2.28 |
| long | 24 Aug 2025 115,438.00 | 30 Aug 2025 108,377.00 | 6 | −$7.84 |
| long | 1 Sep 2025 108,246.00 | 8 Sep 2025 111,137.00 | 7 | $3.14 |
| long | 30 Sep 2025 114,312.00 | 9 Oct 2025 123,306.00 | 9 | $9.63 |
| long | 20 Oct 2025 108,643.00 | 1 Nov 2025 109,608.00 | 12 | $0.91 |
| long | 9 Nov 2025 102,313.00 | 15 Nov 2025 94,594.00 | 6 | −$9.62 |
| long | 25 Nov 2025 88,300.00 | 6 Dec 2025 89,330.00 | 11 | $1.26 |
| long | 23 Dec 2025 88,620.80 | 8 Jan 2026 91,364.20 | 16 | $3.67 |
Similar scripts
No other indicator or strategy here shares enough of its calculations.
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 4 settings use the untyped input() (line 12, 13, 14, 28). 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 27 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 12: input() → input.int()
- Line 13: input() → input.int()
- Line 14: input() → input.int()
- Line 28: input() → input.int()
⋯baja = close<close[1] ? ta.tr : 0-corto = input(10, group="Configuración")+corto = input.int(10, group="Configuración")-largo = input(30)+largo = input.int(30)-suavizado = input(10)+suavizado = input.int(10)fastDiff = ta.wma(sube, corto) - ta.wma(baja,corto)⋯//Contratos-capital = input(defval=1000, title="Capital Inicial", group="Gestión de Riesgo")+capital = input.int(defval=1000, title="Capital Inicial", group="Gestión de Riesgo")contrato1 = (capital*lev)/(16*close)⋯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: 27 before, 27 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.
⋯// © MaclenMtz-//@version=5+//@version=6strategy("[MACLEN] Rangos", shorttitle="Rangos [https://t.me/Bitcoin_Maclen]", overlay=false, slippage=0, initial_capital=1000, currency=currency.USD, default_qty_type=strategy.fixed, default_qty_value=0.1, pyramiding=5, commission_type=strategy.commission.percent, commission_value=0.08)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 77 ms | Yes 1,000 bars in 69 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/// © MaclenMtz//@version=5strategy("[MACLEN] Rangos", shorttitle="Rangos [https://t.me/Bitcoin_Maclen]", overlay=false, slippage=0, initial_capital=1000, currency=currency.USD, default_qty_type=strategy.fixed, default_qty_value=0.1, pyramiding=5, commission_type=strategy.commission.percent, commission_value=0.08)//------WINDOW----------i_startTime = input.time(defval = timestamp("01 Jan 2022 00:00 -0700"), title = "Start Time", group = "Backtest Window")i_endTime = input.time(defval = timestamp("31 Dec 2025 00:00 -0700"), title = "End Time")window = time >= i_startTime and time <= i_endTime//-----------------------------sube = close>close[1] ? ta.tr : 0baja = close<close[1] ? ta.tr : 0corto = input(10, group="Configuración")largo = input(30)suavizado = input(10)fastDiff = ta.wma(sube, corto) - ta.wma(baja,corto)slowDiff = ta.wma(sube, largo) - ta.wma(baja, largo)ind = ta.wma(fastDiff - slowDiff, suavizado)iColor = ind>0 ? color.green : ind<0 ? color.red : color.blackplot(ind, color=iColor)plot(0, color=color.white)long = ind[1]<ind and ind[2]<ind[1] and ind<0short = ind[1]>ind and ind[2]>ind[1] and ind>0plotshape(long and not long[1], style = shape.xcross, color=color.green, location=location.bottom, size=size.tiny)plotshape(short and not short[1], style = shape.xcross, color=color.red, location=location.top, size=size.tiny)//Apalancamientolev = input.int(2)//Contratoscapital = input(defval=1000, title="Capital Inicial", group="Gestión de Riesgo")contrato1 = (capital*lev)/(16*close)c1 = contrato1c2 = contrato1c3 = contrato1*2c4 = contrato1*4c5 = contrato1*8//cap_enopentrade = strategy.opentrades == 1 ? c1: strategy.opentrades == 2 ? c1+c2: strategy.opentrades == 3 ? c1+c2+c3: strategy.opentrades == 4 ? c1+c2+c3+c4: strategy.opentrades == 5 ? c1+c2+c3+c4+c5 : 0change = math.round((close-strategy.position_avg_price)/strategy.position_avg_price * 100,2)var float used = 0porc_tp = input.float(6.5, step=0.1)safe = input.float(-6.0, step=0.1)sl = input.float(-5.0, title="StopLoss", step=0.1)//----------------Strategy---------------------------if strategy.opentrades == 0 and long and not long[1] and window strategy.entry('BUY', strategy.long, qty=c1, comment="Buy") used := used + (c1*close)if strategy.opentrades == 1 and long and not long[1] and window and change<safe strategy.entry('SAFE1', strategy.long, qty=c2, comment="Safe1") used := used + (c2*close)if strategy.opentrades == 2 and long and not long[1] and window and change<safe strategy.entry('SAFE2', strategy.long, qty=c3, comment="Safe2") used := used + (c3*close)if strategy.opentrades == 3 and long and not long[1] and window and change<safe strategy.entry('SAFE3', strategy.long, qty=c4, comment="Safe3") used := used + (c4*close)if strategy.opentrades == 4 and long and not long[1] and window and change<safe strategy.entry('SAFE4', strategy.long, qty=c5, comment="Safe4") used := used + (c5*close)min_prof = strategy.openprofit>0if (short and min_prof) strategy.close_all(comment="Close (Profit= "+ str.tostring(math.round(change,2)*lev)+"%)") used := 0if math.abs(strategy.openprofit) >= (used/lev) strategy.close_all(comment="LIQ") used := 0 if change<=sl strategy.close_all(comment="SL") used := 0//plot (strategy.openprofit)//plot(strategy.position_size)//plot(change)//plot(used/lev)var table display = table.new(position.top_right,1,1)labelText = "Open P/L= " + str.tostring(math.round(strategy.openprofit,2)) + "\n" + "Price Change = " + str.tostring(change) + "%" + "\n" + "Capital Usado = " + str.tostring(used/lev)table.cell(display,0,0, labelText, text_size=size.normal)