make sure my pinescript is viable to give me high profitability for my family wealth and make sure all functionality works (pinescript v5), eg the investment horizon doesnt seem to do anything yet. heres my current code: //@version=5
strategy("Advanced Multi-Timeframe Strategy with Rapid Averages", overlay=true, margin_long=100, margin_short=100, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// User-defined Inputs
risk_tolerance = input.float(title="Risk Tolerance (%)", defval=1.0, minval=0.1, step=0.1)
investment_horizon = input.string(title="Investment Horizon", defval="Medium Term", options=["Short Term", "Medium Term", "Long Term"])
ema_fast_period = input.int(title="Fast EMA Period", defval=9, minval=1)
sma_fast_period = input.int(title="Fast SMA Period", defval=20, minval=1)
ema_slow_period = input.int(title="Slow EMA Period", defval=50, minval=1)
sma_slow_period = input.int(title="Slow SMA Period", defval=200, minval=1)

// Multiple Timeframe Analysis with Rapid Averages
tf1 = "1"
tf5 = "5"
tf15 = "15"

get_tf_ema(src, period, tf) =>
    request.security(syminfo.tickerid, tf, ta.ema(src, period))

ema_fast_avg = (get_tf_ema(close, ema_fast_period, tf1) + get_tf_ema(close, ema_fast_period, tf5) + get_tf_ema(close, ema_fast_period, tf15)) / 3
sma_fast_avg = (request.security(syminfo.tickerid, tf1, ta.sma(close, sma_fast_period)) + request.security(syminfo.tickerid, tf5, ta.sma(close, sma_fast_period)) + request.security(syminfo.tickerid, tf15, ta.sma(close, sma_fast_period))) / 3

// Longer-term Moving Averages for Trend Confirmation
ema_slow = ta.ema(close, ema_slow_period)
sma_slow = ta.sma(close, sma_slow_period)

// Additional Technical Indicators
rsi = ta.rsi(close, 14)
[macd_line, signal_line, _] = ta.macd(close, 12, 26, 9)
[bb_upper, bb_middle, bb_lower] = ta.bb(close, 20, 2)

// Volume-Based Confirmation Indicators
vwap = ta.vwap(close)
obv = ta.obv

// Adaptive Risk Management Techniques
atr = ta.atr(14)
position_size = math.min((strategy.equity * (risk_tolerance / 100)) / atr, strategy.equity)

// Multi-Timeframe Volatility Filter
atr_tf1 = request.security(syminfo.tickerid, tf1, ta.atr(14))
atr_tf5 = request.security(syminfo.tickerid, tf5, ta.atr(14))
atr_tf15 = request.security(syminfo.tickerid, tf15, ta.atr(14))
avg_volatility = (atr_tf1 + atr_tf5 + atr_tf15) / 3.0
high_volatility = avg_volatility > atr

// Visual Signals on the Chart
plot(ema_slow, color=color.blue, title="EMA Slow", linewidth=2)
plot(sma_slow, color=color.orange, title="SMA Slow", linewidth=2)
trend_color = ema_fast_avg > sma_fast_avg ? color.lime : color.red
plot(ema_fast_avg, color=trend_color, title="EMA Fast Average", linewidth=2)
plot(sma_fast_avg, color=trend_color, title="SMA Fast Average", linewidth=2)

rsi_ob_level = 70
rsi_os_level = 30
hline(rsi_ob_level, "Overbought Level", color=color.gray, linestyle=hline.style_dashed)
hline(rsi_os_level, "Oversold Level", color=color.gray, linestyle=hline.style_dashed)
bgcolor(rsi > rsi_ob_level ? color.new(color.red, 90) : na)
bgcolor(rsi < rsi_os_level ? color.new(color.green, 90) : na)

// Entry and Exit Signals
buy_condition = ema_fast_avg > sma_fast_avg and ema_slow > sma_slow and rsi < rsi_ob_level and macd_line > signal_line and obv > obv[1]
sell_condition = ema_fast_avg < sma_fast_avg or ema_slow < sma_slow or rsi > rsi_ob_level or macd_line < signal_line or obv < obv[1]

if buy_condition and strategy.position_size == 0
    strategy.entry("Long Entry", strategy.long, qty=position_size)

if sell_condition and strategy.position_size > 0
    strategy.close("Long Entry")

// Smart Trailing Stop-Loss Mechanism
var float trail_stop_price = na

if strategy.position_size > 0
    trail_stop_price := ema_fast_avg < sma_fast_avg ? math.max(trail_stop_price, close - atr * 1.5) : math.max(trail_stop_price, close - atr * 1.5)
    if close < trail_stop_price
        strategy.close("Long Entry")
        trail_stop_price := na

plot(trail_stop_price, title="Trailing Stop", color=color.purple, style=plot.style_linebr)

// Comprehensive Performance Metrics
risk_free_rate = 0.01 / 252
daily_return = (strategy.equity - strategy.equity[1]) / strategy.equity[1]
mean_daily_return = ta.sma(daily_return, 14)
std_dev_returns = ta.stdev(daily_return, 14)
sharpe_ratio = std_dev_returns != 0 ? (mean_daily_return - risk_free_rate) / std_dev_returns * math.sqrt(252) : na
negative_returns = daily_return < 0 ? daily_return : 0
downside_dev = ta.stdev(negative_returns, 14)
sortino_ratio = downside_dev != 0 ? (mean_daily_return - risk_free_rate) / downside_dev * math.sqrt(252) : na

var label sharpe_label = label.new(bar_index, na, text="")
label.set_x(sharpe_label, bar_index)
label.set_y(sharpe_label, high)
label.set_text(sharpe_label, "Sharpe Ratio: " + str.tostring(sharpe_ratio, "#.##") + "\nSortino Ratio: " + str.tostring(sortino_ratio, "#.##"))
label.set_style(sharpe_label, label.style_label_down)

// Multi-level Alerts
if ta.crossover(ema_fast_avg, sma_fast_avg)
    alert("Bullish Crossover: EMA Fast Average crossed above SMA Fast Average", alert.freq_once_per_bar_close)

if ta.crossunder(ema_fast_avg, sma_fast_avg)
    alert("Bearish Crossover: EMA Fast Average crossed below SMA Fast Average", alert.freq_once_per_bar_close)

resistance = ta.highest(high, 50)
support = ta.lowest(low, 50)
if close > resistance
    alert("Breakout Up: Price broke above resistance level", alert.freq_once_per_bar_close)
if close < support
    alert("Breakout Down: Price broke below support level", alert.freq_once_per_bar_close)

price_higher_high = high > high[1]
rsi_lower_high = rsi < rsi[1]
price_lower_low = low < low[1]
rsi_higher_low = rsi > rsi[1]

if price_higher_high and rsi_lower_high
    alert("Bearish Divergence: Bearish divergence detected between price and RSI", alert.freq_once_per_bar_close)
if price_lower_low and rsi_higher_low
    alert("Bullish Divergence: Bullish divergence detected between price and RSI", alert.freq_once_per_bar_close)