qqe setting thường 1/10

k reversal 6 12 20 100 1: có thể tuỳ chỉnh thêm// 6 12 20 150 1// 
K'REVERSAL:
 GHI CHÚ:
 S1 
S2
S3
S4 : XEM XÉT 100 150, CÓ TĂNG VÀ GIẢM LỆNH, CÀNG NHỎ TÍN HIỆU FAIL CÀNG LỚN, 
100 CŨNG TỐT 150 CŨNG ỔN
S5


//@version=5
indicator("Combined K's Reversal and QQE Signals", overlay=true)

// --- K's Reversal Indicator I Section ---
k_fast       = input(defval=12, title='K Fast')
k_slow       = input(defval=26, title='K Slow')
k_signal     = input(defval=9,  title='K Signal')
k_length     = input(defval=100, title='K Bollinger Lookback')
k_multiplier = input(defval=2,  title='K Multiplier')

k_macd_line   = ta.ema(close, k_fast) - ta.ema(close, k_slow)
k_signal_line = ta.ema(k_macd_line, k_signal)

k_lower_boll = ta.sma(close, k_length) - (k_multiplier * ta.stdev(close, k_length))
k_upper_boll = ta.sma(close, k_length) + (k_multiplier * ta.stdev(close, k_length))
k_mid_line   = ta.sma(close, k_length)

k_buy_signal  = math.min(open[1], close[1]) <= k_lower_boll[1] and math.max(open[1], close[1]) <= k_mid_line and k_macd_line[1] > k_signal_line[1] and k_macd_line[2] < k_signal_line[2]
k_sell_signal = math.max(open[1], close[1]) >= k_upper_boll[1] and math.min(open[1], close[1]) >= k_mid_line and k_macd_line[1] < k_signal_line[1] and k_macd_line[2] > k_signal_line[2]

plotshape(k_buy_signal,  style=shape.triangleup, color=color.green, location=location.belowbar, size=size.small, title="K Buy")
plotshape(k_sell_signal, style=shape.triangledown, color=color.red, location=location.abovebar, size=size.small, title="K Sell")

k_bar_size = timeframe.multiplier * (timeframe.isdaily ? 1440 : timeframe.isweekly ? 7*1440 : timeframe.ismonthly ? 30*1440 : 1) * 60*1000

if k_buy_signal
    line.new(time, low[1] - (high[1] - low[1]) * 2, time + k_bar_size * 20, low[1] - (high[1] - low[1]) * 2, xloc.bar_time, color=color.green, width=2)
    line.new(time, open, time + k_bar_size * 20, open, xloc.bar_time, color=color.blue, width=2)

if k_sell_signal
    line.new(time, high[1] + (high[1] - low[1]) * 2, time + k_bar_size * 20, high[1] + (high[1] - low[1]) * 2, xloc.bar_time, color=color.red, width=2)
    line.new(time, open, time + k_bar_size * 20, open, xloc.bar_time, color=color.blue, width=2)

// --- QQE Signals Section ---
qqe_RSI_Period = input(14, title='QQE RSI Length')
qqe_SF = input(5, title='QQE RSI Smoothing')
qqe_QQE = input(4.238, title='QQE Fast QQE Factor')
qqe_ThreshHold = input(10, title="QQE Thresh-hold")

qqe_src = close
qqe_Wilders_Period = qqe_RSI_Period * 2 - 1

qqe_Rsi = ta.rsi(qqe_src, qqe_RSI_Period)
qqe_RsiMa = ta.ema(qqe_Rsi, qqe_SF)
qqe_AtrRsi = math.abs(qqe_RsiMa[1] - qqe_RsiMa)
qqe_MaAtrRsi = ta.ema(qqe_AtrRsi, qqe_Wilders_Period)
qqe_dar = ta.ema(qqe_MaAtrRsi, qqe_Wilders_Period) * qqe_QQE

qqe_longband = 0.0
qqe_shortband = 0.0
qqe_trend = 0

qqe_DeltaFastAtrRsi = qqe_dar
qqe_RSIndex = qqe_RsiMa
qqe_newshortband = qqe_RSIndex + qqe_DeltaFastAtrRsi
qqe_newlongband = qqe_RSIndex - qqe_DeltaFastAtrRsi
qqe_longband := qqe_RSIndex[1] > qqe_longband[1] and qqe_RSIndex > qqe_longband[1] ? math.max(qqe_longband[1], qqe_newlongband) : qqe_newlongband
qqe_shortband := qqe_RSIndex[1] < qqe_shortband[1] and qqe_RSIndex < qqe_shortband[1] ? math.min(qqe_shortband[1], qqe_newshortband) : qqe_newshortband
qqe_cross_1 = ta.cross(qqe_longband[1], qqe_RSIndex)
qqe_trend := ta.cross(qqe_RSIndex, qqe_shortband[1]) ? 1 : qqe_cross_1 ? -1 : nz(qqe_trend[1], 1)
qqe_FastAtrRsiTL = qqe_trend == 1 ? qqe_longband : qqe_shortband

qqe_QQExlong = 0
qqe_QQExlong := nz(qqe_QQExlong[1])
qqe_QQExshort = 0
qqe_QQExshort := nz(qqe_QQExshort[1])
qqe_QQExlong := qqe_FastAtrRsiTL < qqe_RSIndex ? qqe_QQExlong + 1 : 0
qqe_QQExshort := qqe_FastAtrRsiTL > qqe_RSIndex ? qqe_QQExshort + 1 : 0

qqe_qqeLong = qqe_QQExlong == 1 ? qqe_FastAtrRsiTL[1] - 50 : na
qqe_qqeShort = qqe_QQExshort == 1 ? qqe_FastAtrRsiTL[1] - 50 : na

plotshape(qqe_qqeLong, title="QQE Long", text="Long", textcolor=color.white, style=shape.labelup, location=location.belowbar, color=color.green, transp=0, size=size.tiny)
plotshape(qqe_qqeShort, title="QQE Short", text="Short", textcolor=color.white, style=shape.labeldown, location=location.abovebar, color=color.red, transp=0, size=size.tiny)

alertcondition(qqe_qqeLong, title="QQE Long", message="QQE Long")
alertcondition(qqe_qqeShort, title="QQE Short", message="QQE Short")