Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Directional Movement Index

A Pine Script v5 strategy built on Lowest (Length), Highest (Length) and BB (20, 1). It has 6 order rules, 3 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 100.0% of equity and pays 0.1% commission. 12 settings; defaults include Position Type Long/Short, Conversion Periods 9 and Base Periods 26.

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 Directional Movement Index repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Directional Movement Index do on BTCUSDT 1D with default settings?
+49.71%
From 26 Jan 2024 to 21 Oct 2026, over 35 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Directional Movement Index 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: 35 before, 35 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 Directional Movement Index use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Directional Movement Index run in Zeal Terminal?
Yes
It compiles in 60 ms and runs 1,000 bars in 166 ms, in the browser.

BTCUSDT · 1D · default settings

  • Tenkan
  • Kijun
  • Chikou
  • SenkouA
  • SenkouB
  • ADX
  • +DI
  • -DI
  • Long - Entry Labels
  • Long - Exit Labels
  • Short - Entry Labels
  • Short - Exit Labels
  • 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 (10)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$150$203Equity from $100
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
+49.71%
$49.71
Buy and hold
+102.5%
same period
Closed trades
35
16 won · 19 lost
Profitable
45.7%
of closed trades
Profit factor
1.66
gross profit ÷ gross loss
Max drawdown
19.38%
−$28.30

One run with the author's default settings, $100 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

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    4 settings have no label

    In the settings dialog conversionPeriods (line 16), basePeriods (line 17), laggingSpan2Periods (line 18), displacement (line 19) show an empty name. The labels on this page come from the variable names.

  • Note

    Uses an argument v6 removed

    when = on line 127, 128, 129, 130, 132, 133. The upgraded version below moves each call inside an if block.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Trading Settings
Position TypeLong/Shortstring · options ["Long/Short", "Long"]entry Long close Long entry Short close Short entry Long close Long Long - Entry Bar Long - Exit Bar Long - Entry Labels Long - Exit Labels Short - Entry Labels Short - Exit Labels line 126 line 131
Testing Start Datetimestamp("2017-01-01T00:00:00")time_testperiod
Testing End Datetimestamp("2025-01-01T00:00:00")time_testperiod
Ichimoku Kinko Hyo - Settings
Conversion Periods (no label in the script)9int · min 1Tenkan
Base Periods (no label in the script)26int · min 1Kijun SenkouB
Lagging Span2Periods (no label in the script)52int · min 1SenkouA
Displacement (no label in the script)26int · min 1SenkouB SenkouA SenkouB red_kumo_cloud green_kumo_cloud chikou_open_space tenkan_in_cloud kijun_in_cloud price_in_green_cloud price_in_red_cloud chikou_in_cloud cloud_thickness percent_thick_cloud red_2_green_cloud green_2_red_cloud close_above_cloud tenkan_over_cloud kijun_crosses_red_cloud Chikou
ADX / DMI - Setting
ADX Smoothing14int · min 1 · max 50dmi_adx
DI Length7int · min 1dmi_rma dmi_plus dmi_minus
Consolidation ADX25intdmi_consld dmi_strong_up dmi_strong_down
Signals Style - Setting
Long Entrycolor.new(color.teal,0)colorLong - Entry Bar Long - Entry Labels
Long Exitcolor.new(color.purple,0)colorLong - Exit Bar Long - Exit Labels

What it calculates

  • LowestLengthlower · line 14
  • HighestLengthupper · line 14
  • BBseries = close, length = 20, mult = 1close_middle_bb · line 40
  • BBseries = close, length = 20, mult = 1close_upper_bb · line 40
  • BBseries = close, length = 20, mult = 1close_lower_bb · line 40
  • Highestpercent_thick_cloud, 10000thickest_cloud · line 52
  • CrossoverTenkan, Kijuntenkan_crossover_kijun · line 69
  • Changehighdmi_up · line 77
  • Changelowdmi_down · line 78
  • RMAta.tr, DI Length (7)dmi_rma · line 81
  • RMAdmi_plusDM, DI Length (7)dmi_plus · line 82
  • RMAdmi_minusDM, DI Length (7)dmi_minus · line 83
  • RMAmath.abs(dmi_plus - dmi_minus) / (dmi_sum == 0 ? 1 : dmi_sum), ADX Smoothing (14)dmi_adx · line 85

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 98 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Long longlong_e and _testperiodOn127
Close Longlong_x and _testperiodOn128
Open Short shortshort_e and _testperiodOn129
Close Shortshort_x and _testperiodOn130
Open Long longlong_e and _testperiodOn132
Close Longlong_x and _testperiodOn133

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.

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 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+49.7%+102.5%3546%1.6619.4%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+82.0%+9.8%2752%1.9323.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+13.4%+16.7%4045%1.1334.9%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−25.1%+148.3%3540%0.6542.7%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—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 barsTradesWonP&L
Rising market1644%$59.70
Sideways market1947%−$9.99
Falling market0—$0.00

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

28.0%

The 95th percentile of the worst drawdown when the same 35 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 12.7% to 28.0%; the tick is what actually happened, 16.1%. Order luck alone moves it this much.

0%32%
All 35 trades
SideEntryExitBarsP&L
long16 Feb 2024 51,880.0016 Mar 2024 69,499.8029$33.70
short16 Mar 2024 69,499.8026 Mar 2024 69,880.0010−$1.00
long26 Mar 2024 69,880.002 Apr 2024 69,649.807−$0.70
short2 Apr 2024 69,649.807 Apr 2024 68,896.005$1.17
long7 Apr 2024 68,896.0012 Apr 2024 70,006.205$1.88
short13 Apr 2024 67,116.5014 Apr 2024 63,924.501$6.15
long5 May 2024 63,892.009 May 2024 61,193.004−$6.23
short9 May 2024 61,193.0010 May 2024 63,074.001−$4.42
long16 May 2024 66,206.502 Jun 2024 67,766.8017$2.81
long4 Jun 2024 68,809.9012 Jun 2024 67,314.208−$3.16
short12 Jun 2024 67,314.2016 Jun 2024 66,228.304$1.84
long15 Jul 2024 60,797.9026 Jul 2024 65,799.9011$10.58
short26 Jul 2024 65,799.9027 Jul 2024 67,908.001−$4.86
long27 Jul 2024 67,908.002 Aug 2024 65,354.006−$5.45
short2 Aug 2024 65,354.0019 Aug 2024 58,427.4017$13.77
long22 Aug 2024 61,156.0028 Aug 2024 59,415.006−$4.44
short28 Aug 2024 59,415.0029 Aug 2024 59,034.901$0.62
long14 Sep 2024 60,498.0017 Sep 2024 58,214.003−$5.64
short17 Sep 2024 58,214.0018 Sep 2024 60,314.001−$5.21
long18 Sep 2024 60,314.001 Oct 2024 63,327.6013$6.30
short1 Oct 2024 63,327.608 Oct 2024 62,224.007$2.13
long8 Oct 2024 62,224.0010 Oct 2024 60,636.002−$3.84
short10 Oct 2024 60,636.0012 Oct 2024 62,540.002−$4.55
long12 Oct 2024 62,540.0014 Oct 2024 62,870.002$0.43
short14 Oct 2024 62,870.0015 Oct 2024 66,084.001−$7.01
long15 Oct 2024 66,084.0024 Oct 2024 66,668.609$0.85
short24 Oct 2024 66,668.6025 Oct 2024 68,198.301−$3.14
long25 Oct 2024 68,198.304 Nov 2024 68,776.0010$0.79
short4 Nov 2024 68,776.005 Nov 2024 67,850.001$1.42
long6 Nov 2024 69,372.0027 Nov 2024 91,965.1021$40.30
short27 Nov 2024 91,965.1028 Nov 2024 95,863.101−$7.33
long28 Nov 2024 95,863.104 Dec 2024 95,849.706−$0.34
short4 Dec 2024 95,849.705 Dec 2024 98,587.301−$4.82
long5 Dec 2024 98,587.3020 Dec 2024 97,461.9015−$2.05
short20 Dec 2024 97,461.9021 Dec 2024 97,805.401−$0.83

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
Directional Movement Index this page—v5 strategy+49.7%3519.4%
Wilder's Volatility Trailing Stop Strategy with various MA's by SparkyFlaryrma lowest highestv4 strategy+16.9%1541.6%
Simple RSI strategy by RafaelZionirma highest lowestv4 strategy−11.0%11924.4%
HiLo Extension by Saravanan_Ragavanlowest highest rmav4 strategyNo trades on this market
Bollinger -B Candles Strategy by Trendoscopebb lowest highestv4 strategy+17.3%295.1%
Bollinger Bands Modified (Stormer) by AugustoErnibb highest lowestv5 strategy−7.8%298.0%

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.

  • 6 strategy calls use the when = argument (line 127, 128, 129, 130, 132, 133). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

Same 35 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 127: when = long_e and _testperiod → if block
  • Line 128: when = long_x and _testperiod → if block
  • Line 129: when = short_e and _testperiod → if block
  • Line 130: when = short_x and _testperiod → if block
  • Line 132: when = long_e and _testperiod → if block
  • Line 133: when = long_x and _testperiod → if block
⋯if trade_type == "Long/Short" and _check-    strategy.entry("Long", strategy.long, comment=" ", when=long_e and _testperiod)+    if long_e and _testperiod+        strategy.entry("Long", strategy.long, comment=" ")-    strategy.close("Long", comment=" ", when=long_x and _testperiod)+    if long_x and _testperiod+        strategy.close("Long", comment=" ")-    strategy.entry("Short", strategy.short, comment=" ", when=short_e and _testperiod)+    if short_e and _testperiod+        strategy.entry("Short", strategy.short, comment=" ")-    strategy.close("Short", comment=" ", when=short_x and _testperiod)+    if short_x and _testperiod+        strategy.close("Short", comment=" ")if trade_type == "Long" and _check-    strategy.entry("Long", strategy.long, comment=" ", when=long_e and _testperiod)+    if long_e and _testperiod+        strategy.entry("Long", strategy.long, comment=" ")-    strategy.close("Long", comment=" ", when=long_x and _testperiod)+    if long_x and _testperiod+        strategy.close("Long", comment=" ")

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: 35 before, 35 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.

⋯// ©wojak_bogdanoff-// @version=5+// @version=6// Directional Movement Index (DMI)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 60 msYes 1,000 bars in 166 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/// ©wojak_bogdanoff// @version=5// Directional Movement Index (DMI)strategy(title="Directional Movement Index", shorttitle="DMI︎", overlay=true, pyramiding=1, calc_on_every_tick=false, calc_on_order_fills=false, initial_capital=100.0, default_qty_type=strategy.percent_of_equity, default_qty_value=100.0, commission_type=strategy.commission.percent, commission_value=0.1, slippage=1)trade_type = input.string(defval = "Long/Short", title="Position Type", options=["Long/Short", "Long"], group='Trading Settings')strategy_type = 'DMI'start_date  = input.time(title='Testing Start Date', defval=timestamp("2017-01-01T00:00:00"), group='Trading Settings')finish_date = input.time(title='Testing End Date', defval=timestamp("2025-01-01T00:00:00"), group='Trading Settings')_testperiod = time >= start_date and time <= finish_date_check = _testperiod// --- (Start) Ichimoku kinko Hyo ------------------------------------------- // Credits : LonesomeTheBluemiddleDonchian(Length) =>    lower = ta.lowest(Length), upper = ta.highest(Length)    math.avg(upper, lower)conversionPeriods = input.int(defval=9, minval=1, group='Ichimoku Kinko Hyo - Settings')basePeriods = input.int(defval=26, minval=1, group='Ichimoku Kinko Hyo - Settings')laggingSpan2Periods = input.int(defval=52, minval=1, group='Ichimoku Kinko Hyo - Settings')displacement = input.int(defval=26, minval=1, group='Ichimoku Kinko Hyo - Settings')Tenkan = middleDonchian(conversionPeriods)Kijun =  middleDonchian(basePeriods)xChikou = closeSenkouA = middleDonchian(laggingSpan2Periods)SenkouB = (Tenkan[basePeriods-displacement] + Kijun[basePeriods-displacement]) / 2plot(Tenkan, color=color.red, title="Tenkan", linewidth=2, display=display.all)plot(Kijun, color=color.blue, title="Kijun", linewidth=2, display=display.all)plot(xChikou, color= color.lime , title="Chikou", offset = -displacement, display=display.all)A = plot(SenkouA, color=color.new(color.red,70), title="SenkouA", offset=displacement, display=display.none)B = plot(SenkouB, color=color.new(color.green,70), title="SenkouB", offset=displacement, display=display.none)fill(A, B, color= (SenkouA > SenkouB) ? color.new(color.red,90) : color.new(color.green,90), title='Kumo Cloud')// --- (End) Ichimoku kinko Hyo --------------------------------------------- //// --- (Start) Ichimoku conditions ------------------------------------------ // Credits : ThermalWindsred_kumo_cloud = SenkouA[displacement] > SenkouB[displacement] // Verifiedgreen_kumo_cloud = SenkouA[displacement] < SenkouB[displacement] // Verifiedred_kumo_cloud_future = SenkouA > SenkouB // Verifiedgreen_kumo_cloud_future = SenkouA < SenkouB // Verifiedclose_crosses_kijun = close > Kijun and close[1] < Kijun[1] // Verifiedtenkan_over_kijun = Tenkan > Kijun // Verifiedtenkan_below_kijun_tenkan_up_kijun_flat = (Tenkan < Kijun) and (ta.change(Tenkan, 1) > 0) and (Kijun[0] == Kijun[1]) // Verified[close_middle_bb, close_upper_bb, close_lower_bb] = ta.bb(series=close, length=20, mult=1)chikou_open_space = (xChikou < close_lower_bb[displacement] and xChikou < SenkouA[2*displacement] and xChikou < SenkouB[2*displacement] and xChikou < 2*low[displacement]) or (xChikou > close_upper_bb[displacement] and xChikou > SenkouA[2*displacement] and xChikou > SenkouB[2*displacement] and xChikou > 2*high[displacement]) // Verifiedfuture_senkouB_up_flat =  green_kumo_cloud_future and (ta.change(SenkouB, 1) > 0 or SenkouB[0] == SenkouB[1]) // Verifiedtenkan_in_cloud = (Tenkan < SenkouA[displacement] and Tenkan > SenkouB[displacement]) or (Tenkan > SenkouA[displacement] and Tenkan < SenkouB[displacement]) // Verifiedkijun_in_cloud = (Kijun < SenkouA[displacement] and Kijun > SenkouB[displacement]) or (Kijun > SenkouA[displacement] and Kijun < SenkouB[displacement]) // Verifiedprice_in_green_cloud = green_kumo_cloud and ((open < SenkouB[displacement] and open > SenkouA[displacement]) or (high < SenkouB[displacement] and high > SenkouA[displacement]) or (low < SenkouB[displacement] and low > SenkouA[displacement]) or (close < SenkouB[displacement] and close > SenkouA[displacement])) // Verifiedprice_in_red_cloud = red_kumo_cloud and ((open < SenkouA[displacement] and open > SenkouB[displacement]) or (high < SenkouA[displacement] and high > SenkouB[displacement]) or (low < SenkouA[displacement] and low > SenkouB[displacement]) or (close < SenkouA[displacement] and close > SenkouB[displacement])) // Verifiedprice_in_cloud = price_in_green_cloud or price_in_red_cloud // Verifiedchikou_in_cloud = (green_kumo_cloud[displacement] and (xChikou < SenkouB[2*displacement] and xChikou > SenkouA[2*displacement])) or (red_kumo_cloud[displacement] and (xChikou < SenkouA[2*displacement] and xChikou > SenkouB[2*displacement])) // Verifiedprice_tenkan_kijun_chikou_not_in_cloud = (not tenkan_in_cloud) and (not kijun_in_cloud) and (not price_in_cloud) and (not chikou_in_cloud) // Verifiedcloud_thickness = math.abs(SenkouA[displacement] - SenkouB[displacement])percent_thick_cloud = green_kumo_cloud ? (cloud_thickness * 100) / SenkouA[displacement] : (cloud_thickness * 100) / SenkouB[displacement]thickness_threshold = 14, thickest_cloud = ta.highest(percent_thick_cloud, 10000)thick_cloud = percent_thick_cloud >= (thickest_cloud * (thickness_threshold/100)) // Verifiedprice_tenkan_kijun_chikou_in_thick_cloud = (not price_tenkan_kijun_chikou_not_in_cloud) and thick_cloud // Verifiedproximity_mult = 0.001 // 0.1 %tenkan_middle_bb = Tenkan + (Tenkan*0), tenkan_upper_bb = Tenkan + (Tenkan*proximity_mult), tenkan_lower_bb = Tenkan + (Tenkan*-proximity_mult)kijun_middle_bb = Kijun + (Kijun*0), kijun_upper_bb = Kijun + (Kijun*proximity_mult), kijun_lower_bb = Kijun + (Kijun*-proximity_mult)price_near_tenkan = (open < tenkan_upper_bb and open > tenkan_lower_bb) or (high < tenkan_upper_bb and high > tenkan_lower_bb) or (low < tenkan_upper_bb and low > tenkan_lower_bb) or (close < tenkan_upper_bb and close > tenkan_lower_bb)price_near_kijun = (open < kijun_upper_bb and open > kijun_lower_bb) or (high < kijun_upper_bb and high > kijun_lower_bb) or (low < kijun_upper_bb and low > kijun_lower_bb) or (close < kijun_upper_bb and close > kijun_lower_bb)price_near_tenkan_kijun = price_near_tenkan or price_near_kijuncloud_thickness_future = math.abs(SenkouA[0] - SenkouB[0])percent_thick_cloud_future = green_kumo_cloud_future ? (cloud_thickness_future * 100) / SenkouA[0] : (red_kumo_cloud_future ? (cloud_thickness_future * 100) / SenkouB[0] : na)thickness_threshold_future = 0.20thin_cloud = percent_thick_cloud_future <= thickness_threshold_futurered_2_green_cloud = (SenkouA[displacement+1] > SenkouB[displacement+1]) and (SenkouA[displacement+0] < SenkouB[displacement+0])green_2_red_cloud = (SenkouA[displacement+1] < SenkouB[displacement+1]) and (SenkouA[displacement+0] > SenkouB[displacement+0])close_above_cloud = close > SenkouA[displacement] and close > SenkouB[displacement]close_below_kijun = close < Kijuntenkan_crossover_kijun = ta.crossover(Tenkan, Kijun)tenkan_over_cloud = Tenkan > SenkouA[displacement] and Tenkan > SenkouB[displacement]tenkan_over_red_cloud = red_kumo_cloud and tenkan_over_cloudkijun_crosses_red_cloud = red_kumo_cloud and ta.crossover(Kijun, SenkouA[displacement])// --- (End) Ichimoku conditions -------------------------------------------- //// --- (Start) Directional Movement Index (DMI) ----------------------------- //dmi_adxSmoothing = input.int(14, title="ADX Smoothing", minval=1, maxval=50, group='ADX / DMI - Setting')dmi_len = input.int(7, minval=1, title="DI Length", group='ADX / DMI - Setting')dmi_up = ta.change(high)dmi_down = -ta.change(low)dmi_plusDM = na(dmi_up) ? na : (dmi_up > dmi_down and dmi_up > 0 ? dmi_up : 0)dmi_minusDM = na(dmi_down) ? na : (dmi_down > dmi_up and dmi_down > 0 ? dmi_down : 0)dmi_rma = ta.rma(ta.tr, dmi_len)dmi_plus = fixnan(100 * ta.rma(dmi_plusDM, dmi_len) / dmi_rma)dmi_minus = fixnan(100 * ta.rma(dmi_minusDM, dmi_len) / dmi_rma)dmi_sum = dmi_plus + dmi_minusdmi_adx = 100 * ta.rma(math.abs(dmi_plus - dmi_minus) / (dmi_sum == 0 ? 1 : dmi_sum), dmi_adxSmoothing)plot(dmi_adx, color=#F50057, title="ADX", display=display.none)plot(dmi_plus, color=#2962FF, title="+DI", display=display.none)plot(dmi_minus, color=#FF6D00, title="-DI", display=display.none)dmi_consld_limit=input.int(defval=25, title='Consolidation ADX', group='ADX / DMI - Setting')dmi_consld=dmi_adx<=dmi_consld_limitdmi_strong_up=dmi_adx>dmi_consld_limit and dmi_plus>dmi_minusdmi_strong_down=dmi_adx>dmi_consld_limit and dmi_plus<dmi_minusbarcolor(dmi_consld ? color.new(color.black,0) : na, title='Consolidation region', display=display.none)barcolor(dmi_strong_up ? color.new(color.green,0) : na, title='Uptrend Region')barcolor(dmi_strong_down ? color.new(color.red,0) : na, title='Downtrend Region')dmi_long_e = (not dmi_strong_up[1] and dmi_strong_up[0])dmi_long_x = (dmi_strong_up[1] and not dmi_strong_up[0]) or (thick_cloud and green_kumo_cloud)dmi_short_e = (not dmi_strong_down[1]) and dmi_strong_down[0]dmi_short_x = (dmi_strong_down[1] and not dmi_strong_down[0]) or green_kumo_cloud// --- (End) Directional Movement Index (DMI) ------------------------------- //// --- Trade Conditions ----------------------------------------------------- //var is_long_open=false, var is_short_open=falselong_e = strategy_type == "DMI" ? dmi_long_e : nalong_x = strategy_type == "DMI" ? dmi_long_x : nashort_e = strategy_type == "DMI" ? dmi_short_e : nashort_x = strategy_type == "DMI" ? dmi_short_x : nalong_e_color = input.color(defval=color.new(color.teal,0), title='Long Entry', group='Signals Style - Setting', inline='il1')long_x_color = input.color(defval=color.new(color.purple,0), title='Long Exit', group='Signals Style - Setting', inline='il1')is_trade_bar = (long_e and not is_long_open) or (long_x and is_long_open)barcolor(color=is_trade_bar ? na : (close>open ? color.new(color.green,90) : color.new(color.red,90)), title='Trade Bars')barcolor(color=(trade_type == 'Long' or trade_type == 'Long/Short') ? long_e and not is_long_open ? long_e_color : na : na, title="Long - Entry Bar", editable=false)barcolor(color=(trade_type == 'Long' or trade_type == 'Long/Short') ? long_x and is_long_open ? long_x_color : na : na, title="Long - Exit Bar", editable=false)plotshape((trade_type == 'Long' or trade_type == 'Long/Short') ? long_e and not is_long_open : na, text="B", textcolor=color.white, style=shape.labelup, color=long_e_color, size=size.tiny, location=location.belowbar, title="Long - Entry Labels")plotshape((trade_type == 'Long' or trade_type == 'Long/Short') ? long_x and is_long_open : na, text="S", textcolor=color.white, style=shape.labeldown, color=long_x_color, size=size.tiny, location=location.abovebar, title="Long - Exit Labels")plotshape((trade_type == 'Short' or trade_type == 'Long/Short') ? short_e and not is_short_open : na, text="E", textcolor=color.black, style=shape.labeldown, color=color.new(color.yellow,30), size=size.tiny, location=location.abovebar, title="Short - Entry Labels", editable=false)plotshape((trade_type == 'Short' or trade_type == 'Long/Short') ? short_x and is_short_open : na, text="X", textcolor=color.black, style=shape.labeldown, color=color.new(color.orange,30), size=size.tiny, location=location.abovebar, title="Short - Exit Labels", editable=false)if long_e and not is_long_open    is_long_open:=trueif long_x and is_long_open    is_long_open:=falseif short_e and not is_short_open    is_short_open:=trueif short_x and is_short_open    is_short_open:=false// --- Trade Executions ----------------------------------------------------- //if trade_type == "Long/Short" and _check    strategy.entry("Long", strategy.long, comment=" ", when=long_e and _testperiod)    strategy.close("Long", comment=" ", when=long_x and _testperiod)    strategy.entry("Short", strategy.short, comment=" ", when=short_e and _testperiod)    strategy.close("Short", comment=" ", when=short_x and _testperiod)if trade_type == "Long" and _check    strategy.entry("Long", strategy.long, comment=" ", when=long_e and _testperiod)    strategy.close("Long", comment=" ", when=long_x and _testperiod)