ATR + Momentum Shifts w/Take Profit
// This source code is subject to the terms of the Mozilla Public License 2.0
// © DraftVenture

//@version=5
indicator(title="ATR + Momentum Shifts w/Take Profit", overlay=true, timeframe="", timeframe_gaps=true)

// Inputs
atr_length = input(9, title="ATR Length")
atr_mult = input.float(2, step=0.1, title="ATR Multiplier")
momentum_length = input.int(18, minval=1, title="Momentum Length")
take_profit_above = input(2.0, title="Take Profit Long")
take_profit_below = input(2.0, title="Take Profit Short")
source = input(close, title="Source")

// Calculate ATR
atr_ = atr_mult * ta.atr(atr_length)

// Calculate Momentum
mom = source - source[momentum_length]

// Custom Colors
upperColor = color.new(#ff9393, 25)
lowerColor = color.new(#ff9393, 25)
longArrowColor = color.new(#fffc3f, 0)
shortArrowColor = color.new(#fffc3f, 1)
takeProfitColor = color.new(#a1ffa5, 50)


// Plot ATR Bands
plot(source + atr_, color=upperColor, linewidth=2, style=plot.style_steplinebr, title="Upper Trailing Stop")
plot(source - atr_, color=lowerColor, linewidth=2, style=plot.style_steplinebr, title="Lower Trailing Stop")

// Plot Shift Arrows
plotshape(mom > 0 and ta.crossover(mom, 0), style=shape.triangleup, location=location.belowbar, color=longArrowColor, size=size.small, title="Potential Long Entry")
plotshape(mom < 0 and ta.crossunder(mom, 0), style=shape.triangledown, location=location.abovebar, color=shortArrowColor, size=size.small, title="Potential Short Entry")

// Calculate Take Profit Levels
takeProfitLevelAbove = source + take_profit_above * atr_
takeProfitLevelBelow = source - take_profit_below * atr_

// Plot Take Profit Levels
plot(takeProfitLevelAbove, title="Take Profit Long", color=takeProfitColor, linewidth=2, style=plot.style_steplinebr)
plot(takeProfitLevelBelow, title="Take Profit Short", color=takeProfitColor, linewidth=2, style=plot.style_steplinebr)

// Indicator by KP