Strategy vault / Trend following
Dual DI Crossover Daily Trading Strategy
This strategy generates trading signals based on the crossover of the positive directional indicator (DI+) and negative directional indicator (DI-) calculated from the average true range (ATR). It belongs to the…

Overview
This strategy generates trading signals based on the crossover of the positive directional indicator (DI+) and negative directional indicator (DI-) calculated from the average true range (ATR). It belongs to the trend following strategy that identifies trend reversal points through the crossover of DI+ and DI-. ATR is used to set stop loss and take profit levels.
Strategy Logic
Calculate ATR(14): Compute the average true range over the past 14 days using high, low and close prices.
Compute DI+ and DI-:
DI+ = 100 * RMA(MAX(UP,0),N) / ATNR
DI- = 100 * RMA(MAX(DOWN,0),N) / ATNR
Where UP is the difference between current high and previous close, DOWN is the difference between current low and previous close, N is the parameter period, default to 14, and ATNR is the ATR calculated from step 1.
Determine entry and exit:
When DI+ crosses over DI-, a buy signal is generated.
When DI+ crosses below DI-, a sell signal is generated.
Set stop loss and take profit:
Long stop loss is entry price minus ATR multiplied by the stop loss multiplier
Long take profit is entry price plus ATR multiplied by the take profit multiplier
Short stop loss is entry price plus ATR multiplied by the stop loss multiplier
Short take profit is entry price minus ATR multiplied by the take profit multiplier
Advantage Analysis
Using DI+/DI- crossover to determine trend reversal provides timely signal for new trend direction.
ATR as dynamic stop loss/take profit indicator can set reasonable levels based on market volatility.
The strategy has few parameters and is easy to understand and implement.
Backtest results show this strategy has positive profit factor and outperforms buy & hold.
Risks and Solutions
False signal risk from DI crossover
- Filter signals with moving averages etc. to avoid false breakout.
Stop loss/take profit too close
- Adjust ATR multiplier to accommodate volatility.
Ineffective in range-bound market
- Combine with other indicators to filter signals in consolidation.
Drawdown risk
- Drawdown is acceptable but unavoidable for systematic strategies. Adjust position sizing to control drawdown.
Optimization Suggestions
Add filters like moving average to avoid false signals in range-bound periods.
Implement position sizing like fixed fractional or Martingale to control drawdown and boost profitability.
Optimize ATR parameters to match volatility of different trading instruments.
Parameter optimization on DI period, ATR period, ATR multiplier etc. to find optimum combination.
Add overnight and early session logic to run strategy 24/7.
Conclusion
This is a simple and practical strategy generating signals from DI crossover and setting dynamic stop loss/take profit with ATR. With few parameters, it is easy to test and optimize. But DI crossover is less effective during consolidation. Going forward, combining additional filters is the main improvement area. Overall this strategy demonstrates stable performance suitable for short-term day trading.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | true | ATR Multiplier |
| v_input_2 | 14 | Length di |
Source Pine Script
/*backtest
start: 2022-11-06 00:00:00
end: 2023-11-12 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TheHulkTrading
//@version=4
strategy("DI Crossing Daily Straregy HulkTrading", overlay=true)
// ATR Multiplier. Recommended values between 1..4
atr_multiplier = input(1, minval=1, title="ATR Multiplier")
//Length of DI. Recommended default value = 14
length = input(14, minval=1, title="Length di")
up = change(high)
down = -change(low)
range = rma(tr, 14)
//DI+ and DI- Calculations
di_plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, length) / range)
di_minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, length) / range)
//Long and short conditions
longCond = crossover(di_plus,di_minus)
shortCond = crossunder(di_plus,di_minus)
//Stop levels and take profits
stop_level_long = strategy.position_avg_price - atr_multiplier*atr(14)
take_level_long = strategy.position_avg_price + 2*atr_multiplier*atr(14)
stop_level_short = strategy.position_avg_price + atr_multiplier*atr(14)
take_level_short = strategy.position_avg_price - 2*atr_multiplier*atr(14)
//Entries and exits
strategy.entry("Long", strategy.long, when=longCond)
strategy.exit("Close Long","Long", stop=stop_level_long, limit = take_level_long)
strategy.entry("Short", strategy.short, when=shortCond)
strategy.exit("Close Short","Short", stop=stop_level_short, limit = take_level_short)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-11-13. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Dual-DI-Crossover-Daily-Trading-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- ATR Dynamic Profit Target and Stop Loss StrategyPine Script · Trend following · 1d
- ATR Dynamic Trend Following and EMA Crossover Trading StrategyPine Script · Trend following · 1d
- ATR and Moving Average Crossover Hybrid StrategyPine Script · Trend following · 1h
- ATR and T3 Moving Average StrategyPine Script · Trend following · 5m
- Adaptive ATR and RSI Trend Following Strategy with Trailing Stop LossPine Script · Trend following · 1h
- Adaptive Risk Management Strategy Based on Dynamic ATR and Moving Average CrossoverPine Script · Trend following · 2h