like to delve deeper into any of these specific indicators (EMAs, RSI, or Bollinger Bands) or discuss the role of the ATR in this script for stop-loss calculation

in

What they are: EMAs are used to smooth price data, similar to Simple Moving Averages (SMAs), but they give more weight to recent prices. This makes them more responsive to current price changes [Source: Previous conversation].

How they are used in the script:

Inputs: The script allows you to customize the lengths for three EMAs: len_fast (default 5), len_mid (default 10), and len_slow (default 20). The source for these calculations is typically the close price.

Calculations:

    ◦ ema_fast = ta.ema(src, len_fast)

    ◦ ema_mid = ta.ema(src, len_mid)

    ◦ ema_slow = ta.ema(src, len_slow)

Role in Signals:

    ◦ Trend Confirmation: The EMAs are used together to establish a “strong uptrend” or “strong downtrend.”

    ◦ Crossover Triggers: The ema_fast crossing over or under the ema_mid acts as a primary trigger for signals:

        ▪ For a buy_signal, ta.crossover(ema_fast, ema_mid) is required.

        ▪ For a sell_signal, ta.crossunder(ema_fast, ema_mid) is required.

Visuals: The ema_fast, ema_mid, and ema_slow are all plotted on the chart in aqua, yellow, and orange, respectively, to visually represent the trend.

2. Relative Strength Index (RSI)

What it is: The RSI is a momentum oscillator that measures the speed and change of price movements. It oscillates between 0 and 100, typically used to identify overbought or oversold conditions.

How it is used in the script:

Inputs: You can set the len_rsi (RSI Length, default 14), rsi_overbought level (default 70), and rsi_oversold level (default 30).

Calculations: The RSI is calculated using Pine Script’s built-in ta.rsi function: rsi = ta.rsi(src, len_rsi).

Role in Signals: The RSI acts as a filter for both buy and sell signals, aiming to prevent trades from being entered at extreme price points:

3. Bollinger Bands (BB)

What they are: Bollinger Bands are a volatility indicator. They consist of a middle band (a Simple Moving Average) and two outer bands (upper and lower) that are typically two standard deviations away from the middle band. The bands widen or narrow based on market volatility.

How they are used in the script:

Inputs: The script allows you to configure len_bb (BB Length, default 20) and mult_bb (BB Standard Deviation Multiplier, default 2.0).

Calculations:

    ◦ bb_basis = ta.sma(src, len_bb): This is the middle band, a Simple Moving Average of the source price.

    ◦ bb_dev = ta.stdev(src, len_bb) * mult_bb: This calculates the standard deviation of the price over len_bb periods and multiplies it by the mult_bb to determine the distance of the outer bands from the basis.

    ◦ bb_upper = bb_basis + bb_dev: The upper band.

    ◦ bb_lower = bb_basis - bb_dev: The lower band.

Role in Signals: Bollinger Bands are used to confirm volatility and price position relative to the average:

Visuals: The bb_basis, bb_upper, and bb_lower are all plotted on the chart, with the area between the upper and lower bands filled for visual clarity.

What it is: ATR is a measure of market volatility. It indicates how much an asset moves, on average, during a given timeframe. It’s often used in risk management to set stop-loss levels based on an asset’s typical price fluctuations.

How it is used in the script:

Inputs: You can customize the len_atr (ATR Length, default 14) and atr_multiplier (ATR Stop Loss Multiplier, default 2.0).

Calculations:

    ◦ atr = ta.atr(len_atr): The ATR value is calculated using Pine Script’s built-in ta.atr function.

    ◦ stop_loss_level_long = low - atr * atr_multiplier: For a long position (buy), the suggested stop loss is set a certain multiple of ATR below the current bar’s low.

    ◦ stop_loss_level_short = high + atr * atr_multiplier: For a short position (sell), the suggested stop loss is set a certain multiple of ATR above the current bar’s high.

Role in Risk Management: The ATR is not directly involved in generating the buy/sell signals themselves. Instead, it’s used for risk management by dynamically suggesting a stop-loss level once a signal is generated:

    ◦ The sl_price variable tracks the suggested stop-loss level.

    ◦ If a buy_signal occurs, sl_price is set to stop_loss_level_long.

    ◦ If a sell_signal occurs, sl_price is set to stop_loss_level_short.

Visuals: The sl_price is plotted on the chart as a red line, but only when a new signal is generated, making it a dynamic visual aid for managing risk.

This comprehensive strategy combines these indicators to create robust trading signals by considering trend, momentum, and volatility, along with built-in risk management using ATR.


// © Gemini
//@version=5
indicator("Enhanced Trend, Momentum & Volatility Strategy", shorttitle="TMV Enhanced", overlay=true)

// --- SECTION: INDICATOR INPUTS ---
// This section allows you to customize the settings for each indicator in the strategy.

// Exponential Moving Averages (EMAs) for trend direction
ema_group = "Trend Indicators (EMAs)"
len_fast = input.int(5, title="Fast EMA Length", group=ema_group, inline="ema_lens")
len_mid = input.int(10, title="Mid EMA Length", group=ema_group, inline="ema_lens")
len_slow = input.int(20, title="Slow EMA Length", group=ema_group, inline="ema_lens")
src = input(close, "Source", group=ema_group)

// Relative Strength Index (RSI) for momentum
rsi_group = "Momentum Indicator (RSI)"
len_rsi = input.int(14, title="RSI Length", group=rsi_group)

// Bollinger Bands for Volatility
bb_group = "Volatility Indicator (Bollinger Bands)"
len_bb = input.int(20, title="BB Length", group=bb_group)
mult_bb = input.float(2.0, title="BB StdDev Multiplier", group=bb_group, step=0.1)

// Average True Range (ATR) for Stop Loss
atr_group = "Risk Management (ATR)"
len_atr = input.int(14, "ATR Length", group=atr_group)
atr_multiplier = input.float(2.0, "ATR Stop Loss Multiplier", group=atr_group, step=0.5)

// --- SECTION: ENHANCED CONFLUENCE FILTERS ---
// These optional filters can be enabled to make the buy/sell signals more accurate.
filter_group = "Confluence Filters (for Accuracy)"
use_strict_trend_filter = input.bool(true, title="Use Stricter Trend Filter (Price > Slow EMA)?", group=filter_group)
use_rsi_filter = input.bool(true, title="Use RSI Momentum Filter (RSI > 50 for Buy)?", group=filter_group)
use_vol_filter = input.bool(true, title="Use Volume Filter (Volume > Avg Volume)?", group=filter_group)
len_vol = input.int(20, title="Volume SMA Length", group=filter_group)


// --- SECTION: CALCULATIONS ---
// Calculate the values for our indicators.

// EMAs
ema_fast = ta.ema(src, len_fast)
ema_mid = ta.ema(src, len_mid)
ema_slow = ta.ema(src, len_slow)

// RSI
rsi = ta.rsi(src, len_rsi)

// Bollinger Bands
bb_basis = ta.sma(src, len_bb)
bb_dev = ta.stdev(src, len_bb) * mult_bb
bb_upper = bb_basis + bb_dev
bb_lower = bb_basis - bb_dev

// ATR
atr = ta.atr(len_atr)

// Average Volume for the filter
avg_vol = ta.sma(volume, len_vol)


// --- SECTION: ENHANCED STRATEGY LOGIC ---
// Define the conditions with stricter confluence for more accurate signals.

// --- Bullish Conditions ---
// 1. Core Trend: EMAs are stacked bullishly (fast > mid > slow).
// 2. Core Trigger: The fast EMA crosses above the mid EMA.
// 3. Filter 1 (Optional): Price is above the slow EMA for stricter trend confirmation.
// 4. Filter 2 (Optional): RSI is above 50, confirming bullish momentum is in control.
// 5. Filter 3 (Optional): Volume is above its moving average, confirming market conviction.

is_strong_uptrend = ema_fast > ema_mid and ema_mid > ema_slow
strict_trend_buy_filter = not use_strict_trend_filter or close > ema_slow
rsi_momentum_buy_filter = not use_rsi_filter or rsi > 50
volume_conviction_filter = not use_vol_filter or volume > avg_vol

buy_signal = ta.crossover(ema_fast, ema_mid) and is_strong_uptrend and strict_trend_buy_filter and rsi_momentum_buy_filter and volume_conviction_filter

// --- Bearish Conditions ---
// 1. Core Trend: EMAs are stacked bearishly (fast < mid < slow).
// 2. Core Trigger: The fast EMA crosses below the mid EMA.
// 3. Filter 1 (Optional): Price is below the slow EMA for stricter trend confirmation.
// 4. Filter 2 (Optional): RSI is below 50, confirming bearish momentum is in control.
// 5. Filter 3 (Optional): Volume is above its moving average, confirming market conviction.

is_strong_downtrend = ema_fast < ema_mid and ema_mid < ema_slow
strict_trend_sell_filter = not use_strict_trend_filter or close < ema_slow
rsi_momentum_sell_filter = not use_rsi_filter or rsi < 50
// Note: High volume confirms conviction for both bullish and bearish moves.

sell_signal = ta.crossunder(ema_fast, ema_mid) and is_strong_downtrend and strict_trend_sell_filter and rsi_momentum_sell_filter and volume_conviction_filter


// --- SECTION: PLOTTING & VISUALS ---
// Plot the indicators and the buy/sell signals on the chart.

// Plot Bollinger Bands
plot(bb_basis, "BB Basis", color=color.new(color.gray, 50))
p_upper = plot(bb_upper, "BB Upper", color=color.new(color.gray, 80))
p_lower = plot(bb_lower, "BB Lower", color=color.new(color.gray, 80))
fill(p_upper, p_lower, color=color.new(color.gray, 95), title="BB Fill")

// Plot EMAs
plot(ema_fast, "Fast EMA", color=color.new(color.aqua, 0), linewidth=2)
plot(ema_mid, "Mid EMA", color=color.new(color.yellow, 0), linewidth=2)
plot(ema_slow, "Slow EMA", color=color.new(color.orange, 0), linewidth=2)

// Plot Buy Signals on the chart
plotshape(buy_signal, "Buy Signal", style=shape.labelup, location=location.belowbar, color=color.new(color.green, 20), text="BUY", textcolor=color.white, size=size.small)

// Plot Sell Signals on the chart
plotshape(sell_signal, "Sell Signal", style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 20), text="SELL", textcolor=color.white, size=size.small)

// Calculate and plot the suggested Stop Loss level
stop_loss_level_long = low - atr * atr_multiplier
stop_loss_level_short = high + atr * atr_multiplier

var float sl_price = na
if (buy_signal)
    sl_price := stop_loss_level_long
if (sell_signal)
    sl_price := stop_loss_level_short
    
plot(sl_price, "Suggested Stop Loss", color=color.new(color.red, 0), style=plot.style_linebr, linewidth=2)

// Alert Conditions
alertcondition(buy_signal, title="TMV Buy Signal", message="Potential Buy Signal on {{ticker}}")
alertcondition(sell_signal, title="TMV Sell Signal", message="Potential Sell Signal on {{ticker}}")

// © Gemini add volume version
//@version=5
indicator("Enhanced Trend, Momentum & Volatility Strategy", shorttitle="TMV Enhanced", overlay=true)

// --- SECTION: INDICATOR INPUTS ---
// This section allows you to customize the settings for each indicator in the strategy.

// Exponential Moving Averages (EMAs) for trend direction
ema_group = "Trend Indicators (EMAs)"
len_fast = input.int(5, title="Fast EMA Length", group=ema_group, inline="ema_lens")
len_mid = input.int(10, title="Mid EMA Length", group=ema_group, inline="ema_lens")
len_slow = input.int(20, title="Slow EMA Length", group=ema_group, inline="ema_lens")
src = input(close, "Source", group=ema_group)

// Relative Strength Index (RSI) for momentum
rsi_group = "Momentum Indicator (RSI)"
len_rsi = input.int(14, title="RSI Length", group=rsi_group)

// Bollinger Bands for Volatility
bb_group = "Volatility Indicator (Bollinger Bands)"
len_bb = input.int(20, title="BB Length", group=bb_group)
mult_bb = input.float(2.0, title="BB StdDev Multiplier", group=bb_group, step=0.1)

// Average True Range (ATR) for Stop Loss
atr_group = "Risk Management (ATR)"
len_atr = input.int(14, "ATR Length", group=atr_group)
atr_multiplier = input.float(2.0, "ATR Stop Loss Multiplier", group=atr_group, step=0.5)

// --- SECTION: ENHANCED CONFLUENCE FILTERS ---
// These optional filters can be enabled to make the buy/sell signals more accurate.
filter_group = "Confluence Filters (for Accuracy)"
use_strict_trend_filter = input.bool(true, title="Use Stricter Trend Filter (Price > Slow EMA)?", group=filter_group)
use_rsi_filter = input.bool(true, title="Use RSI Momentum Filter (RSI > 50 for Buy)?", group=filter_group)
use_vol_filter = input.bool(true, title="Use Basic Volume Filter (Volume > Avg Volume)?", group=filter_group)
len_vol = input.int(20, title="Volume SMA Length", group=filter_group)

// --- SECTION: ADVANCED VOLUME FILTERS ---
adv_vol_group = "Advanced Volume Filters"
use_obv_filter = input.bool(true, "Use On-Balance Volume (OBV) Filter?", group=adv_vol_group)
len_obv_ma = input.int(20, "OBV Smoothing MA Length", group=adv_vol_group)
use_vwma_filter = input.bool(true, "Use Volume-Weighted MA (VWMA) Filter?", group=adv_vol_group)
len_vwma = input.int(20, "VWMA Length", group=adv_vol_group)


// --- SECTION: CALCULATIONS ---
// Calculate the values for our indicators.

// EMAs
ema_fast = ta.ema(src, len_fast)
ema_mid = ta.ema(src, len_mid)
ema_slow = ta.ema(src, len_slow)

// RSI
rsi = ta.rsi(src, len_rsi)

// Bollinger Bands
bb_basis = ta.sma(src, len_bb)
bb_dev = ta.stdev(src, len_bb) * mult_bb
bb_upper = bb_basis + bb_dev
bb_lower = bb_basis - bb_dev

// ATR
atr = ta.atr(len_atr)

// Average Volume for the filter
avg_vol = ta.sma(volume, len_vol)

// Advanced Volume Calculations
obv = ta.obv
obv_ma = ta.sma(obv, len_obv_ma)
vwma = ta.vwma(src, len_vwma)


// --- SECTION: ENHANCED STRATEGY LOGIC ---
// Define the conditions with stricter confluence for more accurate signals.

// --- Bullish Conditions ---
// 1. Core Trend: EMAs are stacked bullishly (fast > mid > slow).
// 2. Core Trigger: The fast EMA crosses above the mid EMA.
// 3. Filter 1 (Optional): Price is above the slow EMA for stricter trend confirmation.
// 4. Filter 2 (Optional): RSI is above 50, confirming bullish momentum is in control.
// 5. Filter 3 (Optional): Volume is above its moving average, confirming market conviction.
// 6. Filter 4 (Optional): OBV is trending up, showing accumulation.
// 7. Filter 5 (Optional): Price is above the VWMA, showing strength against the volume-weighted price.

is_strong_uptrend = ema_fast > ema_mid and ema_mid > ema_slow
strict_trend_buy_filter = not use_strict_trend_filter or close > ema_slow
rsi_momentum_buy_filter = not use_rsi_filter or rsi > 50
volume_conviction_filter = not use_vol_filter or volume > avg_vol
obv_buy_filter = not use_obv_filter or obv > obv_ma
vwma_buy_filter = not use_vwma_filter or close > vwma

buy_signal = ta.crossover(ema_fast, ema_mid) and is_strong_uptrend and strict_trend_buy_filter and rsi_momentum_buy_filter and volume_conviction_filter and obv_buy_filter and vwma_buy_filter

// --- Bearish Conditions ---
// 1. Core Trend: EMAs are stacked bearishly (fast < mid < slow).
// 2. Core Trigger: The fast EMA crosses below the mid EMA.
// 3. Filter 1 (Optional): Price is below the slow EMA for stricter trend confirmation.
// 4. Filter 2 (Optional): RSI is below 50, confirming bearish momentum is in control.
// 5. Filter 3 (Optional): Volume is above its moving average, confirming market conviction.
// 6. Filter 4 (Optional): OBV is trending down, showing distribution.
// 7. Filter 5 (Optional): Price is below the VWMA, showing weakness against the volume-weighted price.

is_strong_downtrend = ema_fast < ema_mid and ema_mid < ema_slow
strict_trend_sell_filter = not use_strict_trend_filter or close < ema_slow
rsi_momentum_sell_filter = not use_rsi_filter or rsi < 50
// Note: High volume confirms conviction for both bullish and bearish moves.
obv_sell_filter = not use_obv_filter or obv < obv_ma
vwma_sell_filter = not use_vwma_filter or close < vwma

sell_signal = ta.crossunder(ema_fast, ema_mid) and is_strong_downtrend and strict_trend_sell_filter and rsi_momentum_sell_filter and volume_conviction_filter and obv_sell_filter and vwma_sell_filter


// --- SECTION: PLOTTING & VISUALS ---
// Plot the indicators and the buy/sell signals on the chart.

// Plot Bollinger Bands
plot(bb_basis, "BB Basis", color=color.new(color.gray, 50))
p_upper = plot(bb_upper, "BB Upper", color=color.new(color.gray, 80))
p_lower = plot(bb_lower, "BB Lower", color=color.new(color.gray, 80))
fill(p_upper, p_lower, color=color.new(color.gray, 95), title="BB Fill")

// Plot EMAs
plot(ema_fast, "Fast EMA", color=color.new(color.aqua, 0), linewidth=2)
plot(ema_mid, "Mid EMA", color=color.new(color.yellow, 0), linewidth=2)
plot(ema_slow, "Slow EMA", color=color.new(color.orange, 0), linewidth=2)
plot(vwma, "VWMA", color=color.new(color.purple, 0), linewidth=2)

// Plot Buy Signals on the chart
plotshape(buy_signal, "Buy Signal", style=shape.labelup, location=location.belowbar, color=color.new(color.green, 20), text="BUY", textcolor=color.white, size=size.small)

// Plot Sell Signals on the chart
plotshape(sell_signal, "Sell Signal", style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 20), text="SELL", textcolor=color.white, size=size.small)

// Calculate and plot the suggested Stop Loss level
stop_loss_level_long = low - atr * atr_multiplier
stop_loss_level_short = high + atr * atr_multiplier

var float sl_price = na
if (buy_signal)
    sl_price := stop_loss_level_long
if (sell_signal)
    sl_price := stop_loss_level_short
    
plot(sl_price, "Suggested Stop Loss", color=color.new(color.red, 0), style=plot.style_linebr, linewidth=2)

// Alert Conditions
alertcondition(buy_signal, title="TMV Buy Signal", message="Potential Buy Signal on {{ticker}}")
alertcondition(sell_signal, title="TMV Sell Signal", message="Potential Sell Signal on {{ticker}}")


// © Gemini final version with price showing
//@version=5
indicator("Enhanced Trend, Momentum & Volatility Strategy", shorttitle="TMV Enhanced", overlay=true)

// --- SECTION: INDICATOR INPUTS ---
// This section allows you to customize the settings for each indicator in the strategy.

// Exponential Moving Averages (EMAs) for trend direction
ema_group = "Trend Indicators (EMAs)"
len_fast = input.int(5, title="Fast EMA Length", group=ema_group, inline="ema_lens")
len_mid = input.int(10, title="Mid EMA Length", group=ema_group, inline="ema_lens")
len_slow = input.int(20, title="Slow EMA Length", group=ema_group, inline="ema_lens")
src = input(close, "Source", group=ema_group)

// Relative Strength Index (RSI) for momentum
rsi_group = "Momentum Indicator (RSI)"
len_rsi = input.int(14, title="RSI Length", group=rsi_group)

// Bollinger Bands for Volatility
bb_group = "Volatility Indicator (Bollinger Bands)"
len_bb = input.int(20, title="BB Length", group=bb_group)
mult_bb = input.float(2.0, title="BB StdDev Multiplier", group=bb_group, step=0.1)

// Average True Range (ATR) for Stop Loss
atr_group = "Risk Management (ATR)"
len_atr = input.int(14, "ATR Length", group=atr_group)
atr_multiplier = input.float(2.0, title="ATR Stop Loss Multiplier", group=atr_group, step=0.5)

// --- SECTION: ENHANCED CONFLUENCE FILTERS ---
// These optional filters can be enabled to make the buy/sell signals more accurate.
filter_group = "Confluence Filters (for Accuracy)"
use_strict_trend_filter = input.bool(true, title="Use Stricter Trend Filter (Price > Slow EMA)?", group=filter_group)
use_rsi_filter = input.bool(true, title="Use RSI Momentum Filter (RSI > 50 for Buy)?", group=filter_group)
use_vol_filter = input.bool(true, title="Use Basic Volume Filter (Volume > Avg Volume)?", group=filter_group)
len_vol = input.int(20, title="Volume SMA Length", group=filter_group)

// --- SECTION: ADVANCED VOLUME FILTERS ---
adv_vol_group = "Advanced Volume Filters"
use_obv_filter = input.bool(true, "Use On-Balance Volume (OBV) Filter?", group=adv_vol_group)
len_obv_ma = input.int(20, "OBV Smoothing MA Length", group=adv_vol_group)
use_vwma_filter = input.bool(true, "Use Volume-Weighted MA (VWMA) Filter?", group=adv_vol_group)
len_vwma = input.int(20, "VWMA Length", group=adv_vol_group)


// --- SECTION: CALCULATIONS ---
// Calculate the values for our indicators.

// EMAs
ema_fast = ta.ema(src, len_fast)
ema_mid = ta.ema(src, len_mid)
ema_slow = ta.ema(src, len_slow)

// RSI
rsi = ta.rsi(src, len_rsi)

// Bollinger Bands
bb_basis = ta.sma(src, len_bb)
bb_dev = ta.stdev(src, len_bb) * mult_bb
bb_upper = bb_basis + bb_dev
bb_lower = bb_basis - bb_dev

// ATR
atr = ta.atr(len_atr)

// Average Volume for the filter
avg_vol = ta.sma(volume, len_vol)

// Advanced Volume Calculations
obv = ta.obv
obv_ma = ta.sma(obv, len_obv_ma)
vwma = ta.vwma(src, len_vwma)


// --- SECTION: ENHANCED STRATEGY LOGIC ---
// Define the conditions with stricter confluence for more accurate signals.

// --- Bullish Conditions ---
// 1. Core Trend: EMAs are stacked bullishly (fast > mid > slow).
// 2. Core Trigger: The fast EMA crosses above the mid EMA.
// 3. Filter 1 (Optional): Price is above the slow EMA for stricter trend confirmation.
// 4. Filter 2 (Optional): RSI is above 50, confirming bullish momentum is in control.
// 5. Filter 3 (Optional): Volume is above its moving average, confirming market conviction.
// 6. Filter 4 (Optional): OBV is trending up, showing accumulation.
// 7. Filter 5 (Optional): Price is above the VWMA, showing strength against the volume-weighted price.

is_strong_uptrend = ema_fast > ema_mid and ema_mid > ema_slow
strict_trend_buy_filter = not use_strict_trend_filter or close > ema_slow
rsi_momentum_buy_filter = not use_rsi_filter or rsi > 50
volume_conviction_filter = not use_vol_filter or volume > avg_vol
obv_buy_filter = not use_obv_filter or obv > obv_ma
vwma_buy_filter = not use_vwma_filter or close > vwma

buy_signal = ta.crossover(ema_fast, ema_mid) and is_strong_uptrend and strict_trend_buy_filter and rsi_momentum_buy_filter and volume_conviction_filter and obv_buy_filter and vwma_buy_filter

// --- Bearish Conditions ---
// 1. Core Trend: EMAs are stacked bearishly (fast < mid < slow).
// 2. Core Trigger: The fast EMA crosses below the mid EMA.
// 3. Filter 1 (Optional): Price is below the slow EMA for stricter trend confirmation.
// 4. Filter 2 (Optional): RSI is below 50, confirming bearish momentum is in control.
// 5. Filter 3 (Optional): Volume is above its moving average, confirming market conviction.
// 6. Filter 4 (Optional): OBV is trending down, showing distribution.
// 7. Filter 5 (Optional): Price is below the VWMA, showing weakness against the volume-weighted price.

is_strong_downtrend = ema_fast < ema_mid and ema_mid < ema_slow
strict_trend_sell_filter = not use_strict_trend_filter or close < ema_slow
rsi_momentum_sell_filter = not use_rsi_filter or rsi < 50
// Note: High volume confirms conviction for both bullish and bearish moves.
obv_sell_filter = not use_obv_filter or obv < obv_ma
vwma_sell_filter = not use_vwma_filter or close < vwma

sell_signal = ta.crossunder(ema_fast, ema_mid) and is_strong_downtrend and strict_trend_sell_filter and rsi_momentum_sell_filter and volume_conviction_filter and obv_sell_filter and vwma_sell_filter


// --- SECTION: PLOTTING & VISUALS ---
// Plot the indicators and the buy/sell signals on the chart.

// Plot Bollinger Bands
plot(bb_basis, "BB Basis", color=color.new(color.gray, 50))
p_upper = plot(bb_upper, "BB Upper", color=color.new(color.gray, 80))
p_lower = plot(bb_lower, "BB Lower", color=color.new(color.gray, 80))
fill(p_upper, p_lower, color=color.new(color.gray, 95), title="BB Fill")

// Plot EMAs
plot(ema_fast, "Fast EMA", color=color.new(color.aqua, 0), linewidth=2)
plot(ema_mid, "Mid EMA", color=color.new(color.yellow, 0), linewidth=2)
plot(ema_slow, "Slow EMA", color=color.new(color.orange, 0), linewidth=2)
plot(vwma, "VWMA", color=color.new(color.purple, 0), linewidth=2)

// Plot Buy Signals on the chart
if buy_signal
    buy_label_text = "BUY\n" + str.tostring(close, format.mintick)
    label.new(bar_index, low, text=buy_label_text, color=color.new(color.green, 20), textcolor=color.white, style=label.style_label_up, yloc=yloc.belowbar, size=size.small)

// Plot Sell Signals on the chart
if sell_signal
    sell_label_text = "SELL\n" + str.tostring(close, format.mintick)
    label.new(bar_index, high, text=sell_label_text, color=color.new(color.red, 20), textcolor=color.white, style=label.style_label_down, yloc=yloc.abovebar, size=size.small)

// Calculate and plot the suggested Stop Loss level
stop_loss_level_long = low - atr * atr_multiplier
stop_loss_level_short = high + atr * atr_multiplier

var float sl_price = na
if (buy_signal)
    sl_price := stop_loss_level_long
if (sell_signal)
    sl_price := stop_loss_level_short
    
plot(sl_price, "Suggested Stop Loss", color=color.new(color.red, 0), style=plot.style_linebr, linewidth=2)

// Alert Conditions
alertcondition(buy_signal, title="TMV Buy Signal", message="Potential Buy Signal on {{ticker}} at {{close}}")
alertcondition(sell_signal, title="TMV Sell Signal", message="Potential Sell Signal on {{ticker}} at {{close}}")

Leave a Reply

Your email address will not be published. Required fields are marked *