Dynamic Trend Fusion (DTF)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TheRealDrip2Rip

//@version=5
indicator("Dynamic Trend Fusion", shorttitle="DTF", overlay=false)

// Define input options
option = input.string("Standard", title="Select Option", options=["Standard","Short-term Trading","Long-term Trading","Aggressive Short-term","Conservative Long-term","Balanced Approach","High Sensitivity","Low Sensitivity","Day Trading","Swing Trading"])

// Initialize variables for MACD and RSI settings
var fastLength = 12
var slowLength = 26
var signalSmoothing = 9
var rsiLength = 14

// Update variables based on the selected option
if option == "Short-term Trading"
    fastLength := 8
    slowLength := 17
    signalSmoothing := 9
    rsiLength := 8
else if option == "Long-term Trading"
    fastLength := 19
    slowLength := 39
    signalSmoothing := 9
    rsiLength := 21
else if option == "Aggressive Short-term"
    fastLength := 5
    slowLength := 13
    signalSmoothing := 8
    rsiLength := 5
else if option == "Conservative Long-term"
    fastLength := 24
    slowLength := 52
    signalSmoothing := 18
    rsiLength := 28
else if option == "Balanced Approach"
    fastLength := 10
    slowLength := 22
    signalSmoothing := 7
    rsiLength := 12
else if option == "High Sensitivity"
    fastLength := 4
    slowLength := 8
    signalSmoothing := 5
    rsiLength := 3
else if option == "Low Sensitivity"
    fastLength := 30
    slowLength := 60
    signalSmoothing := 12
    rsiLength := 50
else if option == "Day Trading"
    fastLength := 6
    slowLength := 19
    signalSmoothing := 9
    rsiLength := 6
else if option == "Swing Trading"
    fastLength := 12
    slowLength := 26
    signalSmoothing := 12
    rsiLength := 14

// MACD
[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalSmoothing)
macdHist = macdLine - signalLine

// RSI
rsi = ta.rsi(close, rsiLength)

// Normalizing MACD and RSI to a similar scale
normMacd = (macdHist - ta.lowest(macdHist, 100)) / (ta.highest(macdHist, 100) - ta.lowest(macdHist, 100))
normRsi = (rsi - 30) / 40 // RSI typically moves between 30 and 70

// Combining normalized values
comboValue = (normMacd + normRsi) / 2

// Smoothing the combined value with a moving average
smoothingLength = input(10, title="Smoothing Length")
smoothedComboValue = ta.sma(comboValue, smoothingLength)

// Determine whether the indicator is bullish or bearish
isBullish = smoothedComboValue > 0.5
isBearish = smoothedComboValue < 0.5

// Plotting with color based on bullish or bearish state
plot(smoothedComboValue, title="Custom RSI-MACD Combo", color=isBullish ? color.rgb(76, 175, 79, 50) : color.rgb(255, 82, 82, 50), linewidth = 2)
hline(0.5, title="Midline", color=color.gray, linestyle=hline.style_dashed)

// Alert conditions
alertcondition(isBullish, title="Bullish Alert", message="DTF is Bullish")
alertcondition(not isBullish, title="Bearish Alert", message="DTF is Bearish")

