tradingview mustang script gulshan with cmo value if not showing change value of vidya momentum form 25 to 10
Posted By On 5/06/2026 08:36:00 AM
//@version=5
// ═══════════════════════════════════════════════════════════════════════════
// MUSTANG + FRAMA + SENTIMENTAL RSI + DIAMOND ALIGNMENT + QUANTIFICATION
// Created by: Gulshan Khera, CFP
// Nifty & BankNifty Expert at INDIAN-SHARE-TIPS.COM
// Optimized for 5-Minute NSE Options Trading
// ═══════════════════════════════════════════════════════════════════════════
indicator("Mustang + FRAMA + SRSI + Diamonds + Quant - Gulshan Khera", overlay=true, max_labels_count=500, max_lines_count=500)
//═══════════════════════════════════════════════════════════════════════════
// QUANTIFICATION SYSTEM SETTINGS
//═══════════════════════════════════════════════════════════════════════════
enable_quant = input.bool(true, "🔢 Enable Quantification", group="🔢 QUANTIFICATION")
show_grade_labels = input.bool(true, "Show Grade Numbers in Candles", group="🔢 QUANTIFICATION")
grade_vertical_offset = input.float(0.25, "Vertical Position (0=bottom, 0.5=center, 1=top)", minval=0.0, maxval=1.0, step=0.05, group="🔢 QUANTIFICATION")
grade_horizontal_shift = input.int(0, "Horizontal Shift (bars)", minval=-5, maxval=5, group="🔢 QUANTIFICATION")
show_grade_3plus = input.bool(true, "3+", group="🔢 Grades", inline="g1")
show_grade_3 = input.bool(true, "3", group="🔢 Grades", inline="g1")
show_grade_2plus = input.bool(true, "2+", group="🔢 Grades", inline="g2")
show_grade_2 = input.bool(true, "2", group="🔢 Grades", inline="g2")
show_grade_1 = input.bool(true, "1", group="🔢 Grades", inline="g3")
show_grade_0 = input.bool(true, "0", group="🔢 Grades", inline="g3")
enable_tier1 = input.bool(true, "Tier 1", group="🔢 Tiers", inline="t1")
enable_tier2 = input.bool(true, "Tier 2", group="🔢 Tiers", inline="t1")
enable_tier3 = input.bool(true, "Tier 3", group="🔢 Tiers", inline="t1")
enable_gaussian_scoring = input.bool(true, "Gaussian", group="🔢 Indicators", inline="i1")
enable_sr_scoring = input.bool(true, "SR", group="🔢 Indicators", inline="i1")
enable_srsi_scoring = input.bool(true, "SRSI", group="🔢 Indicators", inline="i2")
enable_tdfi_scoring = input.bool(true, "TDFI", group="🔢 Indicators", inline="i2")
enable_deceptive_scoring = input.bool(true, "Deceptive", group="🔢 Indicators", inline="i3")
grade_text_size = input.string("small", "Grade Text Size", options=["tiny","small","normal","large"], group="🔢 QUANTIFICATION")
buy_text_col = input.color(color.white, "Buy Text", group="🔢 Colors", inline="c1")
sell_text_col = input.color(color.yellow, "Sell Text", group="🔢 Colors", inline="c1")
buy_3p = input.color(#00ff00, "3+", group="🔢 Buy", inline="b1")
buy_3 = input.color(#00dd00, "3", group="🔢 Buy", inline="b1")
buy_2p = input.color(#00bb00, "2+", group="🔢 Buy", inline="b2")
buy_2 = input.color(#009900, "2", group="🔢 Buy", inline="b2")
buy_1 = input.color(#007700, "1", group="🔢 Buy", inline="b3")
sell_3p = input.color(#ff0000, "3+", group="🔢 Sell", inline="s1")
sell_3 = input.color(#dd0000, "3", group="🔢 Sell", inline="s1")
sell_2p = input.color(#bb0000, "2+", group="🔢 Sell", inline="s2")
sell_2 = input.color(#990000, "2", group="🔢 Sell", inline="s2")
sell_1 = input.color(#770000, "1", group="🔢 Sell", inline="s3")
neutral_col = input.color(#555555, "0", group="🔢 Colors", inline="c2")
//═══════════════════════════════════════════════════════════════════════════
// CANDLE PATTERN SETTINGS
//═══════════════════════════════════════════════════════════════════════════
enable_candle_patterns = input.bool(true, "🕯️ Enable Candle Patterns", group="🕯️ CANDLE PATTERNS")
show_pattern_labels = input.bool(true, "Show Pattern Labels on Chart", group="🕯️ CANDLE PATTERNS")
candle_confirmation_bonus = input.int(5, "Confirmation Bonus", minval=3, maxval=10, group="🕯️ CANDLE PATTERNS", tooltip="Bonus when pattern confirms grade direction")
candle_contradiction_penalty = input.int(10, "Contradiction Penalty", minval=5, maxval=15, group="🕯️ CANDLE PATTERNS", tooltip="Penalty when pattern contradicts grade direction")
pattern_label_size = input.string("tiny", "Pattern Label Size", options=["tiny","small","normal"], group="🕯️ CANDLE PATTERNS")
show_hammer_labels = input.bool(true, "Show Hammer Labels", group="🕯️ CANDLE PATTERNS")
show_shoot_labels = input.bool(true, "Show Shooting Star Labels", group="🕯️ CANDLE PATTERNS")
show_engulf_labels = input.bool(false, "Show Engulfing Labels", group="🕯️ CANDLE PATTERNS")
show_marubozu_labels = input.bool(false, "Show Marubozu Labels", group="🕯️ CANDLE PATTERNS")
//═══════════════════════════════════════════════════════════════════════════
// SYSTEM SELECTION & TOGGLES
//═══════════════════════════════════════════════════════════════════════════
enable_mustang = input.bool(true, "🐎 Enable Mustang System", group="⚙️ SYSTEM SELECTION")
enable_frama = input.bool(true, "📊 Enable FRAMA Panel", group="⚙️ SYSTEM SELECTION")
enable_sentimental_rsi = input.bool(true, "💭 Enable Sentimental RSI Line", group="⚙️ SYSTEM SELECTION")
show_mustang_symbols = input.bool(true, "Show Mustang 🐎 Symbols", group="⚙️ SYMBOL TOGGLES")
show_frama_symbols = input.bool(true, "Show FRAMA ▲▼ Symbols", group="⚙️ SYMBOL TOGGLES")
show_diamond_symbols = input.bool(true, "Show Diamond Symbols", group="⚙️ SYMBOL TOGGLES")
show_deceptive_dot = input.bool(true, "Show Deceptive Dot", group="⚙️ SYMBOL TOGGLES")
enable_mustang_blink = input.bool(true, "Enable Mustang Blinking Alerts", group="⚙️ ALERTS - MUSTANG")
enable_mustang_audio = input.bool(true, "Enable Mustang Audio Alert", group="⚙️ ALERTS - MUSTANG")
mustang_blink_duration = input.int(3, "Mustang Blink Duration (bars)", minval=1, maxval=10, group="⚙️ ALERTS - MUSTANG")
enable_frama_blink = input.bool(true, "Enable FRAMA Blinking Alerts", group="⚙️ ALERTS - FRAMA")
enable_frama_audio = input.bool(true, "Enable FRAMA Audio Alert", group="⚙️ ALERTS - FRAMA")
frama_blink_duration = input.int(3, "FRAMA Blink Duration (bars)", minval=1, maxval=10, group="⚙️ ALERTS - FRAMA")
enable_deceptive_dot = input.bool(true, "Enable Deceptive Dot", group="🟡 DECEPTIVE DOT")
deceptive_dot_color = input.color(color.yellow, "Dot Color", group="🟡 DECEPTIVE DOT")
enable_stop_loss = input.bool(true, "Enable Stop Loss Display", group="🛑 STOP LOSS SYSTEM")
stop_loss_atr_multiplier = input.float(1.5, "ATR Multiplier for SL", minval=0.5, maxval=5.0, step=0.1, group="🛑 STOP LOSS SYSTEM")
visual_spacing_note = input.bool(false, "ℹ️ Spacing: Diamond (farthest) → Mustang → FRAMA → Dot (closest)", group="🎨 VISUAL SPACING")
//═══════════════════════════════════════════════════════════════════════════
// DIAMOND ALIGNMENT SYSTEM SETTINGS
//═══════════════════════════════════════════════════════════════════════════
enable_diamonds = input.bool(true, "🔷 Enable Diamond Signals", group="💎 DIAMOND ALIGNMENT")
show_all_diamonds = input.bool(true, "Show Diamonds on ALL Candles", group="💎 DIAMOND ALIGNMENT", tooltip="When ON: Shows diamonds everywhere. When OFF: Shows ONLY at Mustang/FRAMA signals")
show_mustang_diamonds = input.bool(true, "Show Diamonds at Mustang Signals", group="💎 DIAMOND ALIGNMENT", tooltip="Shows diamonds at Mustang entry/exit signals (BUY/SELL/EXIT)")
show_frama_diamonds = input.bool(true, "Show Diamonds at FRAMA Signals", group="💎 DIAMOND ALIGNMENT", tooltip="Shows diamonds at FRAMA entry/exit signals (BUY/SELL/EXIT)")
diamond_offset = input.int(120, "Diamond Offset (ticks from candle)", minval=0, group="💎 DIAMOND ALIGNMENT", tooltip="Distance from candle - should be farthest from all symbols")
diamond_transparency = input.int(0, "Diamond Transparency %", minval=0, maxval=100, group="💎 DIAMOND ALIGNMENT")
strong_bull_shape = input.string("diamond", "Strong Bullish Shape", options=["diamond","circle","square","triangleup","cross","xcross"], group="💎 STRONG (4/4)")
strong_bull_color = input.color(color.lime, "Strong Bullish Color", group="💎 STRONG (4/4)")
strong_bull_size = input.string("large", "Strong Bullish Size", options=["tiny","small","normal","large","huge"], group="💎 STRONG (4/4)")
strong_bear_shape = input.string("diamond", "Strong Bearish Shape", options=["diamond","circle","square","triangledown","cross","xcross"], group="💎 STRONG (4/4)")
strong_bear_color = input.color(color.red, "Strong Bearish Color", group="💎 STRONG (4/4)")
strong_bear_size = input.string("large", "Strong Bearish Size", options=["tiny","small","normal","large","huge"], group="💎 STRONG (4/4)")
moderate_bull_shape = input.string("diamond", "Moderate Bullish Shape", options=["diamond","circle","square","triangleup","cross","xcross"], group="💎 MODERATE (3/4)")
moderate_bull_color = input.color(color.blue, "Moderate Bullish Color", group="💎 MODERATE (3/4)")
moderate_bull_size = input.string("small", "Moderate Bullish Size", options=["tiny","small","normal","large","huge"], group="💎 MODERATE (3/4)")
moderate_bear_shape = input.string("diamond", "Moderate Bearish Shape", options=["diamond","circle","square","triangledown","cross","xcross"], group="💎 MODERATE (3/4)")
moderate_bear_color = input.color(color.fuchsia, "Moderate Bearish Color", group="💎 MODERATE (3/4)")
moderate_bear_size = input.string("small", "Moderate Bearish Size", options=["tiny","small","normal","large","huge"], group="💎 MODERATE (3/4)")
//═══════════════════════════════════════════════════════════════════════════
// MUSTANG SYSTEM SETTINGS
//═══════════════════════════════════════════════════════════════════════════
doji_threshold = input.float(0.15, "Doji Threshold", minval=0.0, maxval=1.0, group="🐎 MUSTANG - Filters")
wick_threshold = input.float(0.10, "Zero-Wick Threshold", minval=0.0, maxval=0.5, group="🐎 MUSTANG - Filters")
use_ha_confirmation = input.bool(true, "Use Heikin Ashi Confirmation", group="🐎 MUSTANG - Filters")
show_mustang_ha = input.bool(false, "Show Mustang Heikin Ashi Candles", group="🐎 MUSTANG - Filters")
enable_first_candle_filter = input.bool(true, "Enable First Candle Protection", group="🐎 MUSTANG - Safety")
gap_threshold = input.float(0.75, "Gap Threshold %", minval=0.0, maxval=5.0, group="🐎 MUSTANG - Safety")
wide_range_threshold = input.float(0.5, "Wide Range Threshold %", minval=0.0, maxval=2.0, group="🐎 MUSTANG - Safety")
wick_trap_threshold = input.float(0.40, "Wick Trap Threshold", minval=0.0, maxval=0.8, group="🐎 MUSTANG - Safety")
enable_trend_filter = input.bool(true, "Enable Trend Meter Filter", group="🐎 MUSTANG - Trend Meter")
mustang_buy_color = input.color(color.lime, "Buy Signal Color", group="🐎 MUSTANG - Visual")
mustang_sell_color = input.color(color.red, "Sell Signal Color", group="🐎 MUSTANG - Visual")
mustang_exit_color = input.color(color.orange, "Exit Signal Color", group="🐎 MUSTANG - Visual")
mustang_size = input.string("tiny", "Signal Size", options=["tiny","small","normal","large"], group="🐎 MUSTANG - Visual")
//═══════════════════════════════════════════════════════════════════════════
// FRAMA SYSTEM SETTINGS
//═══════════════════════════════════════════════════════════════════════════
mmaMode = input.string("ema", "MMA Mode", options=["ema","wma","swma","vwma","hull","tema"], group="📊 FRAMA - TDFI")
smmaMode = input.string("ema", "SMMA Mode", options=["ema","wma","swma","vwma","hull","tema"], group="📊 FRAMA - TDFI")
filterHigh = input.float(0.05, "Filter High", group="📊 FRAMA - TDFI")
filterLow = input.float(-0.05, "Filter Low", group="📊 FRAMA - TDFI")
tdfi_vertical_offset = input.float(0.0, "TDFI Vertical Offset (ATR multiplier)", minval=-50.0, maxval=50.0, step=0.5, group="📊 FRAMA - TDFI", tooltip="Move TDFI line up/down. Positive = up, Negative = down. Try values like 5.0 to 20.0 to bring line closer to candles")
bandsDist = input.float(1.5, "Bands Distance", group="📊 FRAMA - Bands")
frama_middle_color = input.color(color.new(color.gray, 50), "Middle Line Color", group="📊 FRAMA - Bands")
frama_upper_color = input.color(color.new(color.gray, 60), "Upper Band Color", group="📊 FRAMA - Bands")
frama_lower_color = input.color(color.new(color.gray, 60), "Lower Band Color", group="📊 FRAMA - Bands")
show_frama_fill = input.bool(false, "Show FRAMA Band Fill", group="📊 FRAMA - Bands")
gauss_color_up = input.color(color.new(color.green, 30), "Gaussian Up Color", group="📊 FRAMA - Gaussian")
gauss_color_down = input.color(color.new(color.red, 30), "Gaussian Down Color", group="📊 FRAMA - Gaussian")
gauss_linewidth = input.int(2, "Gaussian Line Width", minval=1, maxval=5, group="📊 FRAMA - Gaussian")
vidyaBandDist = input.float(1.8, "Band Distance", step=0.1, group="📊 FRAMA - VIDYA")
vidyaShadow = input.bool(false, "Show Shadow", group="📊 FRAMA - VIDYA")
cmo_label_offset = input.int(30, "CMO Label Offset (ticks)", minval=0, maxval=500, group="📊 FRAMA - VIDYA")
showFramaHA = input.bool(false, "Show FRAMA Heikin Ashi", group="📊 FRAMA - Display")
frama_triangle_size = input.string("large", "Triangle Size", options=["tiny","small","normal","large","huge"], group="📊 FRAMA - Visual")
frama_buy_color = input.color(color.white, "Triangle Color", group="📊 FRAMA - Visual")
frama_sell_color = input.color(color.white, "Triangle Color", group="📊 FRAMA - Visual")
frama_exit_color = input.color(color.red, "Exit X Color", group="📊 FRAMA - Visual")
//═══════════════════════════════════════════════════════════════════════════
// SENTIMENTAL RSI SETTINGS
//═══════════════════════════════════════════════════════════════════════════
//═══════════════════════════════════════════════════════════════════════════
// HELPER FUNCTIONS
//═══════════════════════════════════════════════════════════════════════════
tema(src, len) =>
ema1 = ta.ema(src, len)
ema2 = ta.ema(ema1, len)
ema3 = ta.ema(ema2, len)
(3 * ema1) - (3 * ema2) + ema3
swma_fallback(src) => ta.sma(src, 3)
ma_by_mode(mode, src, len) =>
float out = na
if mode == "ema"
out := ta.ema(src, len)
else if mode == "wma"
out := ta.wma(src, len)
else if mode == "swma"
out := swma_fallback(src)
else if mode == "vwma"
out := ta.vwma(src, len)
else if mode == "hull"
out := ta.wma((2 * ta.wma(src, len / 2)) - ta.wma(src, len), math.round(math.sqrt(len)))
else if mode == "tema"
out := tema(src, len)
else
out := ta.sma(src, len)
out
get_label_size(sz_string) =>
sz_string == "tiny" ? size.tiny : sz_string == "small" ? size.small : sz_string == "large" ? size.large : sz_string == "huge" ? size.huge : size.normal
//═══════════════════════════════════════════════════════════════════════════
// SENTIMENTAL RSI CALCULATIONS
//═══════════════════════════════════════════════════════════════════════════
r = ta.rsi(close, rsiLen)
s1 = ta.ema(r, smoothFast)
rs = ta.ema(s1, smoothSlow)
srsi_col = rs > rs[1] ? color.green : color.red
plot(enable_sentimental_rsi ? rs : na, "Sentimental RSI", color=srsi_col, linewidth=srsi_line_width)
//═══════════════════════════════════════════════════════════════════════════
// MUSTANG SYSTEM CALCULATIONS
//═══════════════════════════════════════════════════════════════════════════
ema_base_line = ta.ema(close, ema_base)
ema_fast_line = ta.ema(close, ema_fast)
ema_med_line = ta.ema(close, ema_med)
ema_slow_line = ta.ema(close, ema_slow)
bool all_emas_green = close > ema_base_line and close > ema_fast_line and close > ema_med_line and close > ema_slow_line
bool all_emas_red = close < ema_base_line and close < ema_fast_line and close < ema_med_line and close < ema_slow_line
rsi_value = ta.rsi(close, rsi_length)
stoch_rsi = ta.stoch(rsi_value, rsi_value, rsi_value, stoch_length)
stoch_k = ta.sma(stoch_rsi, smoothK)
stoch_d = ta.sma(stoch_k, smoothD)
bool stoch_light_grey = stoch_k > 50
bool stoch_dark_grey = stoch_k <= 50
var alpha_mustang = 2/(length+1)
var up1 = 0., var up2 = 0.
var dn1 = 0., var dn2 = 0.
C = close
O = open
up1 := nz(math.max(C, O, up1[1] - (up1[1] - C) * alpha_mustang), C)
up2 := nz(math.max(C * C, O * O, up2[1] - (up2[1] - C * C) * alpha_mustang), C * C)
dn1 := nz(math.min(C, O, dn1[1] + (C - dn1[1]) * alpha_mustang), C)
dn2 := nz(math.min(C * C, O * O, dn2[1] + (C * C - dn2[1]) * alpha_mustang), C * C)
bull = math.sqrt(dn2 - dn1 * dn1)
bear = math.sqrt(up2 - up1 * up1)
signal_line = ta.ema(math.max(bull, bear), sig_length)
bull_slope = bull - bull[1]
bear_slope = bear - bear[1]
var float ha_close_mustang = na
var float ha_open_mustang = na
ha_close_mustang := (open + high + low + close) / 4
ha_open_mustang := na(ha_open_mustang[1]) ? (open + close) / 2 : (ha_open_mustang[1] + ha_close_mustang[1]) / 2
float ha_high_mustang = math.max(high, math.max(ha_open_mustang, ha_close_mustang))
float ha_low_mustang = math.min(low, math.min(ha_open_mustang, ha_close_mustang))
bool ha_is_green_mustang = ha_close_mustang > ha_open_mustang
bool ha_is_red_mustang = ha_close_mustang < ha_open_mustang
mustang_ha_o = show_mustang_ha ? ha_open_mustang : na
mustang_ha_h = show_mustang_ha ? ha_high_mustang : na
mustang_ha_l = show_mustang_ha ? ha_low_mustang : na
mustang_ha_c = show_mustang_ha ? ha_close_mustang : na
plotcandle(mustang_ha_o, mustang_ha_h, mustang_ha_l, mustang_ha_c,
title="Mustang HA")
bool is_first_candle = ta.change(time("D")) != 0
float prev_close_mustang = ta.valuewhen(ta.change(time("D")) != 0, close[1], 0)
bool first_candle_safe = true
if is_first_candle and enable_first_candle_filter
float gap_percent = math.abs(open - prev_close_mustang) / prev_close_mustang * 100
if gap_percent > gap_threshold
first_candle_safe := false
float range_percent = (high - low) / open * 100
if range_percent > wide_range_threshold
first_candle_safe := false
float candle_range_mustang = high - low
if candle_range_mustang > 0
float upper_wick_pct = (high - math.max(open, close)) / candle_range_mustang
float lower_wick_pct = (math.min(open, close) - low) / candle_range_mustang
if upper_wick_pct > wick_trap_threshold or lower_wick_pct > wick_trap_threshold
first_candle_safe := false
float body_pct = candle_range_mustang > 0 ? math.abs(close - open) / candle_range_mustang : 0
if body_pct < doji_threshold
first_candle_safe := false
bool has_strong_buy_slope = bull > bear and bull_slope > 0
bool has_strong_sell_slope = bear > bull and bear_slope > 0
if not has_strong_buy_slope and not has_strong_sell_slope
first_candle_safe := false
candle_body_mustang = math.abs(close - open)
candle_range_mustang = high - low
is_doji_mustang = candle_range_mustang > 0 ? (candle_body_mustang < doji_threshold * candle_range_mustang) : true
upper_wick_mustang = high - math.max(open, close)
is_zero_wick_bullish = candle_range_mustang > 0 ? (upper_wick_mustang < wick_threshold * candle_range_mustang) : false
lower_wick_mustang = math.min(open, close) - low
is_zero_wick_bearish = candle_range_mustang > 0 ? (lower_wick_mustang < wick_threshold * candle_range_mustang) : false
close_at_low = math.abs(close - low) < syminfo.mintick * 2
close_at_high = math.abs(close - high) < syminfo.mintick * 2
is_true_green = close > open and (use_ha_confirmation ? ha_is_green_mustang : true)
is_true_red = close < open and (use_ha_confirmation ? ha_is_red_mustang : true)
var bool in_buy_position = false
var bool in_sell_position = false
var bool bull_crossed_bear = false
var bool bull_crossed_signal = false
var bool bear_crossed_bull = false
var bool bear_crossed_signal = false
if ta.crossover(bull, bear) and not in_buy_position
bull_crossed_bear := true
bull_crossed_signal := false
if bull_crossed_bear and ta.crossover(bull, signal_line) and bull > bear
bull_crossed_signal := true
if bull_crossed_signal and ta.crossunder(bull, signal_line)
bull_crossed_signal := false
if ta.crossover(bear, bull)
bull_crossed_bear := false
bull_crossed_signal := false
bool andean_buy_ready = bull_crossed_bear and bull_crossed_signal and bull > bear and bull > signal_line
bool mustang_buySignal = false
if andean_buy_ready and enable_mustang and barstate.isconfirmed
bool allow_signal = true
if is_first_candle and not first_candle_safe
allow_signal := false
if enable_trend_filter
if not (all_emas_green and stoch_light_grey)
allow_signal := false
if allow_signal
if not is_doji_mustang and not is_zero_wick_bullish and not close_at_low and is_true_green
mustang_buySignal := true
bull_crossed_bear := false
bull_crossed_signal := false
in_buy_position := true
in_sell_position := false
if ta.crossover(bear, bull) and not in_sell_position
bear_crossed_bull := true
bear_crossed_signal := false
if bear_crossed_bull and ta.crossover(bear, signal_line) and bear > bull
bear_crossed_signal := true
if bear_crossed_signal and ta.crossunder(bear, signal_line)
bear_crossed_signal := false
if ta.crossover(bull, bear)
bear_crossed_bull := false
bear_crossed_signal := false
bool andean_sell_ready = bear_crossed_bull and bear_crossed_signal and bear > bull and bear > signal_line
bool mustang_sellSignal = false
if andean_sell_ready and enable_mustang and barstate.isconfirmed
bool allow_signal = true
if is_first_candle and not first_candle_safe
allow_signal := false
if enable_trend_filter
if not (all_emas_red and stoch_dark_grey)
allow_signal := false
if allow_signal
if not is_doji_mustang and not is_zero_wick_bearish and not close_at_high and is_true_red
mustang_sellSignal := true
bear_crossed_bull := false
bear_crossed_signal := false
in_sell_position := true
in_buy_position := false
bool mustang_exitBuy = in_buy_position and ta.crossunder(bull, signal_line)
if mustang_exitBuy
in_buy_position := false
bull_crossed_bear := false
bull_crossed_signal := false
bool mustang_exitSell = in_sell_position and ta.crossunder(bear, signal_line)
if mustang_exitSell
in_sell_position := false
bear_crossed_bull := false
bear_crossed_signal := false
//═══════════════════════════════════════════════════════════════════════════
// FRAMA SYSTEM CALCULATIONS
//═══════════════════════════════════════════════════════════════════════════
td_src = close
mma = ma_by_mode(mmaMode, td_src * 1000, mmaLength)
smma = ma_by_mode(smmaMode, mma, smmaLength)
imp_mma = mma - mma[1]
imp_smma = smma - smma[1]
divma = math.abs(mma - smma)
avg_imp = (imp_mma + imp_smma) / 2
tdf = divma * math.pow(avg_imp, nLength)
tdfi = tdf / ta.highest(math.abs(tdf), lookback * nLength)
rangeHigh = ta.highest(high, rangeLen)
rangeLow = ta.lowest(low, rangeLen)
rangeW = rangeHigh - rangeLow
rangeOsc = rangeW != 0 ? ((close - rangeLow) / rangeW) * 100 : 50
sigma = gaussLen / 3
sumW = 0.0
sumV = 0.0
for i = 0 to gaussLen - 1
mid = (gaussLen - 1) / 2
x = (i - mid) / sigma
w = math.exp(-0.5 * x * x)
sumW += w
sumV += close[i] * w
gauss = sumV / (sumW == 0 ? 1 : sumW)
plot(gauss, "Gaussian Filter", color = gauss > gauss[1] ? gauss_color_up : gauss_color_down, linewidth=gauss_linewidth)
vid_calc(_src, _len, _mom) =>
mlen = math.max(1, math.min(_mom, bar_index + 1))
float sumPos = 0.0, sumNeg = 0.0
for k = 0 to mlen - 1
d = nz(_src[k]) - nz(_src[k + 1])
if d >= 0
sumPos += d
else
sumNeg += -d
denom = sumPos + sumNeg
abs_cmo = denom != 0 ? math.abs(100 * (sumPos - sumNeg) / denom) : 0
alpha_vid = 2 / (_len + 1)
var float vid = na
if na(vid)
vid := nz(_src)
vid := (alpha_vid * abs_cmo / 100) * nz(_src) + (1 - alpha_vid * abs_cmo / 100) * nz(vid[1], nz(_src))
ta.sma(vid, 15)
vidya_val = vid_calc(close, vidyaLen, vidyaMomentum)
atr_vid = ta.atr(200)
upper_vidya = vidya_val + atr_vid * vidyaBandDist
lower_vidya = vidya_val - atr_vid * vidyaBandDist
var bool vidUp = false
if ta.crossover(close, upper_vidya)
vidUp := true
if ta.crossunder(close, lower_vidya)
vidUp := false
sv = vidUp ? lower_vidya : upper_vidya
if ta.change(vidUp)
sv := na
vcol = vidUp ? vidya_color_up : vidya_color_down
p_vid = plot(sv, "VIDYA", color=vcol, linewidth=vidya_linewidth)
p_hl = plot(hl2, display=display.none)
haClose_frama = (open + high + low + close) / 4
var float haOpen_frama = na
haOpen_frama := na(haOpen_frama[1]) ? (open + close) / 2 : (haOpen_frama[1] + haClose_frama[1]) / 2
haHigh_frama = math.max(high, math.max(haOpen_frama, haClose_frama))
haLow_frama = math.min(low, math.min(haOpen_frama, haClose_frama))
haBull_frama = haClose_frama >= haOpen_frama
frama_ha_o = showFramaHA ? haOpen_frama : na
frama_ha_h = showFramaHA ? haHigh_frama : na
frama_ha_l = showFramaHA ? haLow_frama : na
frama_ha_c = showFramaHA ? haClose_frama : na
plotcandle(frama_ha_o, frama_ha_h, frama_ha_l, frama_ha_c,
title="FRAMA HA")
bullDec = close < open and haClose_frama > haOpen_frama
bearDec = close > open and haClose_frama < haOpen_frama
candle_center = (open + close) / 2
plot(enable_deceptive_dot and show_deceptive_dot and (bullDec or bearDec) and barstate.isconfirmed ? candle_center : na,
"Deceptive Dot",
style=plot.style_circles,
linewidth=3)
sr_rsi_len = 14
sr_stoch_len = 134
sr_smooth_k = 3
sr_smooth_d = 3
sr_rsi = ta.rsi(close, sr_rsi_len)
sr_ll = ta.lowest(sr_rsi, sr_stoch_len)
sr_hh = ta.highest(sr_rsi, sr_stoch_len)
sr_base = sr_hh - sr_ll != 0 ? (sr_rsi - sr_ll) / (sr_hh - sr_ll) : 0
sr_k = ta.sma(sr_base * 100, sr_smooth_k)
sr_d = ta.sma(sr_k, sr_smooth_d)
sr_color_down = input.color(color.new(color.red, 20), "SR Line Down Color", group="📊 FRAMA - SR Line")
plot(sr_d, "SR Line", color = sr_d >= 50 ? sr_color_up : sr_color_down, linewidth=sr_linewidth)
tdfi_color_up = input.color(color.new(color.green, 20), "TDFI Up Color", group="📊 FRAMA - TDFI Colors")
tdfi_color_down = input.color(color.new(color.red, 20), "TDFI Down Color", group="📊 FRAMA - TDFI Colors")
tdfi_color_mid = input.color(color.new(color.gray, 40), "TDFI Neutral Color", group="📊 FRAMA - TDFI Colors")
td_color = tdfi > filterHigh ? tdfi_color_up : tdfi < filterLow ? tdfi_color_down : tdfi_color_mid
// Calculate vertical offset for TDFI line
tdfi_atr = ta.atr(14)
tdfi_offset_value = tdfi_vertical_offset * tdfi_atr
p_tdfi = plot(tdfi + tdfi_offset_value, "TDFI", color=td_color, linewidth=tdfi_linewidth)
p_hi = plot(filterHigh + tdfi_offset_value, "High Level", color=color.new(color.green, 80), linewidth=1)
p_lo = plot(filterLow + tdfi_offset_value, "Low Level", color=color.new(color.red, 80), linewidth=1)
type FRAMABands
float N1
float N2
float N3
float HH
float LL
float Dim
float alpha
frama_bands = FRAMABands.new(0, 0, 0, 0, 0, 0, 0)
frama_bands.N3 := (ta.highest(high, framaN) - ta.lowest(low, framaN)) / framaN
frama_bands.HH := high
frama_bands.LL := low
for i = 0 to framaN / 2 - 1
if high[i] > frama_bands.HH
frama_bands.HH := high[i]
if low[i] < frama_bands.LL
frama_bands.LL := low[i]
frama_bands.N1 := (frama_bands.HH - frama_bands.LL) / (framaN / 2)
frama_bands.HH := high[framaN / 2]
frama_bands.LL := low[framaN / 2]
for i = framaN / 2 to framaN - 1
if high[i] > frama_bands.HH
frama_bands.HH := high[i]
if low[i] < frama_bands.LL
frama_bands.LL := low[i]
frama_bands.N2 := (frama_bands.HH - frama_bands.LL) / (framaN / 2)
if frama_bands.N1 > 0 and frama_bands.N2 > 0 and frama_bands.N3 > 0
frama_bands.Dim := (math.log(frama_bands.N1 + frama_bands.N2) - math.log(frama_bands.N3)) / math.log(2)
frama_bands.alpha := math.max(math.min(math.exp(-4.6 * (frama_bands.Dim - 1)), 1), 0.01)
var float Filt = na
Filt := na(Filt) ? hl2 : frama_bands.alpha * hl2 + (1 - frama_bands.alpha) * nz(Filt[1])
Filt := ta.sma((bar_index < framaN + 1 ? hl2 : Filt), 5)
vol = ta.sma(high - low, 200)
FiltU = Filt + vol * bandsDist
FiltL = Filt - vol * bandsDist
p0 = plot(Filt, "FRAMA Middle", color=frama_middle_color, linewidth=frama_linewidth)
p1 = plot(FiltU, "FRAMA Upper", color=frama_upper_color, linewidth=frama_linewidth)
p2 = plot(FiltL, "FRAMA Lower", color=frama_lower_color, linewidth=frama_linewidth)
bodyTop_frama = math.max(open, close)
bodyBot_frama = math.min(open, close)
bodyH_frama = bodyTop_frama - bodyBot_frama
pctA = bodyH_frama > 0 ? (bodyTop_frama - FiltU) / bodyH_frama * 100 : 0
pctB = bodyH_frama > 0 ? (FiltL - bodyBot_frama) / bodyH_frama * 100 : 0
buyB = pctA >= breach_pct
sellB = pctB >= breach_pct
rangeOKBuy = rangeOsc >= rangeBuyLvl
rangeOKSell = rangeOsc <= rangeSellLvl
var bool in_frama_buy = false
var bool in_frama_sell = false
var int frama_entry_day = -1
var int frama_buy_bar = -1
var int frama_sell_bar = -1
bool frama_buySignal = false
bool frama_sellSignal = false
bool frama_exitBuy = false
bool frama_exitSell = false
int current_day = dayofmonth(time)
if current_day != frama_entry_day
in_frama_buy := false
in_frama_sell := false
if buyB and rangeOKBuy and enable_frama and not in_frama_buy and barstate.isconfirmed
frama_buySignal := true
in_frama_buy := true
in_frama_sell := false
frama_entry_day := current_day
frama_buy_bar := bar_index
if in_frama_buy and not frama_buySignal and barstate.isconfirmed
float pctBelowBand = bodyH_frama > 0 ? ((FiltU - bodyBot_frama) / bodyH_frama) * 100 : 0
if pctBelowBand >= breach_pct
frama_exitBuy := true
in_frama_buy := false
if sellB and rangeOKSell and enable_frama and not in_frama_sell and barstate.isconfirmed
frama_sellSignal := true
in_frama_sell := true
in_frama_buy := false
frama_entry_day := current_day
frama_sell_bar := bar_index
if in_frama_sell and not frama_sellSignal and barstate.isconfirmed
float pctAboveBand = bodyH_frama > 0 ? ((bodyTop_frama - FiltL) / bodyH_frama) * 100 : 0
if pctAboveBand >= breach_pct
frama_exitSell := true
in_frama_sell := false
//═══════════════════════════════════════════════════════════════════════════
// CANDLE PATTERN DETECTION
//═══════════════════════════════════════════════════════════════════════════
float body = math.abs(close - open)
float total_range = high - low
float upper_shadow = high - math.max(open, close)
float lower_shadow = math.min(open, close) - low
bool green_candle = close > open
bool red_candle = close < open
bool valid_candle = total_range > 0 and body > 0
bool bullish_engulfing = green_candle and close[1] < open[1] and close > open[1] and open < close[1] and body > body[1] * 1.1
bool bearish_engulfing = red_candle and close[1] > open[1] and close < open[1] and open > close[1] and body > body[1] * 1.1
bool hammer = valid_candle and lower_shadow > body * 2 and upper_shadow < body * 0.3 and close > ta.lowest(low, 10)
bool shooting_star = valid_candle and upper_shadow > body * 2 and lower_shadow < body * 0.3 and close < ta.highest(high, 10)
bool bullish_marubozu = green_candle and valid_candle and upper_shadow < total_range * 0.05 and lower_shadow < total_range * 0.05 and body > total_range * 0.9
bool bearish_marubozu = red_candle and valid_candle and upper_shadow < total_range * 0.05 and lower_shadow < total_range * 0.05 and body > total_range * 0.9
bool bullish_pattern = bullish_engulfing or hammer or bullish_marubozu
bool bearish_pattern = bearish_engulfing or shooting_star or bearish_marubozu
string pattern_name = bullish_engulfing ? "Bullish Engulfing" : bearish_engulfing ? "Bearish Engulfing" : hammer ? "Hammer" : shooting_star ? "Shooting Star" : bullish_marubozu ? "Bullish Marubozu" : bearish_marubozu ? "Bearish Marubozu" : ""
//═══════════════════════════════════════════════════════════════════════════
// CANDLE PATTERN LABELS
//═══════════════════════════════════════════════════════════════════════════
if enable_candle_patterns and show_pattern_labels and barstate.isconfirmed
if bullish_engulfing and show_engulf_labels
style=label.style_label_up,
textcolor=color.white,
size=get_label_size(pattern_label_size),
tooltip="Bullish Engulfing\nStrong reversal signal")
if bearish_engulfing and show_engulf_labels
style=label.style_label_down,
textcolor=color.white,
size=get_label_size(pattern_label_size),
tooltip="Bearish Engulfing\nStrong reversal signal")
if hammer and show_hammer_labels
style=label.style_label_up,
textcolor=color.white,
size=get_label_size(pattern_label_size),
tooltip="Hammer\nBullish reversal at support")
if shooting_star and show_shoot_labels
style=label.style_label_down,
textcolor=color.white,
size=get_label_size(pattern_label_size),
tooltip="Shooting Star\nBearish reversal at resistance")
if bullish_marubozu and show_marubozu_labels
style=label.style_label_up,
textcolor=color.white,
size=get_label_size(pattern_label_size),
tooltip="Bullish Marubozu\nStrong continuation")
if bearish_marubozu and show_marubozu_labels
style=label.style_label_down,
textcolor=color.white,
size=get_label_size(pattern_label_size),
tooltip="Bearish Marubozu\nStrong continuation")
//═══════════════════════════════════════════════════════════════════════════
// DIAMOND ALIGNMENT CALCULATIONS
//═══════════════════════════════════════════════════════════════════════════
bool gauss_bull = gauss > gauss[1]
bool gauss_bear = gauss < gauss[1]
bool sr_bull = sr_d >= 50
bool sr_bear = sr_d < 50
bool tdfi_bull = tdfi > filterHigh
bool tdfi_bear = tdfi < filterLow
bool srsi_bull = rs > rs[1]
bool srsi_bear = rs < rs[1]
int bull_count = 0
int bear_count = 0
if gauss_bull
bull_count += 1
if sr_bull
bull_count += 1
if tdfi_bull
bull_count += 1
if srsi_bull
bull_count += 1
if gauss_bear
bear_count += 1
if sr_bear
bear_count += 1
if tdfi_bear
bear_count += 1
if srsi_bear
bear_count += 1
bool strong_bull_signal = bull_count == 4
bool strong_bear_signal = bear_count == 4
bool moderate_bull_signal = bull_count == 3 and bear_count < 3
bool moderate_bear_signal = bear_count == 3 and bull_count < 3
bool show_diamond_here = false
if show_all_diamonds
show_diamond_here := true
else
if show_mustang_diamonds and (mustang_buySignal or mustang_sellSignal or mustang_exitBuy or mustang_exitSell)
show_diamond_here := true
if show_frama_diamonds and (frama_buySignal or frama_sellSignal or frama_exitBuy or frama_exitSell)
show_diamond_here := true
float diamond_tick_offset = diamond_offset * syminfo.mintick
// Strong Bullish Diamond (4/4)
if enable_diamonds and show_diamond_symbols and show_diamond_here and strong_bull_signal and barstate.isconfirmed
string diamond_symbol = strong_bull_shape == "diamond" ? "◆" : strong_bull_shape == "circle" ? "●" : strong_bull_shape == "square" ? "■" : strong_bull_shape == "triangleup" ? "▲" : strong_bull_shape == "cross" ? "+" : "✖"
style=label.style_label_center,
size=get_label_size(strong_bull_size),
yloc=yloc.price,
tooltip="Strong Bullish (4/4)\nAll indicators aligned")
// Strong Bearish Diamond (4/4)
if enable_diamonds and show_diamond_symbols and show_diamond_here and strong_bear_signal and barstate.isconfirmed
string diamond_symbol = strong_bear_shape == "diamond" ? "◆" : strong_bear_shape == "circle" ? "●" : strong_bear_shape == "square" ? "■" : strong_bear_shape == "triangledown" ? "▼" : strong_bear_shape == "cross" ? "+" : "✖"
style=label.style_label_center,
size=get_label_size(strong_bear_size),
yloc=yloc.price,
tooltip="Strong Bearish (4/4)\nAll indicators aligned")
// Moderate Bullish Diamond (3/4)
if enable_diamonds and show_diamond_symbols and show_diamond_here and moderate_bull_signal and barstate.isconfirmed
string diamond_symbol = moderate_bull_shape == "diamond" ? "◆" : moderate_bull_shape == "circle" ? "●" : moderate_bull_shape == "square" ? "■" : moderate_bull_shape == "triangleup" ? "▲" : moderate_bull_shape == "cross" ? "+" : "✖"
style=label.style_label_center,
size=get_label_size(moderate_bull_size),
yloc=yloc.price,
tooltip="Moderate Bullish (3/4)\n3 indicators aligned")
// Moderate Bearish Diamond (3/4)
if enable_diamonds and show_diamond_symbols and show_diamond_here and moderate_bear_signal and barstate.isconfirmed
string diamond_symbol = moderate_bear_shape == "diamond" ? "◆" : moderate_bear_shape == "circle" ? "●" : moderate_bear_shape == "square" ? "■" : moderate_bear_shape == "triangledown" ? "▼" : moderate_bear_shape == "cross" ? "+" : "✖"
style=label.style_label_center,
size=get_label_size(moderate_bear_size),
yloc=yloc.price,
tooltip="Moderate Bearish (3/4)\n3 indicators aligned")
//═══════════════════════════════════════════════════════════════════════════
// QUANTIFICATION SYSTEM CALCULATIONS
//═══════════════════════════════════════════════════════════════════════════
int t1 = 0
int t2 = 0
int t3 = 0
// Tier 1: Mustang and FRAMA positions (+25/-25 points)
if enable_tier1
if in_buy_position
t1 += 25
if in_sell_position
t1 -= 25
if in_frama_buy
t1 += 25
if in_frama_sell
t1 -= 25
// Tier 2: Gaussian and SR Line (+10/-10 points)
if enable_tier2
if enable_gaussian_scoring
if gauss_bull
t2 += 10
if gauss_bear
t2 -= 10
if enable_sr_scoring
if sr_bull
t2 += 10
if sr_bear
t2 -= 10
// Tier 3: SRSI and TDFI (+5/-5 points with grey penalty)
if enable_tier3
if enable_srsi_scoring
if srsi_bull
t3 += 5
if srsi_bear
t3 -= 5
if enable_tdfi_scoring
bool tdfi_is_grey = not tdfi_bull and not tdfi_bear
if tdfi_bull
t3 += 5
else if tdfi_bear
t3 -= 5
// Candle Pattern Bonus/Penalty
if enable_candle_patterns and enable_tier3
int current_score = t1 + t2 + t3
if bullish_pattern and barstate.isconfirmed
if current_score > 15
t3 += candle_confirmation_bonus
else if current_score < -30
t3 += candle_contradiction_penalty * 2
else if current_score < 0
t3 += candle_confirmation_bonus
if bearish_pattern and barstate.isconfirmed
if current_score < -15
t3 -= candle_confirmation_bonus
else if current_score > 30
t3 -= candle_contradiction_penalty * 2
else if current_score > 0
t3 -= candle_confirmation_bonus
// Deceptive penalty (reduces confidence toward neutral on BOTH sides)
if enable_deceptive_scoring and (bullDec or bearDec)
int score_direction = t1 + t2 + t3
if score_direction > 0
t3 -= 10 // Reduce bullish confidence
else if score_direction < 0
t3 += 10 // Reduce bearish confidence (move toward zero)
int totSc = t1 + t2 + t3
string grd = "0"
color grd_col = neutral_col
color grd_text_col = color.white
if totSc >= 75
grd := "3+"
grd_col := buy_3p
grd_text_col := buy_text_col
else if totSc >= 60
grd := "3"
grd_col := buy_3
grd_text_col := buy_text_col
else if totSc >= 45
grd := "2+"
grd_col := buy_2p
grd_text_col := buy_text_col
else if totSc >= 30
grd := "2"
grd_col := buy_2
grd_text_col := buy_text_col
else if totSc >= 15
grd := "1"
grd_col := buy_1
grd_text_col := buy_text_col
else if totSc <= -75
grd := "3+"
grd_col := sell_3p
grd_text_col := sell_text_col
else if totSc <= -60
grd := "3"
grd_col := sell_3
grd_text_col := sell_text_col
else if totSc <= -45
grd := "2+"
grd_col := sell_2p
grd_text_col := sell_text_col
else if totSc <= -30
grd := "2"
grd_col := sell_2
grd_text_col := sell_text_col
else if totSc <= -15
grd := "1"
grd_col := sell_1
grd_text_col := sell_text_col
bool show_this_grade = false
if grd == "3+" and show_grade_3plus
show_this_grade := true
else if grd == "3" and show_grade_3
show_this_grade := true
else if grd == "2+" and show_grade_2plus
show_this_grade := true
else if grd == "2" and show_grade_2
show_this_grade := true
else if grd == "1" and show_grade_1
show_this_grade := true
else if grd == "0" and show_grade_0
show_this_grade := true
// Place grade number inside candle body
// Position: lower third of candle, slightly to the right
if enable_quant and show_grade_labels and show_this_grade and barstate.isconfirmed
float candle_body_top = math.max(open, close)
float candle_body_bottom = math.min(open, close)
float candle_body_height = candle_body_top - candle_body_bottom
// Position in lower third (1/3 from bottom to center)
float label_y_position = candle_body_bottom + (candle_body_height * 0.17)
style=label.style_label_center,
textcolor=grd_text_col,
size=get_label_size(grade_text_size),
yloc=yloc.price,
tooltip="Score: " + str.tostring(totSc) + "\nT1: " + str.tostring(t1) + " | T2: " + str.tostring(t2) + " | T3: " + str.tostring(t3))
//═══════════════════════════════════════════════════════════════════════════
// LABELS
//═══════════════════════════════════════════════════════════════════════════
mustang_label_size = get_label_size(mustang_size)
mustang_tick_offset = mustang_offset * syminfo.mintick
if mustang_buySignal and show_mustang_symbols
style = label.style_label_up, color = mustang_buy_color, textcolor = color.white,
size = mustang_label_size, yloc = yloc.price,
tooltip = "Mustang BUY\nAndean + EMAs + Stoch Confirmed")
if mustang_sellSignal and show_mustang_symbols
style = label.style_label_down, color = mustang_sell_color, textcolor = color.white,
size = mustang_label_size, yloc = yloc.price,
tooltip = "Mustang SELL\nAndean + EMAs + Stoch Confirmed")
if mustang_exitBuy and show_mustang_symbols
style = label.style_label_up, color = mustang_buy_color, textcolor = color.red,
size = mustang_label_size, yloc = yloc.price, tooltip = "Mustang Exit Buy")
if mustang_exitSell and show_mustang_symbols
style = label.style_label_down, color = mustang_sell_color, textcolor = color.white,
size = mustang_label_size, yloc = yloc.price, tooltip = "Mustang Exit Sell")
atr_for_sl = ta.atr(stop_loss_atr_length)
sl_value = atr_for_sl * stop_loss_atr_multiplier
frama_label_size = get_label_size(frama_triangle_size)
frama_tick_offset = frama_offset * syminfo.mintick
if frama_buySignal and show_frama_symbols
style = label.style_label_center, textcolor = frama_buy_color,
tooltip = "FRAMA BUY\n60% Breach Above Upper Band")
if frama_sellSignal and show_frama_symbols
style = label.style_label_center, textcolor = frama_sell_color,
tooltip = "FRAMA SELL\n60% Breach Below Lower Band")
if frama_exitBuy and show_frama_symbols
float exit_buy_position = bodyBot_frama - frama_tick_offset
style = label.style_label_center, textcolor = color.white,
style = label.style_label_center, textcolor = color.red,
tooltip = "FRAMA Exit Buy\nPrice back below upper band")
if frama_exitSell and show_frama_symbols
float exit_sell_position = bodyTop_frama + frama_tick_offset
style = label.style_label_center, textcolor = color.white,
style = label.style_label_center, textcolor = color.red,
tooltip = "FRAMA Exit Sell\nPrice back above lower band")
//═══════════════════════════════════════════════════════════════════════════
// ALERTS
//═══════════════════════════════════════════════════════════════════════════
if enable_mustang_audio
if mustang_buySignal
alert("🐎 MUSTANG BUY at " + str.tostring(close), alert.freq_once_per_bar)
if mustang_sellSignal
alert("🐎 MUSTANG SELL at " + str.tostring(close), alert.freq_once_per_bar)
if mustang_exitBuy
alert("EXIT BUY at " + str.tostring(close), alert.freq_once_per_bar)
if mustang_exitSell
alert("EXIT SELL at " + str.tostring(close), alert.freq_once_per_bar)
if enable_frama_audio
if frama_buySignal
alert("📊 FRAMA BUY at " + str.tostring(close), alert.freq_once_per_bar)
if frama_sellSignal
alert("📊 FRAMA SELL at " + str.tostring(close), alert.freq_once_per_bar)
if frama_exitBuy
alert("📊 FRAMA EXIT BUY at " + str.tostring(close), alert.freq_once_per_bar)
if frama_exitSell
alert("📊 FRAMA EXIT SELL at " + str.tostring(close), alert.freq_once_per_bar)
alertcondition(mustang_buySignal, title="🐎 Mustang BUY",
message='🐎 MUSTANG BUY\nSymbol: {{ticker}}\nTime: {{timenow}}\nPrice: {{close}}')
alertcondition(mustang_sellSignal, title="🐎 Mustang SELL",
message='🐎 MUSTANG SELL\nSymbol: {{ticker}}\nTime: {{timenow}}\nPrice: {{close}}')
alertcondition(frama_buySignal, title="📊 FRAMA BUY",
message='📊 FRAMA BUY\nSymbol: {{ticker}}\nTime: {{timenow}}\nPrice: {{close}}')
alertcondition(frama_sellSignal, title="📊 FRAMA SELL",
message='📊 FRAMA SELL\nSymbol: {{ticker}}\nTime: {{timenow}}\nPrice: {{close}}')
alertcondition(mustang_exitBuy, title="🚪 EXIT BUY",
message='🚪 EXIT BUY\nSymbol: {{ticker}}\nTime: {{timenow}}\nPrice: {{close}}')
alertcondition(mustang_exitSell, title="🚪 EXIT SELL",
message='🚪 EXIT SELL\nSymbol: {{ticker}}\nTime: {{timenow}}\nPrice: {{close}}')
alertcondition(enable_diamonds and strong_bull_signal, title="💎 Strong Bullish",
message='💎 STRONG BULLISH (4/4)\nSymbol: {{ticker}}\nTime: {{timenow}}\nPrice: {{close}}')
alertcondition(enable_diamonds and strong_bear_signal, title="💎 Strong Bearish",
message='💎 STRONG BEARISH (4/4)\nSymbol: {{ticker}}\nTime: {{timenow}}\nPrice: {{close}}')
//═══════════════════════════════════════════════════════════════════════════
// DATA WINDOW OUTPUT
//═══════════════════════════════════════════════════════════════════════════
// CMO calculated standalone — not from VIDYA function
cmo_mom = math.max(1, math.min(vidyaMomentum, bar_index + 1))
float cmo_sumPos = 0.0
float cmo_sumNeg = 0.0
for k = 0 to cmo_mom - 1
float d = nz(close[k]) - nz(close[k + 1])
if d >= 0
cmo_sumPos += d
else
cmo_sumNeg += -d
cmo_denom = cmo_sumPos + cmo_sumNeg
float cmo_value = cmo_denom != 0 ? math.abs(100 * (cmo_sumPos - cmo_sumNeg) / cmo_denom) : 0
// CMO Label — green under bullish candles, red above bearish candles
if barstate.isconfirmed and cmo_value > 50
float cmo_tick_offset = cmo_label_offset * syminfo.mintick
string cmo_text = "● CMO " + str.tostring(math.round(cmo_value))
if totSc > 0
style=label.style_label_up,
textcolor=color.green,
size=size.small,
yloc=yloc.price,
tooltip="CMO: " + str.tostring(math.round(cmo_value)) + "\nTrending Market\nQ Score: " + str.tostring(totSc))
else if totSc < 0
style=label.style_label_down,
textcolor=color.red,
size=size.small,
yloc=yloc.price,
tooltip="CMO: " + str.tostring(math.round(cmo_value)) + "\nTrending Market\nQ Score: " + str.tostring(totSc))
plot(enable_quant ? totSc : na, "Q Score", display=display.data_window)
plot(enable_quant ? t1 : na, "T1", display=display.data_window)
plot(enable_quant ? t2 : na, "T2", display=display.data_window)
plot(enable_quant ? t3 : na, "T3", display=display.data_window)
//═══════════════════════════════════════════════════════════════════════════
// TABLES
//═══════════════════════════════════════════════════════════════════════════
var table sl_table = table.new(position.top_right, 2, 1, bgcolor=color.new(color.black, 85), border_width=2)
if barstate.islast and enable_stop_loss
table.cell(sl_table, 0, 0, "SL:", text_color=color.white, text_size=size.normal)
table.cell(sl_table, 1, 0, str.tostring(sl_value, format.mintick), text_color=color.red, text_size=size.large, bgcolor=color.new(color.maroon, 85))
var table status_table = table.new(position.bottom_left, 4, 14, bgcolor=color.new(color.black, 90), border_width=1)
if barstate.islast
table.cell(status_table, 0, 0, "SYSTEM", text_color=color.yellow, text_size=size.small, bgcolor=color.new(color.black, 85))
table.cell(status_table, 1, 0, "MUSTANG", text_color=color.lime, text_size=size.tiny, bgcolor=color.new(color.black, 85))
table.cell(status_table, 2, 0, "FRAMA", text_color=color.aqua, text_size=size.tiny, bgcolor=color.new(color.black, 85))
table.cell(status_table, 3, 0, "SRSI", text_color=color.fuchsia, text_size=size.tiny, bgcolor=color.new(color.black, 85))
table.cell(status_table, 0, 1, "Position", text_color=color.white, text_size=size.tiny)
string mustang_pos = in_buy_position ? "BUY" : in_sell_position ? "SELL" : "None"
color mustang_pos_color = in_buy_position ? color.green : in_sell_position ? color.red : color.gray
table.cell(status_table, 1, 1, mustang_pos, text_color=mustang_pos_color, text_size=size.tiny)
string frama_pos = in_frama_buy ? "BUY" : in_frama_sell ? "SELL" : "None"
color frama_pos_color = in_frama_buy ? color.green : in_frama_sell ? color.red : color.gray
table.cell(status_table, 2, 1, frama_pos, text_color=frama_pos_color, text_size=size.tiny)
table.cell(status_table, 3, 1, str.tostring(math.round(rs, 1)), text_color=srsi_col, text_size=size.tiny)
table.cell(status_table, 0, 2, "Andean", text_color=color.white, text_size=size.tiny)
string andean_status = andean_buy_ready ? "BUY ✓" : andean_sell_ready ? "SELL ✓" : "Wait"
color andean_color = andean_buy_ready ? color.lime : andean_sell_ready ? color.orange : color.gray
table.cell(status_table, 1, 2, andean_status, text_color=andean_color, text_size=size.tiny)
table.cell(status_table, 2, 2, "-", text_color=color.gray, text_size=size.tiny)
table.cell(status_table, 3, 2, rs > rs[1] ? "UP" : "DN", text_color=srsi_col, text_size=size.tiny)
table.cell(status_table, 0, 3, "EMAs", text_color=color.white, text_size=size.tiny)
string ema_status = all_emas_green ? "GREEN" : all_emas_red ? "RED" : "Mix"
color ema_color = all_emas_green ? color.green : all_emas_red ? color.red : color.yellow
table.cell(status_table, 1, 3, ema_status, text_color=ema_color, text_size=size.tiny)
table.cell(status_table, 2, 3, "-", text_color=color.gray, text_size=size.tiny)
table.cell(status_table, 3, 3, "-", text_color=color.gray, text_size=size.tiny)
table.cell(status_table, 0, 4, "Breach", text_color=color.white, text_size=size.tiny)
table.cell(status_table, 1, 4, "-", text_color=color.gray, text_size=size.tiny)
string breach_status = pctA >= breach_pct ? str.tostring(math.round(pctA)) + "%" : pctB >= breach_pct ? str.tostring(math.round(pctB)) + "%" : "-"
color breach_color = pctA >= breach_pct ? color.green : pctB >= breach_pct ? color.red : color.gray
table.cell(status_table, 2, 4, breach_status, text_color=breach_color, text_size=size.tiny)
table.cell(status_table, 3, 4, "-", text_color=color.gray, text_size=size.tiny)
table.cell(status_table, 0, 5, "Range", text_color=color.white, text_size=size.tiny)
table.cell(status_table, 1, 5, "-", text_color=color.gray, text_size=size.tiny)
color range_color = rangeOsc >= rangeBuyLvl ? color.green : rangeOsc <= rangeSellLvl ? color.red : color.yellow
table.cell(status_table, 2, 5, str.tostring(math.round(rangeOsc)), text_color=range_color, text_size=size.tiny)
table.cell(status_table, 3, 5, "-", text_color=color.gray, text_size=size.tiny)
table.cell(status_table, 0, 6, "Gauss", text_color=color.white, text_size=size.tiny)
table.cell(status_table, 1, 6, "-", text_color=color.gray, text_size=size.tiny)
color gauss_color = gauss > gauss[1] ? color.green : color.red
table.cell(status_table, 2, 6, gauss > gauss[1] ? "UP" : "DN", text_color=gauss_color, text_size=size.tiny)
table.cell(status_table, 3, 6, "-", text_color=color.gray, text_size=size.tiny)
table.cell(status_table, 0, 7, "SR Line", text_color=color.white, text_size=size.tiny)
table.cell(status_table, 1, 7, "-", text_color=color.gray, text_size=size.tiny)
color sr_color = sr_d >= 50 ? color.green : color.red
table.cell(status_table, 2, 7, str.tostring(math.round(sr_d)), text_color=sr_color, text_size=size.tiny)
table.cell(status_table, 3, 7, "-", text_color=color.gray, text_size=size.tiny)
table.cell(status_table, 0, 8, "TDFI", text_color=color.white, text_size=size.tiny)
table.cell(status_table, 1, 8, "-", text_color=color.gray, text_size=size.tiny)
color tdfi_display_color = tdfi > filterHigh ? color.green : tdfi < filterLow ? color.red : color.gray
table.cell(status_table, 2, 8, str.tostring(math.round(tdfi, 3)), text_color=tdfi_display_color, text_size=size.tiny)
table.cell(status_table, 3, 8, "-", text_color=color.gray, text_size=size.tiny)
table.cell(status_table, 0, 9, "Pattern", text_color=color.white, text_size=size.tiny)
string pattern_display = bullish_pattern ? "🟢" : bearish_pattern ? "🔴" : "-"
color pattern_color = bullish_pattern ? color.green : bearish_pattern ? color.red : color.gray
table.cell(status_table, 1, 9, pattern_display, text_color=pattern_color, text_size=size.tiny)
table.cell(status_table, 2, 9, enable_candle_patterns ? "ON" : "OFF", text_color=enable_candle_patterns ? color.yellow : color.gray, text_size=size.tiny)
table.cell(status_table, 3, 9, pattern_name != "" ? pattern_name : "-", text_color=color.gray, text_size=size.tiny)
table.cell(status_table, 0, 10, "Diamond", text_color=color.white, text_size=size.tiny)
string diamond_status = strong_bull_signal ? "4/4 Bull" : strong_bear_signal ? "4/4 Bear" : moderate_bull_signal ? "3/4 Bull" : moderate_bear_signal ? "3/4 Bear" : "Mixed"
color diamond_color = strong_bull_signal ? color.lime : strong_bear_signal ? color.red : moderate_bull_signal ? color.blue : moderate_bear_signal ? color.fuchsia : color.gray
table.cell(status_table, 1, 10, diamond_status, text_color=diamond_color, text_size=size.tiny)
table.cell(status_table, 2, 10, str.tostring(bull_count) + "/" + str.tostring(bear_count), text_color=color.gray, text_size=size.tiny)
table.cell(status_table, 3, 10, enable_diamonds ? "ON" : "OFF", text_color=enable_diamonds ? color.yellow : color.gray, text_size=size.tiny)
table.cell(status_table, 0, 11, "Status", text_color=color.white, text_size=size.tiny)
table.cell(status_table, 1, 11, enable_mustang ? "ON" : "OFF", text_color=enable_mustang ? color.lime : color.gray, text_size=size.tiny)
table.cell(status_table, 2, 11, enable_frama ? "ON" : "OFF", text_color=enable_frama ? color.aqua : color.gray, text_size=size.tiny)
table.cell(status_table, 3, 11, enable_sentimental_rsi ? "ON" : "OFF", text_color=enable_sentimental_rsi ? color.fuchsia : color.gray, text_size=size.tiny)
table.cell(status_table, 0, 12, "Quant", text_color=color.white, text_size=size.tiny)
color grade_color = totSc > 0 ? color.green : totSc < 0 ? color.red : color.gray
table.cell(status_table, 1, 12, grd, text_color=grade_color, text_size=size.tiny)
table.cell(status_table, 2, 12, str.tostring(totSc), text_color=grade_color, text_size=size.tiny)
string tier_breakdown = str.tostring(t1) + "|" + str.tostring(t2) + "|" + str.tostring(t3)
if bullDec or bearDec
tier_breakdown += " 🟡"
table.cell(status_table, 3, 12, tier_breakdown, text_color=color.gray, text_size=size.tiny)
table.cell(status_table, 0, 13, "Gulshan Khera, CFP®", text_color=color.aqua, text_size=size.tiny)
table.cell(status_table, 1, 13, "INDIAN-SHARE-TIPS.COM", text_color=color.aqua, text_size=size.tiny)
table.cell(status_table, 2, 13, "+ SRSI + 💎", text_color=color.fuchsia, text_size=size.tiny)
table.cell(status_table, 3, 13, "+ 🔢 + 🕯️", text_color=color.yellow, text_size=size.tiny)
