PHP Code:
// © Marcin Kukulski
//@version=6
indicator(title="Buy Sell Indicator PRO", overlay=true)
// Inputs
keyValue = input.float(1.0, title="Key Value (Sensitivity)", step=0.5)
atrPeriod = input.int(10, title="ATR Period")
emaPeriod = input.int(1, title="EMA Period (default 1)")
srLookback = input.int(20, title="Support/Resistance Lookback", minval=2)
// ATR Calculation
atrValue = ta.atr(atrPeriod)
nLoss = keyValue * atrValue
// Trailing Stop Logic
var float trailingStop = na
if (na(trailingStop))
trailingStop := close - nLoss
if (close > trailingStop and close[1] > trailingStop)
trailingStop := math.max(trailingStop, close - nLoss)
else if (close < trailingStop and close[1] < trailingStop)
trailingStop := math.min(trailingStop, close + nLoss)
else
trailingStop := close > trailingStop ? (close - nLoss) : (close + nLoss)
// Position tracking
var int pos = 0
if (close[1] < trailingStop and close > trailingStop)
pos := 1
else if (close[1] > trailingStop and close < trailingStop)
pos := -1
else
pos := pos[1]
// Color logic
trailColor = pos == -1 ? color.red : pos == 1 ? color.green : color.blue
// Plot trailing stop
plot(trailingStop, color=trailColor, title="Trailing Stop")
// Signal logic
emaLine = ta.ema(close, emaPeriod)
buySignal = ta.crossover(emaLine, trailingStop)
sellSignal = ta.crossunder(emaLine, trailingStop)
// Plot shapes
plotshape(buySignal, title="Buy", text='Buy', style=shape.labelup, location=location.belowbar, color=color.green, textcolor=color.white, size=size.small)
plotshape(sellSignal, title="Sell", text='Sell', style=shape.labeldown, location=location.abovebar, color=color.red, textcolor=color.white, size=size.small)
// Bar coloring
barCol = close > trailingStop ? color.green : color.red
barcolor(barCol)
// Alerts
alertcondition(buySignal, title="Buy Alert", message="Buy Signal!")
alertcondition(sellSignal, title="Sell Alert", message="Sell Signal!")
// === Support & Resistance ===
// Detecting swing highs and lows
isResistance = high == ta.highest(high, srLookback)
isSupport = low == ta.lowest(low, srLookback)
// Plotting lines
plotshape(isResistance, style=shape.triangledown, location=location.abovebar, color=color.orange, size=size.tiny, title="Resistance Marker")
plotshape(isSupport, style=shape.triangleup, location=location.belowbar, color=color.aqua, size=size.tiny, title="Support Marker")
// Draw horizontal lines (optional, limited by PineScript constraints)
var float resistanceLevel = na
var float supportLevel = na
if isResistance
resistanceLevel := high
if isSupport
supportLevel := low
plot(resistanceLevel, title="Resistance Level", color=color.orange, linewidth=1, style=plot.style_linebr)
plot(supportLevel, title="Support Level", color=color.aqua, linewidth=1, style=plot.style_linebr)
Yer İmleri