PROTECTED SOURCE SCRIPT

3-in-1 Confluence Signal (by Gemini)

39
//version=5
indicator("Improved EMA Signal", overlay=true, max_lines_count=500, max_labels_count=500, max_boxes_count=500, format=format.price, precision=2)

// === Inputs ===
sensitivity = input.float(3, title="Sensitivity")
atrPeriod = input.int(2, title="ATR Period")
useHeikinAshi = input.bool(false, title="Use Heikin Ashi")

// === ATR Calculation ===
atr = ta.atr(atrPeriod)
nLoss = sensitivity * atr

// === Price Source (Heikin Ashi or Regular) ===
haSymbol = syminfo.tickerid + ".heikinashi"
priceSource = request.security(useHeikinAshi ? haSymbol : syminfo.tickerid, timeframe.period, close)

// === ATR Trailing Stop Logic ===
var float atrStop = 0.0
atrStop := if priceSource > nz(atrStop[1], 0) and priceSource[1] > nz(atrStop[1], 0)
math.max(nz(atrStop[1]), priceSource - nLoss)
else if priceSource < nz(atrStop[1], 0) and priceSource[1] < nz(atrStop[1], 0)
math.min(nz(atrStop[1]), priceSource + nLoss)
else
priceSource > nz(atrStop[1], 0) ? priceSource - nLoss : priceSource + nLoss

// === Position State ===
var int position = 0
position := if priceSource[1] < nz(atrStop[1], 0) and priceSource > nz(atrStop[1], 0)
1
else if priceSource[1] > nz(atrStop[1], 0) and priceSource < nz(atrStop[1], 0)
-1
else
nz(position[1], 0)

// === EMA of ATR Trail ===
atrEma = ta.ema(priceSource, 1)
crossAbove = ta.crossover(atrEma, atrStop)
crossBelow = ta.crossunder(atrEma, atrStop)

// === Filters for Signal Confirmation ===
// 1. Long-Term Trend Filter (using the existing EMA)
trendEmaLength = input.int(240, title="Trend EMA Length")
trendEma = ta.ema(close, trendEmaLength)
isUpTrend = close > trendEma // 장기 상승추세인가?
isDownTrend = close < trendEma // 장기 하락추세인가?

// 2. Market Energy Filter (using ADX to avoid sideways markets)
adxLength = input.int(14, "ADX Length")
adxThreshold = input.int(20, "ADX Threshold")
[diPlus, diMinus, adx] = ta.dmi(adxLength, adxLength)
isTrending = adx > adxThreshold // 시장이 추세적인가?

// === Improved Buy/Sell Signal Conditions ===
buySignal = priceSource > atrStop and crossAbove and isUpTrend and isTrending
sellSignal = priceSource < atrStop and crossBelow and isDownTrend and isTrending

// === Signal Visuals ===
plotshape(buySignal, title="Buy Signal", location=location.belowbar, style=shape.labelup, color=color.new(color.rgb(0, 255, 85), 0), text="Buy", textcolor=color.new(color.black, 0), size=size.small)
plotshape(sellSignal, title="Sell Signal", location=location.abovebar, style=shape.labeldown, color=color.new(color.rgb(255, 0, 64), 0), text="Sell", textcolor=color.new(color.black, 0), size=size.small)

// === Bar Coloring ===
barcolor(priceSource > atrStop ? color.new(color.green, 70) : color.new(color.red, 70))

// === Trend EMA Overlay ===
plot(trendEma, color=color.new(#fcfcfc, 40), linewidth=3, title="Trend EMA")

// === Alerts ===
alertcondition(buySignal, title="Buy Alert", message="Buy Signal!")
alertcondition(sellSignal, title="Sell Alert", message="Sell Signal!")

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.