PHP Code:
//@version=6
indicator(title = 'Sniper Machine', shorttitle = 'Sniper Machine', overlay = true, max_boxes_count=50)
// UI Options for Auto Trend Detection and No Signal in Sideways Market
autoTrendDetection = input.bool(true, title = 'Auto Trend Detection')
noSignalSideways = input.bool(true, title = 'No Signal in Sideways Market')
// Color variables
upTrendColor = color.white
neutralColor = #90bff9
downTrendColor = color.blue
// Source
source = input(defval = close, title = 'Source')
// Sampling Period - Replaced with Sniper Machine
period = input.int(defval = 100, minval = 1, title = 'Sniper Machine Period')
// Trend Master - Replaced with Sniper Machine
multiplier = input.float(defval = 3.0, minval = 0.1, title = 'Sniper Machine Multiplier')
// Smooth Average Range
smoothRange(x, t, m) =>
adjustedPeriod = t * 2 - 1
avgRange = ta.ema(math.abs(x - x[1]), t)
smoothRange = ta.ema(avgRange, adjustedPeriod) * m
smoothRange
smoothedRange = smoothRange(source, period, multiplier)
// Trend Filter
trendFilter(x, r) =>
filtered = x
filtered := x > nz(filtered[1]) ? x - r < nz(filtered[1]) ? nz(filtered[1]) : x - r : x + r > nz(filtered[1]) ? nz(filtered[1]) : x + r
filtered
filter = trendFilter(source, smoothedRange)
// Filter Direction
upCount = 0.0
upCount := filter > filter[1] ? nz(upCount[1]) + 1 : filter < filter[1] ? 0 : nz(upCount[1])
downCount = 0.0
downCount := filter < filter[1] ? nz(downCount[1]) + 1 : filter > filter[1] ? 0 : nz(downCount[1])
// Colors
filterColor = upCount > 0 ? upTrendColor : downCount > 0 ? downTrendColor : neutralColor
// Buy/Sell Signals - Adapted from Clear Trend Logic
trendUp = upCount > 0 // Equivalent to REMA_up in Clear Trend
newBuySignal = trendUp and not trendUp[1] and barstate.isconfirmed
newSellSignal = not trendUp and trendUp[1] and barstate.isconfirmed
initialCondition = 0
initialCondition := newBuySignal ? 1 : newSellSignal ? -1 : initialCondition[1]
longSignal = newBuySignal and initialCondition[1] == -1
shortSignal = newSellSignal and initialCondition[1] == 1
// Alerts and Signals
plotshape(longSignal, title = 'Buy Signal', text = '🚀', textcolor = #000000, style = shape.labelup, size = size.small, location = location.belowbar, color = #fae10400) // Bright yellow for Buy
plotshape(shortSignal, title = 'Sell Signal', text = '🚨', textcolor = #000000, style = shape.labeldown, size = size.small, location = location.abovebar, color = #fb020200) // Bright red for Sell
alertcondition(longSignal, title = 'Buy alert on Sniper Machine', message = 'Buy alert on Sniper Machine')
alertcondition(shortSignal, title = 'Sell alert on Sniper Machine', message = 'Sell alert on Sniper Machine')
///////////////
// Inputs
src = input.source(hlc3, "Source")
emaLen = input.int(1, "Center EMA")
spreadN = input.int(100, "Spread Length")
kMult = input.float(3.0, "Multiplier", step=0.1)
upCol = input.color(color.rgb(251, 5, 5), "Up Color")
dnCol = input.color(color.rgb(26,221,127), "Down Color")
// Core calculation
mid = ta.ema(src, emaLen)
spread = ta.sma(high - low, spreadN)
uBand = mid + kMult * spread
lBand = mid - kMult * spread
// Crawl bands
var float upC = na
var float dnC = na
upC := na(upC[1]) ? uBand : (src[1] > upC[1] ? uBand : math.min(uBand, upC[1]))
dnC := na(dnC[1]) ? lBand : (src[1] < dnC[1] ? lBand : math.max(lBand, dnC[1]))
// Direction & guide
var int dir = na
var float guide = na
if na(dir[1])
dir := 1
else
dir := guide[1] == upC[1] ? (src > upC ? -1 : 1) : (src < dnC ? 1 : -1)
guide := dir == 1 ? upC : dnC
// Background zone fill
bgcolor(dir==1 ? color.new(upCol, 85) : color.new(dnCol, 85), title="Trend Zone")
// Guide line
plot(guide, "Trs", color=color.new(dir==1?upCol:dnCol, 0), linewidth=1)
// Signals
trendUpbn = not na(dir[1]) and dir == -1 and dir[1] != -1
trendDownbn = not na(dir[1]) and dir == 1 and dir[1] != 1
pbUp = dir==-1 and high >= upC
pbDown = dir==1 and low <= dnC
dist = 0.25 * spread
filteredPbUp = pbUp and (high - upC <= dist)
filteredPbDown = pbDown and (dnC - low <= dist)
firstPbUp = filteredPbUp and not filteredPbUp[1]
firstPbDown = filteredPbDown and not filteredPbDown[1]
// ATR for vertical spacing of signals
atrVal = ta.atr(14)
upY = low - 15 * atrVal
downY = high + 10 * atrVal
// Plot BUY/SELL arrows as labels for vertical spacing
//if trendUpbn
//label.new(bar_index, upY, text="BUY", style=label.style_triangleup, color=dnCol, textcolor=color.white, size=size.small, yloc=yloc.price)
//if trendDownbn
//label.new(bar_index, downY, text="SELL", style=label.style_triangledown, color=upCol, textcolor=color.white, size=size.small, yloc=yloc.price)
// Pullback dots
//plotshape(firstPbUp, style=shape.circle, location=location.belowbar, color=color.new(dnCol,0), size=size.small)
//plotshape(firstPbDown, style=shape.circle, location=location.abovebar, color=color.new(upCol,0), size=size.small)
//////////////////////
Yer İmleri