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.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.