Qm
2025-02-09
Category: None

//@version=5
indicator(title='QM + RSI Strategy', shorttitle='QM-RSI', overlay=true)

// ————— تنظیمات RSI —————
rsi_length = input(14, title='RSI Length')
rsi_overbought = input(70, title='Overbought Level')
rsi_oversold = input(30, title='Oversold Level')
rsi = ta.rsi(close, rsi_length)

// ————— شناسایی الگوی QM —————
lookback = input(5, title='Swing Lookback Period')

// تشخیص سوینگ‌های بالا و پایین
swing_high = ta.pivothigh(lookback, lookback)
swing_low = ta.pivotlow(lookback, lookback)

// تشخیص ساختار QM (Higher High + Lower High)
qm_bearish = swing_high and high > high  and high  > high 
qm_bullish = swing_low and low < low  and low  < low 

// ————— واگرایی RSI —————
// واگرایی نزولی (Bearish Divergence)
bearish_div = ta.highest(rsi, lookback) == rsi  and high > high  and rsi < rsi 

// واگرایی صعودی (Bullish Divergence)
bullish_div = ta.lowest(rsi, lookback) == rsi  and low < low  and rsi > rsi 

// ————— سیگنال‌های ترکیبی —————
sell_signal = qm_bearish and bearish_div and rsi >= rsi_overbought
buy_signal = qm_bullish and bullish_div and rsi <= rsi_oversold

// ————— رسم علائم روی چارت —————
plotshape(series=sell_signal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title='Sell')
plotshape(series=buy_signal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title='Buy')

// ————— هشدارها —————
alertcondition(sell_signal, title='Bearish QM+RSI Signal', message='QM Bearish with RSI Divergence!')
alertcondition(buy_signal, title='Bullish QM+RSI Signal', message='QM Bullish with RSI Divergence!')

// ————— نمایش RSI —————
hline(rsi_overbought, color=color.gray, linestyle=hline.style_dotted)
hline(rsi_oversold, color=color.gray, linestyle=hline.style_dotted)