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
- 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Trading Settings | |||
| Position Type | Long/Short | string · 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 Date | timestamp("2017-01-01T00:00:00") | time | _testperiod |
| Testing End Date | timestamp("2025-01-01T00:00:00") | time | _testperiod |
| Ichimoku Kinko Hyo - Settings | |||
| Conversion Periods (no label in the script) | 9 | int · min 1 | Tenkan |
| Base Periods (no label in the script) | 26 | int · min 1 | Kijun SenkouB |
| Lagging Span2Periods (no label in the script) | 52 | int · min 1 | SenkouA |
| Displacement (no label in the script) | 26 | int · min 1 | SenkouB 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 Smoothing | 14 | int · min 1 · max 50 | dmi_adx |
| DI Length | 7 | int · min 1 | dmi_rma dmi_plus dmi_minus |
| Consolidation ADX | 25 | int | dmi_consld dmi_strong_up dmi_strong_down |
| Signals Style - Setting | |||
| Long Entry | color.new(color.teal,0) | color | Long - Entry Bar Long - Entry Labels |
| Long Exit | color.new(color.purple,0) | color | Long - Exit Bar Long - Exit Labels |
What it calculates
- LowestLength
lower · line 14 - HighestLength
upper · line 14 - BBseries = close, length = 20, mult = 1
close_middle_bb · line 40 - BBseries = close, length = 20, mult = 1
close_upper_bb · line 40 - BBseries = close, length = 20, mult = 1
close_lower_bb · line 40 - Highestpercent_thick_cloud, 10000
thickest_cloud · line 52 - CrossoverTenkan, Kijun
tenkan_crossover_kijun · line 69 - Changehigh
dmi_up · line 77 - Changelow
dmi_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
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | long_e and _testperiod | On | 127 |
| Close Long | long_x and _testperiod | On | 128 |
| Open Short short | short_e and _testperiod | On | 129 |
| Close Short | short_x and _testperiod | On | 130 |
| Open Long long | long_e and _testperiod | On | 132 |
| Close Long | long_x and _testperiod | On | 133 |
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 | +49.7% | +102.5% | 35 | 46% | 1.66 | 19.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +82.0% | +9.8% | 27 | 52% | 1.93 | 23.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +13.4% | +16.7% | 40 | 45% | 1.13 | 34.9% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −25.1% | +148.3% | 35 | 40% | 0.65 | 42.7% | 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 | 16 | 44% | $59.70 |
| Sideways market | 19 | 47% | −$9.99 |
| Falling market | 0 | — | $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.
All 35 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 16 Feb 2024 51,880.00 | 16 Mar 2024 69,499.80 | 29 | $33.70 |
| short | 16 Mar 2024 69,499.80 | 26 Mar 2024 69,880.00 | 10 | −$1.00 |
| long | 26 Mar 2024 69,880.00 | 2 Apr 2024 69,649.80 | 7 | −$0.70 |
| short | 2 Apr 2024 69,649.80 | 7 Apr 2024 68,896.00 | 5 | $1.17 |
| long | 7 Apr 2024 68,896.00 | 12 Apr 2024 70,006.20 | 5 | $1.88 |
| short | 13 Apr 2024 67,116.50 | 14 Apr 2024 63,924.50 | 1 | $6.15 |
| long | 5 May 2024 63,892.00 | 9 May 2024 61,193.00 | 4 | −$6.23 |
| short | 9 May 2024 61,193.00 | 10 May 2024 63,074.00 | 1 | −$4.42 |
| long | 16 May 2024 66,206.50 | 2 Jun 2024 67,766.80 | 17 | $2.81 |
| long | 4 Jun 2024 68,809.90 | 12 Jun 2024 67,314.20 | 8 | −$3.16 |
| short | 12 Jun 2024 67,314.20 | 16 Jun 2024 66,228.30 | 4 | $1.84 |
| long | 15 Jul 2024 60,797.90 | 26 Jul 2024 65,799.90 | 11 | $10.58 |
| short | 26 Jul 2024 65,799.90 | 27 Jul 2024 67,908.00 | 1 | −$4.86 |
| long | 27 Jul 2024 67,908.00 | 2 Aug 2024 65,354.00 | 6 | −$5.45 |
| short | 2 Aug 2024 65,354.00 | 19 Aug 2024 58,427.40 | 17 | $13.77 |
| long | 22 Aug 2024 61,156.00 | 28 Aug 2024 59,415.00 | 6 | −$4.44 |
| short | 28 Aug 2024 59,415.00 | 29 Aug 2024 59,034.90 | 1 | $0.62 |
| long | 14 Sep 2024 60,498.00 | 17 Sep 2024 58,214.00 | 3 | −$5.64 |
| short | 17 Sep 2024 58,214.00 | 18 Sep 2024 60,314.00 | 1 | −$5.21 |
| long | 18 Sep 2024 60,314.00 | 1 Oct 2024 63,327.60 | 13 | $6.30 |
| short | 1 Oct 2024 63,327.60 | 8 Oct 2024 62,224.00 | 7 | $2.13 |
| long | 8 Oct 2024 62,224.00 | 10 Oct 2024 60,636.00 | 2 | −$3.84 |
| short | 10 Oct 2024 60,636.00 | 12 Oct 2024 62,540.00 | 2 | −$4.55 |
| long | 12 Oct 2024 62,540.00 | 14 Oct 2024 62,870.00 | 2 | $0.43 |
| short | 14 Oct 2024 62,870.00 | 15 Oct 2024 66,084.00 | 1 | −$7.01 |
| long | 15 Oct 2024 66,084.00 | 24 Oct 2024 66,668.60 | 9 | $0.85 |
| short | 24 Oct 2024 66,668.60 | 25 Oct 2024 68,198.30 | 1 | −$3.14 |
| long | 25 Oct 2024 68,198.30 | 4 Nov 2024 68,776.00 | 10 | $0.79 |
| short | 4 Nov 2024 68,776.00 | 5 Nov 2024 67,850.00 | 1 | $1.42 |
| long | 6 Nov 2024 69,372.00 | 27 Nov 2024 91,965.10 | 21 | $40.30 |
| short | 27 Nov 2024 91,965.10 | 28 Nov 2024 95,863.10 | 1 | −$7.33 |
| long | 28 Nov 2024 95,863.10 | 4 Dec 2024 95,849.70 | 6 | −$0.34 |
| short | 4 Dec 2024 95,849.70 | 5 Dec 2024 98,587.30 | 1 | −$4.82 |
| long | 5 Dec 2024 98,587.30 | 20 Dec 2024 97,461.90 | 15 | −$2.05 |
| short | 20 Dec 2024 97,461.90 | 21 Dec 2024 97,805.40 | 1 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Directional Movement Index this page | — | v5 strategy | +49.7% | 35 | 19.4% |
| Wilder's Volatility Trailing Stop Strategy with various MA's by SparkyFlary | rma lowest highest | v4 strategy | +16.9% | 15 | 41.6% |
| Simple RSI strategy by RafaelZioni | rma highest lowest | v4 strategy | −11.0% | 119 | 24.4% |
| HiLo Extension by Saravanan_Ragavan | lowest highest rma | v4 strategy | No trades on this market | ||
| Bollinger -B Candles Strategy by Trendoscope | bb lowest highest | v4 strategy | +17.3% | 29 | 5.1% |
| Bollinger Bands Modified (Stormer) by AugustoErni | bb highest lowest | v5 strategy | −7.8% | 29 | 8.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.
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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 60 ms | Yes 1,000 bars in 166 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/// ©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)