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が提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、この作者はスクリプトのソースコードを公開しているので、その内容を理解し検証することができます。作者に感謝です!無料でお使いいただけますが、このコードを投稿に再利用する際にはハウスルールに従うものとします。
免責事項
これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。