ProTraderKit
Home
Features
Pricing
Get Started
Home
Features
Pricing
Get Started
Average Directional Index (ADX)
Average Directional Index (ADX) Code
Copy Code
//@version=5 strategy("ADX Strategy", overlay=true) // Input parameters adx_length = input.int(14, title="ADX Length") adx_threshold = input.int(25, title="ADX Threshold") target_points = input.int(100, title="Target Points") stop_loss_points = input.int(50, title="Stop Loss Points") [PDI, NDI, adx] = ta.dmi(adx_length, adx_threshold) // Strategy logic long_condition = adx > adx_threshold and ta.crossover(PDI, NDI) short_condition = adx > adx_threshold and ta.crossunder(PDI, NDI) // Plot ADX plot(adx, color=color.blue, title="ADX") // Strategy entry and exit if long_condition strategy.entry("Long", strategy.long) if short_condition strategy.entry("Short", strategy.short) // Calculate target and stop loss levels long_target = strategy.position_avg_price + target_points long_stop_loss = strategy.position_avg_price - stop_loss_points short_target = strategy.position_avg_price - target_points short_stop_loss = strategy.position_avg_price + stop_loss_points // Strategy exit strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss) strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)