Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (8)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,051,260,000$2,025,272,873Equity from $1,000,000,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
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.

SettingDefaultType and rangeFeeds
Directional IndicatorDI+ DI-
Adx len (no label in the script)Typically 1414intsmooth_tr smooth_directional_mov_plus smooth_directional_mov_minus
DI +/- in Timeframe 1Main: DI+ > DI-timeframeplus_DM_tf1 minus_DM_tf1
DI +/- in Timeframe 2Confirmation: DI+ > DI-1Dtimeframeplus_DM_tf2 minus_DM_tf2
Alerts
Alert MSG for buying (Long position)Long enteredstringalert
Alert MSG for closing (Long position)Long closedstringalert
Time horizon of backtests
Backtest Start Timetimestamp("01 Apr 2020 13:30 +0000")timewithin_timeframe
Stop loss
ATR Multiplier for trailing stoploss2.0floatSL_buffer
Length of ATR for trailing stoploss14intstop_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.

adx_lenAdx lensetting · 14lowlowprice dataclosecloseprice datahighhighprice datatf1DI +/- in Timeframe 1setting · tf2DI +/- in Timeframe 2setting · 1DSL_bufferLength of ATR for trail…setting · 14timetimeprice databacktest_timeframe_startBacktest Start Timesetting · timestamp("01 Apr 2…LONG_MSG_EXITAlert MSG for closing (…setting · Long closedLONG_MSG_ENTERAlert MSG for buying (L…setting · Long entered_tr_trvaluesmooth_trsmooth_trvaluesmooth_directional_mov_plussmooth_directional_mov_…valuesmooth_directional_mov_minussmooth_directional_mov_…valueplus_DMplus_DMvalueminus_DMminus_DMvalueplus_DM_tf1, minus_DM_tf1plus_DM_tf1 · minus_DM_…2 valuesplus_DM_tf2, minus_DM_tf2plus_DM_tf2 · minus_DM_…2 valuesentry_signal_longentry_signal_longvalueTSL_source_longTSL_source_longvaluestop_loss_price_longstop_loss_price_longvalueTSL_transp_longTSL_transp_longvaluewithin_timeframewithin_timeframecondition_uptrend_confirmed_uptrend_confirmedconditionclose:LONGClose LONGstrategy.closeexit:LONGexit LONGstrategy.exitentry:LONGOpen LONGstrategy.entryplotshape:45plotshapeplotshapeplotshape:46plotshapeplotshapealert:57alertalertalert:65alertalertplot:69plotplot

Order rules

OrderFires whenBy defaultLine
Close LONGpos_opened_long and TSL_source_long <= stop_loss_price_longOn58
Exit LONG stoppos_opened_longOn61
Open LONG longwithin_timeframe and entry_signal_longOn66

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
(no title)alertLONG_MSG_EXIT57
(no title)alertLONG_MSG_ENTER65

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D0.0%+102.5%00%—0.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—1.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—1.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—1.7%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—1.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—1.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—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 verified

Neither 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 36 msYes 1,000 bars in 126 msNot measured
PineTSNot testedNot testedNot 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