OPEN-SOURCE SCRIPT
hidden buy or sell

//version=5
indicator(title="Institutional Flow & Trend", shorttitle="IF&T", overlay=true)
// --- INPUTS ---
// Trend EMA lengths
fast_ema_len = input.int(9, title="Fast EMA Length", minval=1)
slow_ema_len = input.int(21, title="Slow EMA Length", minval=1)
// OBV Moving Average length
obv_ema_len = input.int(10, title="OBV EMA Length", minval=1)
// RSI settings for hidden divergence (NEW)
rsi_len = input.int(14, title="RSI Length", minval=1)
// --- CALCULATIONS ---
// Calculate EMAs for trend
fast_ema = ta.ema(close, fast_ema_len)
slow_ema = ta.ema(close, slow_ema_len)
// Calculate On-Balance Volume and its moving average
obv_value = ta.obv
obv_ema = ta.ema(obv_value, obv_ema_len)
// Calculate RSI for divergence (NEW)
rsi_val = ta.rsi(close, rsi_len)
// --- HIDDEN DIVERGENCE LOGIC (NEW) ---
// Bullish hidden divergence: price makes a higher low, but RSI makes a lower low.
bullish_div = ta.lowest(low, 2)[1] > ta.lowest(low, 2) and rsi_val[1] > rsi_val
// Bearish hidden divergence: price makes a lower high, but RSI makes a higher high.
bearish_div = ta.highest(high, 2)[1] < ta.highest(high, 2) and rsi_val[1] < rsi_val
// --- SIGNAL LOGIC ---
// Bullish conditions:
// 1. Hidden bullish divergence is detected (NEW)
// 2. Fast EMA is above Slow EMA (uptrend)
// 3. OBV value is above its moving average (buying pressure)
bullish_signal = bullish_div and fast_ema > slow_ema and obv_value > obv_ema
// Bearish conditions:
// 1. Hidden bearish divergence is detected (NEW)
// 2. Fast EMA is below Slow EMA (downtrend)
// 3. OBV value is below its moving average (selling pressure)
bearish_signal = bearish_div and fast_ema < slow_ema and obv_value < obv_ema
// --- PLOTS & VISUALS ---
// Plot the EMAs on the chart
plot(fast_ema, title="Fast EMA", color=color.new(color.blue, 0), linewidth=2)
plot(slow_ema, title="Slow EMA", color=color.new(color.orange, 0), linewidth=2)
// Color the background based on signals
bgcolor(bullish_signal ? color.new(color.green, 90) : na, title="Bullish Zone")
bgcolor(bearish_signal ? color.new(color.red, 90) : na, title="Bearish Zone")
// Plot shapes for entry signals
plotshape(series=bullish_signal, title="Buy Signal", location=location.belowbar, color=color.new(color.green, 0), style=shape.triangleup, size=size.small)
plotshape(series=bearish_signal, title="Sell Signal", location=location.abovebar, color=color.new(color.red, 0), style=shape.triangledown, size=size.small)
// Plot shapes for divergence signals (NEW)
plotshape(series=bullish_div, title="Bullish Divergence", location=location.belowbar, color=color.new(color.lime, 0), style=shape.circle, size=size.tiny)
plotshape(series=bearish_div, title="Bearish Divergence", location=location.abovebar, color=color.new(color.red, 0), style=shape.circle, size=size.tiny)
// Alert conditions
alertcondition(bullish_signal, title="Bullish Reversal Signal", message="Institutional buying and trend aligned for a reversal!")
alertcondition(bearish_signal, title="Bearish Reversal Signal", message="Institutional selling and trend aligned for a reversal!")
// --- FOOTNOTE ---
// This indicator is a conceptual tool. Use it with other forms of analysis.
// Backtesting and optimization are crucial before live trading.
indicator(title="Institutional Flow & Trend", shorttitle="IF&T", overlay=true)
// --- INPUTS ---
// Trend EMA lengths
fast_ema_len = input.int(9, title="Fast EMA Length", minval=1)
slow_ema_len = input.int(21, title="Slow EMA Length", minval=1)
// OBV Moving Average length
obv_ema_len = input.int(10, title="OBV EMA Length", minval=1)
// RSI settings for hidden divergence (NEW)
rsi_len = input.int(14, title="RSI Length", minval=1)
// --- CALCULATIONS ---
// Calculate EMAs for trend
fast_ema = ta.ema(close, fast_ema_len)
slow_ema = ta.ema(close, slow_ema_len)
// Calculate On-Balance Volume and its moving average
obv_value = ta.obv
obv_ema = ta.ema(obv_value, obv_ema_len)
// Calculate RSI for divergence (NEW)
rsi_val = ta.rsi(close, rsi_len)
// --- HIDDEN DIVERGENCE LOGIC (NEW) ---
// Bullish hidden divergence: price makes a higher low, but RSI makes a lower low.
bullish_div = ta.lowest(low, 2)[1] > ta.lowest(low, 2) and rsi_val[1] > rsi_val
// Bearish hidden divergence: price makes a lower high, but RSI makes a higher high.
bearish_div = ta.highest(high, 2)[1] < ta.highest(high, 2) and rsi_val[1] < rsi_val
// --- SIGNAL LOGIC ---
// Bullish conditions:
// 1. Hidden bullish divergence is detected (NEW)
// 2. Fast EMA is above Slow EMA (uptrend)
// 3. OBV value is above its moving average (buying pressure)
bullish_signal = bullish_div and fast_ema > slow_ema and obv_value > obv_ema
// Bearish conditions:
// 1. Hidden bearish divergence is detected (NEW)
// 2. Fast EMA is below Slow EMA (downtrend)
// 3. OBV value is below its moving average (selling pressure)
bearish_signal = bearish_div and fast_ema < slow_ema and obv_value < obv_ema
// --- PLOTS & VISUALS ---
// Plot the EMAs on the chart
plot(fast_ema, title="Fast EMA", color=color.new(color.blue, 0), linewidth=2)
plot(slow_ema, title="Slow EMA", color=color.new(color.orange, 0), linewidth=2)
// Color the background based on signals
bgcolor(bullish_signal ? color.new(color.green, 90) : na, title="Bullish Zone")
bgcolor(bearish_signal ? color.new(color.red, 90) : na, title="Bearish Zone")
// Plot shapes for entry signals
plotshape(series=bullish_signal, title="Buy Signal", location=location.belowbar, color=color.new(color.green, 0), style=shape.triangleup, size=size.small)
plotshape(series=bearish_signal, title="Sell Signal", location=location.abovebar, color=color.new(color.red, 0), style=shape.triangledown, size=size.small)
// Plot shapes for divergence signals (NEW)
plotshape(series=bullish_div, title="Bullish Divergence", location=location.belowbar, color=color.new(color.lime, 0), style=shape.circle, size=size.tiny)
plotshape(series=bearish_div, title="Bearish Divergence", location=location.abovebar, color=color.new(color.red, 0), style=shape.circle, size=size.tiny)
// Alert conditions
alertcondition(bullish_signal, title="Bullish Reversal Signal", message="Institutional buying and trend aligned for a reversal!")
alertcondition(bearish_signal, title="Bearish Reversal Signal", message="Institutional selling and trend aligned for a reversal!")
// --- FOOTNOTE ---
// This indicator is a conceptual tool. Use it with other forms of analysis.
// Backtesting and optimization are crucial before live trading.
Script de código abierto
Siguiendo fielmente el espíritu de TradingView, el creador de este script lo ha publicado en código abierto, permitiendo que otros traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la publicación de este código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.
Script de código abierto
Siguiendo fielmente el espíritu de TradingView, el creador de este script lo ha publicado en código abierto, permitiendo que otros traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la publicación de este código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.