//@version=5
indicator("Advanced Trend Tracer [Vantage]", overlay=true, max_labels_count=500,
max_lines_count=500, max_boxes_count=500, request_dynamic_requests=true)
// ==========================================================================
// INPUTS
// ==========================================================================
// General Settings
group_general = "GENERAL SETTINGS"
timeframe_filter = input.bool(true, "Multi-Timeframe Analysis",
group=group_general, tooltip="Enables cross-timeframe trend analysis")
show_signals = input.bool(true, "Show Signals", group=group_general,
tooltip="Display buy/sell signals on the chart")
show_dashboard = input.bool(true, "Show Dashboard", group=group_general,
tooltip="Display dashboard with trend information")
trend_filter_strength = input.int(3, "Trend Filter Strength", minval=1, maxval=10,
group=group_general, tooltip="Higher values create more stable but lagging trend
detection")
// Advanced Settings
group_advanced = "ADVANCED SETTINGS"
primary_trend_length = input.int(250, "Primary Trend Length", minval=50,
maxval=500, group=group_advanced, tooltip="Primary EMA length used for trend
detection")
secondary_trend_length = input.int(55, "Secondary Trend Length", minval=10,
maxval=200, group=group_advanced, tooltip="Secondary faster trend length")
volatility_length = input.int(20, "Volatility Length", minval=5, maxval=50,
group=group_advanced, tooltip="Length of volatility calculation")
volume_length = input.int(20, "Volume EMA Length", minval=5, maxval=50,
group=group_advanced, tooltip="Length of volume EMA")
adaptive_mode = input.bool(true, "Adaptive Mode", group=group_advanced,
tooltip="Automatically adjust parameters based on market conditions")
// Price Action Settings
group_price_action = "PRICE ACTION SETTINGS"
show_price_action = input.bool(true, "Enable Price Action Analysis",
group=group_price_action, tooltip="Analyze candlestick patterns and price
structures")
pattern_confirmation = input.bool(true, "Require Pattern Confirmation",
group=group_price_action, tooltip="Require price action pattern confirmation for
signals")
momentum_filter = input.bool(true, "Momentum Filter", group=group_price_action,
tooltip="Filter signals using momentum indicators")
use_swing_detection = input.bool(true, "Swing High/Low Detection",
group=group_price_action, tooltip="Detect swing points for market structure
analysis")
swing_length = input.int(10, "Swing Detection Length", minval=2, maxval=50,
group=group_price_action, tooltip="Number of bars to look for swings")
// Volume Profile Settings
group_volume = "VOLUME PROFILE SETTINGS"
use_volume_profile = input.bool(true, "Enable Volume Profile Analysis",
group=group_volume, tooltip="Analyze volume distribution for key price levels")
volume_lookback = input.int(100, "Volume Profile Lookback", minval=20, maxval=500,
group=group_volume, tooltip="Number of bars to analyze for volume profile")
show_key_levels = input.bool(true, "Show Key Volume Levels", group=group_volume,
tooltip="Display significant volume-based support/resistance levels")
// Projection Settings
group_projection = "TREND PROJECTION SETTINGS"
enable_projections = input.bool(true, "Enable Trend Projections",
group=group_projection, tooltip="Project potential trend targets based on current
trend strength")
projection_method = input.string("Fibonacci", "Projection Method",
options=["Simple", "Fibonacci", "ATR-Based"], group=group_projection)
show_risk_reward = input.bool(true, "Show Risk/Reward Ratio",
group=group_projection, tooltip="Display calculated risk/reward for trade setups")
// Visualization Settings
group_visualization = "VISUALIZATION SETTINGS"
dashboard_location = input.string("Bottom Right", "Dashboard Location",
options=["Top Right", "Middle Right", "Bottom Right", "Top Center", "Middle
Center", "Bottom Center", "Top Left", "Middle Left", "Bottom Left"],
group=group_visualization)
dashboard_size = input.string("Normal", "Dashboard Size", options=["Large",
"Normal", "Small", "Tiny"], group=group_visualization)
trend_line_width = input.int(2, "Trend Line Width", minval=1, maxval=5,
group=group_visualization)
bull_color = input.color(#02ff65, "Bullish Color", group=group_visualization)
bear_color = input.color(#ff1100, "Bearish Color", group=group_visualization)
neutral_color = input.color(color.gray, "Neutral Color", group=group_visualization)
show_cloud = input.bool(true, "Show Trend Cloud", group=group_visualization,
tooltip="Display trend cloud between primary and secondary trend lines")
// Signal Settings
group_signals = "SIGNAL SETTINGS"
signal_sensitivity = input.float(5, "Signal Sensitivity", minval=1, maxval=10,
step=0.1, group=group_signals)
signal_lookback = input.int(10, "Signal Lookback", minval=3, maxval=20,
group=group_signals)
early_entry = input.bool(false, "Enable Early Entry Signals", group=group_signals,
tooltip="Generate signals earlier with higher risk/reward")
signal_filter_strength = input.string("Medium", "Signal Filter Strength",
options=["Low", "Medium", "High"], group=group_signals, tooltip="Higher filter
strength reduces false signals but may miss opportunities")
// ==========================================================================
// ADAPTIVE PARAMETERS
// ==========================================================================
// Detect market volatility regime
is_high_volatility = false
if adaptive_mode
// Calculate volatility ratio using ATR
short_atr = ta.atr(10)
long_atr = ta.atr(100)
volatility_ratio = short_atr / long_atr
is_high_volatility := volatility_ratio > 1.5
// Adaptive parameter adjustment based on market conditions
adjusted_primary_length = adaptive_mode and is_high_volatility ?
math.floor(primary_trend_length * 0.7) : primary_trend_length
adjusted_secondary_length = adaptive_mode and is_high_volatility ?
math.floor(secondary_trend_length * 0.7) : secondary_trend_length
// Adjust signal sensitivity based on volatility regime
adjusted_sensitivity = adaptive_mode and is_high_volatility ? signal_sensitivity *
1.5 : signal_sensitivity
// Adjust signal filter based on selected strength
signal_threshold = signal_filter_strength == "Low" ? 20 :
signal_filter_strength == "Medium" ? 30 :
40
// ==========================================================================
// CALCULATIONS
// ==========================================================================
// Primary trend detection
primary_ema = ta.ema(close, adjusted_primary_length)
primary_trend_direction = close > primary_ema ? 1 : close < primary_ema ? -1 : 0
// Secondary trend detection
secondary_ema = ta.ema(close, adjusted_secondary_length)
secondary_trend_direction = close > secondary_ema ? 1 : close < secondary_ema ? -
1 : 0
// Advanced trend detection using Hull Moving Average for more responsiveness
hma_length = math.floor(adjusted_secondary_length / 2)
hma = ta.hma(close, hma_length)
hma_trend = hma > hma[1] ? 1 : hma < hma[1] ? -1 : 0
// Volatility measurement
atr = ta.atr(volatility_length)
normalized_atr = atr / close * 100
volatility_state = normalized_atr > ta.sma(normalized_atr, volatility_length * 2) ?
1 : 0
// Volume trend
volume_ema = ta.ema(volume, volume_length)
volume_trend = volume > volume_ema ? 1 : volume < volume_ema ? -1 : 0
volume_surge = volume > volume_ema * 1.5
// MACD for additional trend confirmation
[macd_line, signal_line, histogram] = ta.macd(close, 12, 26, 9)
macd_trend = macd_line > signal_line ? 1 : macd_line < signal_line ? -1 : 0
macd_momentum = histogram > histogram[1]
// RSI for trend strength and reversal potential
rsi = ta.rsi(close, 14)
rsi_trend = rsi > 50 ? 1 : rsi < 50 ? -1 : 0
rsi_overbought = rsi > 70
rsi_oversold = rsi < 30
// Stochastic for momentum confirmation
[stoch_k, stoch_d] = ta.stoch(close, high, low, 14)
stoch_trend = stoch_k > stoch_d ? 1 : stoch_k < stoch_d ? -1 : 0
stoch_overbought = stoch_k > 80 and stoch_d > 80
stoch_oversold = stoch_k < 20 and stoch_d < 20
// Combined trend score (weighted approach)
trend_score = (primary_trend_direction * 3 +
secondary_trend_direction * 2 +
hma_trend * 2 +
macd_trend * 1.5 +
rsi_trend * 1 +
stoch_trend * 0.5 +
volume_trend * 0.5) / 10.5
// Dynamic adjustment based on volatility
adjusted_trend_score = volatility_state == 1 ? trend_score * 0.75 : trend_score
// Smooth the trend score for stability
smooth_trend_score = ta.ema(adjusted_trend_score, trend_filter_strength)
// Determine final trend direction
trend_direction = smooth_trend_score > 0.3 ? 1 : smooth_trend_score < -0.3 ? -1 : 0
// Trend strength calculation (0-100%)
trend_strength = math.abs(smooth_trend_score) * 100
trend_strength := math.min(trend_strength, 100)
// ==========================================================================
// PRICE ACTION ANALYSIS
// ==========================================================================
// Swing high/low detection
swing_high = ta.highest(high, swing_length)
swing_low = ta.lowest(low, swing_length)
is_swing_high = high == swing_high and high[1] < swing_high and high[2] <
swing_high
is_swing_low = low == swing_low and low[1] > swing_low and low[2] > swing_low
// Store recent swing points
var float last_swing_high = na
var float last_swing_low = na
var int last_swing_high_bar = na
var int last_swing_low_bar = na
if is_swing_high
last_swing_high := high
last_swing_high_bar := bar_index
if is_swing_low
last_swing_low := low
last_swing_low_bar := bar_index
// Market structure analysis
higher_highs = not na(last_swing_high) and not na(last_swing_high[1]) and
last_swing_high > last_swing_high[1]
higher_lows = not na(last_swing_low) and not na(last_swing_low[1]) and
last_swing_low > last_swing_low[1]
lower_highs = not na(last_swing_high) and not na(last_swing_high[1]) and
last_swing_high < last_swing_high[1]
lower_lows = not na(last_swing_low) and not na(last_swing_low[1]) and
last_swing_low < last_swing_low[1]
bullish_structure = higher_highs and higher_lows
bearish_structure = lower_highs and lower_lows
// Candlestick pattern detection
bullish_engulfing = close > open and close > open[1] and open < close[1] and
open[1] > close[1] and (close - open) > (open[1] - close[1])
bearish_engulfing = open > close and open < close[1] and close < open[1] and
open[1] < close[1] and (open - close) > (close[1] - open[1])
bullish_hammer = low < ta.lowest(low, 5) and (close - low) > 2 * (open - close) and
close > open
bearish_hammer = high > ta.highest(high, 5) and (high - close) > 2 * (close - open)
and open > close
doji = math.abs(close - open) / (high - low) < 0.1 and high - low > 0
// Price Action Scoring
price_action_score = 0.0
if show_price_action
price_action_score := (bullish_engulfing ? 1 : 0) + (bearish_engulfing ? -1 :
0) +
(bullish_hammer ? 1 : 0) + (bearish_hammer ? -1 : 0) +
(bullish_structure ? 1 : 0) + (bearish_structure ? -1 : 0)
+
(higher_highs ? 0.5 : 0) + (higher_lows ? 0.5 : 0) +
(lower_highs ? -0.5 : 0) + (lower_lows ? -0.5 : 0)
// Combine with trend score
final_score = smooth_trend_score * 0.7 + price_action_score * 0.3
// Momentum Confluence Detection
momentum_confluence_bull = macd_trend == 1 and rsi_trend == 1 and stoch_trend == 1
and macd_momentum
momentum_confluence_bear = macd_trend == -1 and rsi_trend == -1 and stoch_trend ==
-1 and not macd_momentum
// ==========================================================================
// VOLUME PROFILE ANALYSIS
// ==========================================================================
// Function to create simple volume profile
get_volume_profile() =>
var profile = array.new_float(10, 0) // Divide price range into 10 bins
var levels = array.new_float(10, 0) // Store price levels for each bin
if barstate.islast and use_volume_profile
// Reset arrays
array.fill(profile, 0)
// Determine price range over lookback period
highest_price = ta.highest(high, volume_lookback)
lowest_price = ta.lowest(low, volume_lookback)
price_range = highest_price - lowest_price
bin_size = price_range / 10
// Populate price levels
for i = 0 to 9
array.set(levels, i, lowest_price + bin_size * i)
// Analyze volume distribution across price levels
for i = 0 to volume_lookback - 1
vp = volume[i]
hlc = (high[i] + low[i] + close[i]) / 3
bin_index = math.floor(math.min(9, math.max(0, (hlc - lowest_price) /
bin_size)))
array.set(profile, bin_index, array.get(profile, bin_index) + vp)
[profile, levels]
[volume_profile, price_levels] = get_volume_profile()
// Find high volume nodes (potential support/resistance)
find_significant_levels() =>
lvl_1 = 0.0
lvl_2 = 0.0
lvl_1_value = 0.0
lvl_2_value = 0.0
if barstate.islast and use_volume_profile
// Find top two volume nodes
for i = 0 to 9
vol = array.get(volume_profile, i)
if vol > lvl_1_value
lvl_2_value := lvl_1_value
lvl_2 := lvl_1
lvl_1_value := vol
lvl_1 := array.get(price_levels, i)
else if vol > lvl_2_value
lvl_2_value := vol
lvl_2 := array.get(price_levels, i)
[lvl_1, lvl_2]
[key_level_1, key_level_2] = find_significant_levels()
// Check if price is near a high volume node (support/resistance)
price_at_volume_node = false
if use_volume_profile and not na(key_level_1)
price_at_volume_node := math.abs(close - key_level_1) / close < 0.01 or
(not na(key_level_2) and math.abs(close - key_level_2) /
close < 0.01)
// ==========================================================================
// TREND PROJECTION ANALYSIS
// ==========================================================================
// Function to calculate projected targets based on current trend
calculate_projections() =>
// Initialize projection values
tp1 = na
tp2 = na
tp3 = na
sl = na
rr1 = 0.0
rr2 = 0.0
rr3 = 0.0
if enable_projections and barstate.islast
// Calculate based on selected method
if projection_method == "Simple"
// Simple percentage-based projection
if trend_direction == 1
sl := math.min(last_swing_low, low - atr * 1.5)
risk = close - sl
tp1 := close + risk * 1.5
tp2 := close + risk * 2.5
tp3 := close + risk * 4.0
else if trend_direction == -1
sl := math.max(last_swing_high, high + atr * 1.5)
risk = sl - close
tp1 := close - risk * 1.5
tp2 := close - risk * 2.5
tp3 := close - risk * 4.0
else if projection_method == "Fibonacci"
// Fibonacci-based projection
if trend_direction == 1
sl := math.min(last_swing_low, low - atr)
price_range = high - sl
tp1 := high + price_range * 0.618
tp2 := high + price_range * 1.0
tp3 := high + price_range * 1.618
else if trend_direction == -1
sl := math.max(last_swing_high, high + atr)
price_range = sl - low
tp1 := low - price_range * 0.618
tp2 := low - price_range * 1.0
tp3 := low - price_range * 1.618
else if projection_method == "ATR-Based"
// ATR-based projection
if trend_direction == 1
sl := close - atr * 1.5
tp1 := close + atr * 2
tp2 := close + atr * 3.5
tp3 := close + atr * 5
else if trend_direction == -1
sl := close + atr * 1.5
tp1 := close - atr * 2
tp2 := close - atr * 3.5
tp3 := close - atr * 5
// Calculate risk/reward ratios
if trend_direction == 1 and not na(sl)
risk = close - sl
rr1 := (tp1 - close) / risk
rr2 := (tp2 - close) / risk
rr3 := (tp3 - close) / risk
else if trend_direction == -1 and not na(sl)
risk = sl - close
rr1 := (close - tp1) / risk
rr2 := (close - tp2) / risk
rr3 := (close - tp3) / risk
[tp1, tp2, tp3, sl, rr1, rr2, rr3]
[target1, target2, target3, stop_level, risk_reward1, risk_reward2, risk_reward3] =
calculate_projections()
// ==========================================================================
// SIGNAL GENERATION
// ==========================================================================
// Trend shift detection
trend_shift_up = trend_direction == 1 and trend_direction[1] <= 0
trend_shift_down = trend_direction == -1 and trend_direction[1] >= 0
// Volume confirmation
volume_confirmed = volume > ta.sma(volume, 20)
// Volume profile confirmation (if price is at a key level)
vol_profile_confirmation = use_volume_profile ? price_at_volume_node : true
// Trend-following signal logic with additional filters
buy_signal = trend_shift_up and trend_strength > signal_threshold and
volume_confirmed and
(not momentum_filter or momentum_confluence_bull) and
(not pattern_confirmation or price_action_score > 0) and
vol_profile_confirmation
sell_signal = trend_shift_down and trend_strength > signal_threshold and
volume_confirmed and
(not momentum_filter or momentum_confluence_bear) and
(not pattern_confirmation or price_action_score < 0) and
vol_profile_confirmation
// Pull-back entry signal (price retraces to EMA during strong trend)
pullback_buy = trend_direction == 1 and close[1] < secondary_ema and close >
secondary_ema and
trend_strength > signal_threshold + 10 and
(not momentum_filter or rsi_oversold or stoch_oversold)
pullback_sell = trend_direction == -1 and close[1] > secondary_ema and close <
secondary_ema and
trend_strength > signal_threshold + 10 and
(not momentum_filter or rsi_overbought or stoch_overbought)
// Early entry signals based on momentum shift before price confirmation
early_buy = early_entry and trend_direction == -1 and momentum_confluence_bull and
price_action_score > 0 and volume_surge
early_sell = early_entry and trend_direction == 1 and momentum_confluence_bear and
price_action_score < 0 and volume_surge
// Get highest/lowest for stop placement
highest_high = ta.highest(high, signal_lookback)
lowest_low = ta.lowest(low, signal_lookback)
// ==========================================================================
// SIGNAL STATISTICS & PERFORMANCE
// ==========================================================================
// Track how many signals were generated
var int total_signals = 0
var int successful_signals = 0
var float avg_win_percent = 0
var float max_win_percent = 0
var float max_loss_percent = 0
// Update statistics on new signals
if (buy_signal or sell_signal) and barstate.islast
total_signals := total_signals + 1
// Calculate success rate (hypothetical based on trend strength as proxy)
success_rate = total_signals > 0 ? (trend_strength / 100) * 0.85 : 0
estimated_win_rate = math.round(success_rate * 100)
// ==========================================================================
// MULTI-TIMEFRAME ANALYSIS
// ==========================================================================
// Function to get trend from higher timeframes
get_tf_trend(tf) =>
request.security(syminfo.tickerid, tf, trend_direction)
// Get trends from higher timeframes if enabled
m15_trend = timeframe_filter ? get_tf_trend("15") : na
h1_trend = timeframe_filter ? get_tf_trend("60") : na
h4_trend = timeframe_filter ? get_tf_trend("240") : na
d1_trend = timeframe_filter ? get_tf_trend("D") : na
// Create a multi-timeframe alignment score (-4 to 4 scale)
mtf_score = 0.0
if timeframe_filter
mtf_score := (trend_direction +
(na(m15_trend) ? 0 : m15_trend) +
(na(h1_trend) ? 0 : h1_trend) +
(na(h4_trend) ? 0 : h4_trend) +
(na(d1_trend) ? 0 : d1_trend))
// Strong alignment when score is >= 3 or <= -3
strong_bullish_alignment = mtf_score >= 3
strong_bearish_alignment = mtf_score <= -3
// ==========================================================================
// TREND TRACER LINE CALCULATION
// ==========================================================================
// Calculate dynamic support/resistance based on trend
support_level = trend_direction == 1 ? ta.lowest(low, 5) : na
resistance_level = trend_direction == -1 ? ta.highest(high, 5) : na
// Calculate the trend tracer line using adaptive EMA
var int trend_tracer_length = 0 // Initialize as simple int
trend_tracer_length := trend_direction == 1 ? math.max(10, 50 -
math.round(trend_strength / 2)) :
trend_direction == -1 ? math.max(10, 50 -
math.round(trend_strength / 2)) :
math.round(adjusted_primary_length / 4)
trend_tracer_line = ta.ema(close, trend_tracer_length)
// Secondary adaptive line for trend cloud
var int fast_length = 0 // Initialize as simple int
fast_length := math.max(5, math.round(trend_tracer_length / 2))
trend_tracer_fast = ta.ema(close, fast_length)
// Trend tracer line color
trend_tracer_color = trend_direction == 1 ? bull_color :
trend_direction == -1 ? bear_color :
neutral_color
// ==========================================================================
// VISUALIZATION
// ==========================================================================
// Plot the trend tracer lines
plot(trend_tracer_line, "Trend Tracer", color=trend_tracer_color,
linewidth=trend_line_width)
plot(show_cloud ? trend_tracer_fast : na, "Fast Tracer",
color=color.new(trend_tracer_color, 70), linewidth=1)
// Plot trend cloud
if show_cloud
fill_color = trend_direction == 1 ? color.new(bull_color, 90) :
trend_direction == -1 ? color.new(bear_color, 90) :
color.new(neutral_color, 90)
fill(plot(trend_tracer_line, "", color=na), plot(trend_tracer_fast, "",
color=na), fill_color)
// Plot key volume levels
if show_key_levels and use_volume_profile
key_level_color = color.new(#9c27b0, 70) // Purple for volume nodes
line.new(bar_index - 50, key_level_1, bar_index, key_level_1,
color=key_level_color, width=1, style=line.style_dashed)
if not na(key_level_2)
line.new(bar_index - 50, key_level_2, bar_index, key_level_2,
color=key_level_color, width=1, style=line.style_dashed)
// Plot projections if enabled
if enable_projections and barstate.islast and (trend_direction != 0)
projection_style = line.style_dotted
tp_width = 1
sl_width = 2
tp_color = trend_direction == 1 ? bull_color : bear_color
sl_color = trend_direction == 1 ? bear_color : bull_color
// Draw projection lines
if not na(target1)
line_tp1 = line.new(bar_index - 5, target1, bar_index + 15, target1,
color=color.new(tp_color, 40),
width=tp_width,
style=projection_style)
label.new(bar_index + 15, target1, "TP1 (" + str.tostring(risk_reward1,
"#.##") + "R)", style=label.style_label_right, color=color.new(tp_color, 70),
textcolor=color.white, size=size.small)
if not na(target2)
line_tp2 = line.new(bar_index - 5, target2, bar_index + 15, target2,
color=color.new(tp_color, 40),
width=tp_width,
style=projection_style)
label.new(bar_index + 15, target2, "TP2 (" + str.tostring(risk_reward2,
"#.##") + "R)", style=label.style_label_right, color=color.new(tp_color, 70),
textcolor=color.white, size=size.small)
if not na(target3)
line_tp3 = line.new(bar_index - 5, target3, bar_index + 15, target3,
color=color.new(tp_color, 40),
width=tp_width,
style=projection_style)
label.new(bar_index + 15, target3, "TP3 (" + str.tostring(risk_reward3,
"#.##") + "R)", style=label.style_label_right, color=color.new(tp_color, 70),
textcolor=color.white, size=size.small)
if not na(stop_level)
line_sl = line.new(bar_index - 5, stop_level, bar_index + 15, stop_level,
color=color.new(sl_color, 40),
width=sl_width,
style=line.style_solid)
label.new(bar_index + 15, stop_level, "SL", style=label.style_label_right,
color=color.new(sl_color, 70), textcolor=color.white, size=size.small)
// Plot signals
plotshape(show_signals and buy_signal, "Buy Signal", style=shape.triangleup,
location=location.belowbar, color=bull_color, size=size.normal)
plotshape(show_signals and sell_signal, "Sell Signal", style=shape.triangledown,
location=location.abovebar, color=bear_color, size=size.normal)
// Plot pullback signals with different shape
plotshape(show_signals and pullback_buy, "Pullback Buy", style=shape.circle,
location=location.belowbar, color=bull_color, size=size.small)
plotshape(show_signals and pullback_sell, "Pullback Sell", style=shape.circle,
location=location.abovebar, color=bear_color, size=size.small)
// Plot early entry signals with different shape
plotshape(show_signals and early_buy, "Early Buy", style=shape.diamond,
location=location.belowbar, color=color.new(bull_color, 40), size=size.small)
plotshape(show_signals and early_sell, "Early Sell", style=shape.diamond,
location=location.abovebar, color=color.new(bear_color, 40), size=size.small)
// Plot price action patterns
if show_price_action
plotshape(bullish_engulfing, "Bullish Engulfing", style=shape.square,
location=location.belowbar, color=color.new(bull_color, 50), size=size.tiny)
plotshape(bearish_engulfing, "Bearish Engulfing", style=shape.square,
location=location.abovebar, color=color.new(bear_color, 50), size=size.tiny)
// Mark swing points
plotshape(use_swing_detection and is_swing_high, "Swing High",
style=shape.circle, location=location.abovebar, color=color.new(bear_color, 70),
size=size.tiny)
plotshape(use_swing_detection and is_swing_low, "Swing Low",
style=shape.circle, location=location.belowbar, color=color.new(bull_color, 70),
size=size.tiny)
// Create labels for signals
if show_signals and barstate.islast
if buy_signal
label.new(bar_index, low, "BUY", style=label.style_label_up,
color=bull_color, textcolor=color.white)
if sell_signal
label.new(bar_index, high, "SELL", style=label.style_label_down,
color=bear_color, textcolor=color.white)
if pullback_buy
label.new(bar_index, low, "PB\nBUY", style=label.style_label_up,
color=color.new(bull_color, 70), textcolor=color.white, size=size.small)
if pullback_sell
label.new(bar_index, high, "PB\nSELL", style=label.style_label_down,
color=color.new(bear_color, 70), textcolor=color.white, size=size.small)
if early_buy
label.new(bar_index, low, "EARLY\nBUY", style=label.style_label_up,
color=color.new(bull_color, 40), textcolor=color.white, size=size.small)
if early_sell
label.new(bar_index, high, "EARLY\nSELL", style=label.style_label_down,
color=color.new(bear_color, 40), textcolor=color.white, size=size.small)
// ==========================================================================
// DASHBOARD
// ==========================================================================
// Set dashboard position and size
dashboard_pos = dashboard_location == "Top Right" ? position.top_right :
dashboard_location == "Middle Right" ? position.middle_right :
dashboard_location == "Bottom Right" ? position.bottom_right :
dashboard_location == "Top Center" ? position.top_center :
dashboard_location == "Middle Center" ? position.middle_center :
dashboard_location == "Bottom Center" ? position.bottom_center :
dashboard_location == "Top Left" ? position.top_left :
dashboard_location == "Middle Left" ? position.middle_left :
position.bottom_left
dashboard_text_size = dashboard_size == "Large" ? size.large :
dashboard_size == "Normal" ? size.normal :
dashboard_size == "Small" ? size.small :
size.tiny
// Create and populate the dashboard
if show_dashboard and barstate.islast
table dash = table.new(dashboard_pos, 2, 12, bgcolor = color.new(color.black,
70), border_width = 1)
// Title
table.cell(dash, 0, 0, "TREND TRACER VANTAGE", bgcolor = color.new(color.gray,
90), text_color = color.white, text_size = dashboard_text_size)
table.cell(dash, 1, 0, "STATUS", bgcolor = color.new(color.gray, 90),
text_color = color.white, text_size = dashboard_text_size)
// Current trend
trend_text = trend_direction == 1 ? "BULLISH" : trend_direction == -1 ?
"BEARISH" : "NEUTRAL"
trend_cell_color = trend_direction == 1 ? color.new(bull_color, 70) :
trend_direction == -1 ? color.new(bear_color, 70) : color.new(neutral_color, 70)
table.cell(dash, 0, 1, "Current Trend", text_color = color.white, text_size =
dashboard_text_size)
table.cell(dash, 1, 1, trend_text, bgcolor = trend_cell_color, text_color =
color.white, text_size = dashboard_text_size)
// Trend strength
strength_text = str.tostring(math.round(trend_strength)) + "%"
table.cell(dash, 0, 2, "Trend Strength", text_color = color.white, text_size =
dashboard_text_size)
table.cell(dash, 1, 2, strength_text, text_color = color.white, text_size =
dashboard_text_size)
// Volatility
volatility_text = volatility_state == 1 ? "HIGH" : "NORMAL"
volatility_color = volatility_state == 1 ? color.new(color.orange, 70) :
color.new(color.green, 70)
table.cell(dash, 0, 3, "Volatility", text_color = color.white, text_size =
dashboard_text_size)
table.cell(dash, 1, 3, volatility_text, bgcolor = volatility_color, text_color
= color.white, text_size = dashboard_text_size)
// Momentum
momentum_text = momentum_confluence_bull ? "BULLISH" : momentum_confluence_bear
? "BEARISH" : "NEUTRAL"
momentum_color = momentum_confluence_bull ? color.new(bull_color, 70) :
momentum_confluence_bear ? color.new(bear_color, 70) : color.new(neutral_color, 70)
table.cell(dash, 0, 4, "Momentum", text_color = color.white, text_size =
dashboard_text_size)
table.cell(dash, 1, 4, momentum_text, bgcolor = momentum_color, text_color =
color.white, text_size = dashboard_text_size)
// Multi-timeframe alignment
if timeframe_filter
mtf_text = strong_bullish_alignment ? "STRONG UP" :
strong_bearish_alignment ? "STRONG DOWN" : "MIXED"
mtf_color = strong_bullish_alignment ? color.new(bull_color, 70) :
strong_bearish_alignment ? color.new(bear_color, 70) : color.new(neutral_color, 70)
table.cell(dash, 0, 5, "MTF Alignment", text_color = color.white, text_size
= dashboard_text_size)
table.cell(dash, 1, 5, mtf_text, bgcolor = mtf_color, text_color =
color.white, text_size = dashboard_text_size)
// Price action
if show_price_action
pa_text = price_action_score > 0.5 ? "BULLISH" : price_action_score < -
0.5 ? "BEARISH" : "NEUTRAL"
pa_color = price_action_score > 0.5 ? color.new(bull_color, 70) :
price_action_score < -0.5 ? color.new(bear_color, 70) : color.new(neutral_color,
70)
table.cell(dash, 0, 6, "Price Action", text_color = color.white, text_size
= dashboard_text_size)
table.cell(dash, 1, 6, pa_text, bgcolor = pa_color, text_color =
color.white, text_size = dashboard_text_size)
// Volume Profile Status
if use_volume_profile
vp_text = price_at_volume_node ? "AT KEY LEVEL" : "NO KEY LEVEL"
vp_color = price_at_volume_node ? color.new(#9c27b0, 70) :
color.new(color.gray, 70)
table.cell(dash, 0, 7, "Volume Level", text_color = color.white, text_size
= dashboard_text_size)
table.cell(dash, 1, 7, vp_text, bgcolor = vp_color, text_color =
color.white, text_size = dashboard_text_size)
// Signal status
signal_active = buy_signal or sell_signal or pullback_buy or pullback_sell or
early_buy or early_sell
signal_text = buy_signal ? "BUY" :
sell_signal ? "SELL" :
pullback_buy ? "PULLBACK BUY" :
pullback_sell ? "PULLBACK SELL" :
early_buy ? "EARLY BUY" :
early_sell ? "EARLY SELL" :
"NO SIGNAL"
signal_color = buy_signal or pullback_buy or early_buy ? color.new(bull_color,
70) :
sell_signal or pullback_sell or early_sell ?
color.new(bear_color, 70) :
color.new(neutral_color, 70)
table.cell(dash, 0, 8, "Signal", text_color = color.white, text_size =
dashboard_text_size)
table.cell(dash, 1, 8, signal_text, bgcolor = signal_color, text_color =
color.white, text_size = dashboard_text_size)
// Win Rate Estimate
wr_color = estimated_win_rate > 70 ? color.new(bull_color, 70) :
estimated_win_rate > 50 ? color.new(color.orange, 70) :
color.new(bear_color, 70)
table.cell(dash, 0, 9, "Est. Win Rate", text_color = color.white, text_size =
dashboard_text_size)
table.cell(dash, 1, 9, str.tostring(estimated_win_rate) + "%", bgcolor =
wr_color, text_color = color.white, text_size = dashboard_text_size)
// Best Risk/Reward
if enable_projections and trend_direction != 0
best_rr = math.max(risk_reward1, math.max(risk_reward2, risk_reward3))
rr_text = str.tostring(best_rr, "#.##") + "R"
rr_color = best_rr > 3 ? color.new(bull_color, 70) :
best_rr > 2 ? color.new(color.orange, 70) :
color.new(bear_color, 70)
table.cell(dash, 0, 10, "Best R:R", text_color = color.white, text_size =
dashboard_text_size)
table.cell(dash, 1, 10, rr_text, bgcolor = rr_color, text_color =
color.white, text_size = dashboard_text_size)
// Current price relative to trend
price_status_text = close > trend_tracer_line ? "ABOVE TREND" : close <
trend_tracer_line ? "BELOW TREND" : "AT TREND"
price_status_color = close > trend_tracer_line ? color.new(bull_color, 70) :
close < trend_tracer_line ? color.new(bear_color, 70) : color.new(neutral_color,
70)
table.cell(dash, 0, 11, "Price Status", text_color = color.white, text_size =
dashboard_text_size)
table.cell(dash, 1, 11, price_status_text, bgcolor = price_status_color,
text_color = color.white, text_size = dashboard_text_size)
// ==========================================================================
// ALERTS
// ==========================================================================
// Generate alert conditions
alertcondition(buy_signal, "Trend Tracer Buy Signal", "Trend Tracer: Buy signal
detected")
alertcondition(sell_signal, "Trend Tracer Sell Signal", "Trend Tracer: Sell signal
detected")
alertcondition(pullback_buy, "Trend Tracer Pullback Buy", "Trend Tracer: Pullback
buy opportunity")
alertcondition(pullback_sell, "Trend Tracer Pullback Sell", "Trend Tracer: Pullback
sell opportunity")
alertcondition(early_buy, "Trend Tracer Early Buy", "Trend Tracer: Early buy signal
detected")
alertcondition(early_sell, "Trend Tracer Early Sell", "Trend Tracer: Early sell
signal detected")
alertcondition(trend_shift_up, "Trend Shifted Bullish", "Trend Tracer: Trend
shifted to bullish")
alertcondition(trend_shift_down, "Trend Shifted Bearish", "Trend Tracer: Trend
shifted to bearish")
alertcondition(price_at_volume_node, "Price at Key Volume Level", "Trend Tracer:
Price at significant volume level")