Sniper Algo
Sniper Algo
Sniper Algo
// Trend band
showBand = input(true, title="", inline="band")
bandColorPos = input(color.green, title="Band colors", inline="band")
bandColorNeg = input(color.red, title="", inline="band")
emaLength1 = 8
emaLength2 = 13
emaLength3 = 21
emaLength4 = 55
// plot(tema1, color=color.orange)
maPlot1 = plot(ema3, color=color.green, display=display.none, editable=false)
maPlot2 = plot(ema4, color=color.red, linewidth=3, display=display.none,
editable=false)
//plot(ema, color=color.blue)
// Pivot points
pivotHigh = fixnan(pivothigh(10, 3))
pivotLow = fixnan(pivotlow(10, 3))
// Entry logic
pos = 0
tpTracker1 = 0
tpTracker2 = 0
tpTracker3 = 0
tpTracker4 = 0
tpTracker5 = 0
// Entry conditions
longCond = array.min(arrMa) == ema4
shortCond = array.max(arrMa) == ema4
// Entry signals
entryLong = longCond and not longCond[1] and pos[1] != 1
entryShort = shortCond and not shortCond[1] and pos[1] != -1
// Entry values
entryValueLong = valuewhen(entryLong, close, 0)
entryValueShort = valuewhen(entryShort, close, 0)
// Stop-loss calculations
slValueOriginalLong = valuewhen(entryLong, valuewhen(close < array.min(arrMa),
close, 0), 0)
slValueLong = slValueOriginalLong
slDistLong = valuewhen(entryLong, entryValueLong - slValueLong, 0)
if tpTracker1[1] == 1
slValueLong := entryValueLong
if tpTracker1[1] == 1
slValueShort := entryValueShort
// Position redefining
pos := entryLong ? 1 : entryShort ? -1 : tpLong5 or tpShort5 or slLong or slShort ?
0 : nz(pos[1])
// Alerts
alertcondition(entryLong, title="Buy signal")
alertcondition(entryShort, title="Sell signal")
alertcondition(tpLong1 or tpLong2 or tpLong3 or tpLong4 or tpLong5, title="Buy any
take profit signal")
alertcondition(tpShort1 or tpShort2 or tpShort3 or tpShort4 or tpShort5,
title="Sell any take profit signal")
alertcondition(slLong, title="Buy stop-loss")
alertcondition(slShort, title="Sell stop-loss")
// Labels
label entryLabel = na
label slLabel = na
label tpLabel1 = na
label tpLabel2 = na
label tpLabel3 = na
label tpLabel4 = na
label tpLabel5 = na
line entryLine = na
line slLine = na
line tpLine1 = na
line tpLine2 = na
line tpLine3 = na
line tpLine4 = na
line tpLine5 = na
if pos == 1
entryLabel := label.new(bar_index + 10, entryValueLong,
style=label.style_label_left, color=color.gray,
textcolor=color.white, text="Entry: " +
tostring(round_to_mintick(entryValueLong)))
if pos == -1
entryLabel := label.new(bar_index + 10, entryValueShort,
style=label.style_label_left, color=color.gray,
textcolor=color.white, text="Entry: " +
tostring(round_to_mintick(entryValueShort)))
label.delete(entryLabel[1])
label.delete(slLabel[1])
label.delete(tpLabel1[1])
label.delete(tpLabel2[1])
label.delete(tpLabel3[1])
label.delete(tpLabel4[1])
label.delete(tpLabel5[1])
line.delete(entryLine[1])
line.delete(slLine[1])
line.delete(tpLine1[1])
line.delete(tpLine2[1])
line.delete(tpLine3[1])
line.delete(tpLine4[1])
line.delete(tpLine5[1])
// Security function
secSMA(_res) =>
security(syminfo.tickerid, (showDashboard ? _res : timeframe.period),
sma(ohlc4, 200) < close, lookahead=barmerge.lookahead_on)
//}
// 2. 15min
trend15min = secSMA(showDashboard ? '15' : '15') ? 'Bullish 🟢' : 'Bearish 🔴'
// 3. 1hr
trend1hr = secSMA(showDashboard ? '60' : '15') ? 'Bullish 🟢' : 'Bearish 🔴'
// 4. 4hr
trend4hr = secSMA(showDashboard ? '240' : '15') ? 'Bullish 🟢' : 'Bearish 🔴'
// 5. 1D
trend1d = secSMA(showDashboard ? '1D' : '15') ? 'Bullish 🟢' : 'Bearish 🔴'
// 2. 3min
trend3min = secSMA(advDash and showDashboard ? '3' : '15') ? 'Bullish 🟢' : 'Bearish
🔴'
// 3. 5min
trend5min = secSMA(advDash and showDashboard ? '5' : '15') ? 'Bullish 🟢' : 'Bearish
🔴'
// 4. 10min
trend10min = secSMA(advDash and showDashboard ? '10' : '15') ? 'Bullish 🟢' :
'Bearish 🔴'
// 5. 30min
trend30min = secSMA(advDash and showDashboard ? '30' : '15') ? 'Bullish 🟢' :
'Bearish 🔴'
// 6. 2hr
trend12hr = secSMA(advDash and showDashboard ? '720' : '15') ? 'Bullish 🟢' :
'Bearish 🔴'
// 7. 12hr
trend2hr = secSMA(advDash and showDashboard ? '120' : '15') ? 'Bullish 🟢' :
'Bearish 🔴'
// Last signal
lastSignalInt = 0
lastSignalInt := entryLong ? 1 : entryShort ? -1 : nz(lastSignalInt[1])
lastSignal = lastSignalInt == 1 ? 'Buy 🟢' : 'Sell 🔴'
// RSI condition
rsiCond = rsiTrend < 30 ? 'Oversold (' + tostring(round(rsiTrend, 2)) + ') ⬆️' :
rsiTrend > 70 ? 'Overbought (' + tostring(round(rsiTrend, 2)) + ') ⬇️' :
'Healthy (' + tostring(round(rsiTrend, 2)) + ') ✅'
// ATR function
atrTrend = atr(14)
atrTrendCond = atrTrend > ema(sma(atrTrend, 100), 100) ? 'Trending 🚀' : 'Ranging
⚠️️'
label dashboard = na
if showDashboard
dashboard := label.new(x = time + btime * xDashBoard,
y = ((highest(20) + lowest(20)) / 2),
text = "𝐒𝐧𝐢𝐩𝐞𝐫 𝐀𝐥𝐠𝐨" +
"\n\nCurrent position: " + lastSignal +
"\nCurrent trend: " + trendCurrent +
"\nPrice condition: " + rsiCond +
"\nVolume: " + tostring(round(volume * close, 2)) + "
" + syminfo.currency +
"\nVolatility: " + atrTrendCond +
"\n\n---------------------------" +
"\nTimeframe trends 📊" +
(advDash ? "\n\n1min: " + trend1min : "") +
(advDash ? "\n3min: " + trend3min : "") +
(advDash ? "\n5min: " + trend5min : "") +
(advDash ? "\n10min: " + trend10min : "") +
"\n15min: " + trend15min +
(advDash ? "\n30min: " + trend30min : "") +
"\n1hr: " + trend1hr +
(advDash ? "\n2hr: " + trend2hr : "") +
"\n4hr: " + trend4hr +
(advDash ? "\n12hr: " + trend12hr : "") +
"\nDaily: " + trend1d,
color=#1E1E1E,
textcolor=#C0C0C0,
style=label.style_label_left,
xloc=xloc.bar_time,
yloc=yloc.price,
textalign=text.align_left)
label.delete(dashboard[1])