Pine Script v5 · Strategy
DMI (Multi timeframe) DI Strategy [KL]
A Pine Script v5 strategy with no technical-analysis calculation. It has 3 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss. Each trade commits 5% of equity and pays no commission. 8 settings; defaults include Adx len 14, DI +/- in Timeframe 2 1D and Alert MSG for buying (Long position) Long entered.
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 DMI (Multi timeframe) DI Strategy [KL] repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did DMI (Multi timeframe) DI Strategy [KL] do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings; it opened a long position that was still open on the last bar, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- What alerts does DMI (Multi timeframe) DI Strategy [KL] have?
- 2
- LONG_MSG_EXIT; LONG_MSG_ENTER.
- Does DMI (Multi timeframe) DI Strategy [KL] run in Pine Script v6?
- Not tested
- Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download.
- Does DMI (Multi timeframe) DI Strategy [KL] use a stop loss?
- Yes
- strategy.exit sets a stop on line 61.
BTCUSDT · 1D · default settings
- Shape
- Shape
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.05%
- −$513,073.00
One run with the author's default settings, $1,000,000,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 commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
1 setting has no label
In the settings dialog adx_len (line 12) 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 |
|---|---|---|---|
| Directional IndicatorDI+ DI- | |||
| Adx len (no label in the script)Typically 14 | 14 | int | smooth_tr smooth_directional_mov_plus smooth_directional_mov_minus |
| DI +/- in Timeframe 1Main: DI+ > DI- | | timeframe | plus_DM_tf1 minus_DM_tf1 |
| DI +/- in Timeframe 2Confirmation: DI+ > DI- | 1D | timeframe | plus_DM_tf2 minus_DM_tf2 |
| Alerts | |||
| Alert MSG for buying (Long position) | Long entered | string | alert |
| Alert MSG for closing (Long position) | Long closed | string | alert |
| Time horizon of backtests | |||
| Backtest Start Time | timestamp("01 Apr 2020 13:30 +0000") | time | within_timeframe |
| Stop loss | |||
| ATR Multiplier for trailing stoploss | 2.0 | float | SL_buffer |
| Length of ATR for trailing stoploss | 14 | int | stop_loss_price_long |
What it calculates
No technical-analysis calculation: the script works on prices and settings directly.
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Close LONG | pos_opened_long and TSL_source_long <= stop_loss_price_long | On | 58 |
| Exit LONG stop | pos_opened_long | On | 61 |
| Open LONG long | within_timeframe and entry_signal_long | On | 66 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| (no title) | alert | LONG_MSG_EXIT | 57 |
| (no title) | alert | LONG_MSG_ENTER | 65 |
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- ClearHigher-timeframe data1 request.security call(s), none with lookahead on.
- 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 | 0.0% | +102.5% | 0 | 0% | — | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 1.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 1.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 1.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 1.7% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 1.6% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.8% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
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.
- 1 setting uses the untyped input() (line 12). 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.
Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 12: input() → input.int()
⋯// ADX Indicator {-adx_len = input(14, group=GROUP_IND, tooltip="Typically 14")+adx_len = input.int(14, group=GROUP_IND, tooltip="Typically 14")tf1 = input.timeframe("", title="DI +/- in Timeframe 1", group=GROUP_IND, tooltip="Main: DI+ > DI-")⋯Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © DojiEmoji-//@version=5+//@version=6strategy("DI+/- multi TF Strat [KL]", overlay=true, pyramiding=1, initial_capital=1000000000, default_qty_type=strategy.percent_of_equity, default_qty_value=5)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 36 ms | Yes 1,000 bars in 126 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/// © DojiEmoji//@version=5strategy("DI+/- multi TF Strat [KL]", overlay=true, pyramiding=1, initial_capital=1000000000, default_qty_type=strategy.percent_of_equity, default_qty_value=5)var string GROUP_ALERT = "Alerts"var string GROUP_SL = "Stop loss"var string GROUP_ORDER = "Order size"var string GROUP_TP = "Profit taking"var string GROUP_HORIZON = "Time horizon of backtests"var string GROUP_IND = "Directional IndicatorDI+ DI-"// ADX Indicator {adx_len = input(14, group=GROUP_IND, tooltip="Typically 14")tf1 = input.timeframe("", title="DI +/- in Timeframe 1", group=GROUP_IND, tooltip="Main: DI+ > DI-")tf2 = input.timeframe("1D", title="DI +/- in Timeframe 2", group=GROUP_IND, tooltip="Confirmation: DI+ > DI-")// adx_thres = input(20, group=GROUP_IND) //threshold not used in this strategyget_ADX(_high, _close, _low) =>// (high, close, mid) -> [plus_DM, minus_DM] // Based on TradingView user BeikabuOyaji's implementation _tr = math.max(math.max(_high - _low, math.abs(_high - nz(_close[1]))), math.abs(_low - nz(_close[1]))) smooth_tr = 0.0 smooth_tr := nz(smooth_tr[1]) - nz(smooth_tr[1]) / adx_len + _tr smooth_directional_mov_plus = 0.0 smooth_directional_mov_plus := nz(smooth_directional_mov_plus[1]) - nz(smooth_directional_mov_plus[1]) / adx_len + (_high - nz(_high[1]) > nz(_low[1]) - _low ? math.max(_high - nz(_high[1]), 0) : 0) smooth_directional_mov_minus = 0.0 smooth_directional_mov_minus := nz(smooth_directional_mov_minus[1]) - nz(smooth_directional_mov_minus[1]) / adx_len + (nz(_low[1]) - _low > _high - nz(_high[1]) ? math.max(nz(_low[1]) - _low, 0) : 0) plus_DM = smooth_directional_mov_plus / smooth_tr * 100 minus_DM = smooth_directional_mov_minus / smooth_tr * 100 // DX = math.abs(plus_DM - minus_DM) / (plus_DM + minus_DM) * 100 // DX not used in this strategy [plus_DM, minus_DM]nrp_security(_symbol, _tf, _src) =>// Wrapper function around request.security() - don't use developing bars request.security(_symbol, _tf, _src[barstate.isrealtime ? 1 : 0], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)// DI +/- from timeframes 1 and 2[plus_DM_tf1, minus_DM_tf1] = get_ADX(nrp_security(syminfo.tickerid, tf1, high), nrp_security(syminfo.tickerid, tf1, close), nrp_security(syminfo.tickerid, tf1, low))[plus_DM_tf2, minus_DM_tf2] = get_ADX(nrp_security(syminfo.tickerid, tf2, high), nrp_security(syminfo.tickerid, tf2, close), nrp_security(syminfo.tickerid, tf2, low))// } end of block: ADX Indicatorvar string ENUM_LONG = "LONG"var string LONG_MSG_ENTER = input.string("Long entered", title="Alert MSG for buying (Long position)", group=GROUP_ALERT)var string LONG_MSG_EXIT = input.string("Long closed", title="Alert MSG for closing (Long position)", group=GROUP_ALERT)backtest_timeframe_start = input.time(defval=timestamp("01 Apr 2020 13:30 +0000"), title="Backtest Start Time", group=GROUP_HORIZON)within_timeframe = time >= backtest_timeframe_start// Signals for entry_uptrend_confirmed = plus_DM_tf1 > minus_DM_tf1 and plus_DM_tf2 > minus_DM_tf2entry_signal_long = _uptrend_confirmedplotshape(_uptrend_confirmed, style=shape.triangleup, location=location.bottom, color=color.green)plotshape(not _uptrend_confirmed, style=shape.triangledown, location=location.bottom, color=color.red)// Trailing stop loss ("TSL") {tsl_multi = input.float(2.0, title="ATR Multiplier for trailing stoploss", group=GROUP_SL)SL_buffer = ta.atr(input.int(14, title="Length of ATR for trailing stoploss", group=GROUP_SL)) * tsl_multiTSL_source_long = lowvar stop_loss_price_long = float(0)var pos_opened_long = falsestop_loss_price_long := pos_opened_long ? math.max(stop_loss_price_long, TSL_source_long - SL_buffer) : TSL_source_long - SL_buffer// MAIN: {if pos_opened_long and TSL_source_long <= stop_loss_price_long pos_opened_long := false alert(LONG_MSG_EXIT, alert.freq_once_per_bar) strategy.close(ENUM_LONG, comment=close < strategy.position_avg_price ? "stop loss" : "take profit")// (2) Update the stoploss to latest trailing amt.if pos_opened_long strategy.exit(ENUM_LONG, stop=stop_loss_price_long, comment="SL")// (3) INITIAL ENTRY:if within_timeframe and entry_signal_long pos_opened_long := true alert(LONG_MSG_ENTER, alert.freq_once_per_bar) strategy.entry(ENUM_LONG, strategy.long, comment="long")// Plotting: TSL_transp_long = pos_opened_long and within_timeframe ? 0 : 100plot(stop_loss_price_long, color=color.new(color.green, TSL_transp_long))// CLEAN UP: Setting variables back to default values once no longer in useif ta.change(strategy.position_size) and strategy.position_size == 0 pos_opened_long := falseif not pos_opened_long stop_loss_price_long := float(0)// } end of MAIN block