generated from kaleem736/smart_ema_candle_sniper_mt5
260 lines
No EOL
36 KiB
Text
260 lines
No EOL
36 KiB
Text
//@version=6
|
|
indicator("Smart EMA Candle Sniper v1", overlay=true, max_lines_count=500, max_labels_count=500)
|
|
|
|
//=========================
|
|
// Inputs
|
|
//=========================
|
|
fastEMA = input.int(20, "EMA Fast")
|
|
midEMA = input.int(50, "EMA Mid")
|
|
slowEMA = input.int(200, "EMA Slow")
|
|
rsiPeriod = input.int(14, "RSI Period")
|
|
atrPeriod = input.int(14, "ATR Period")
|
|
|
|
rsiBuyLvl = input.float(50.0, "RSI Buy Level")
|
|
rsiSellLvl = input.float(50.0, "RSI Sell Level")
|
|
|
|
atrSLmult = input.float(1.2, "SL = ATR x", step=0.1)
|
|
tp1mult = input.float(1.0, "TP1 = ATR x", step=0.1)
|
|
tp2mult = input.float(1.5, "TP2 = ATR x", step=0.1)
|
|
tp3mult = input.float(2.0, "TP3 = ATR x", step=0.1)
|
|
tp4mult = input.float(3.0, "TP4 = ATR x", step=0.1)
|
|
|
|
useBullishEngulfing = input.bool(true, "Use Bullish Engulfing")
|
|
useBearishEngulfing = input.bool(true, "Use Bearish Engulfing")
|
|
useHammer = input.bool(true, "Use Hammer")
|
|
useShootingStar = input.bool(true, "Use Shooting Star")
|
|
useDojiBreak = input.bool(true, "Use Doji Break")
|
|
|
|
showTargets = input.bool(true, "Show Targets")
|
|
showOnlyLatest = input.bool(true, "Show Only Latest Signal Levels")
|
|
extendBars = input.int(20, "Extend Lines Bars", minval=5, maxval=200)
|
|
|
|
//=========================
|
|
// Indicators
|
|
//=========================
|
|
ema20 = ta.ema(close, fastEMA)
|
|
ema50 = ta.ema(close, midEMA)
|
|
ema200 = ta.ema(close, slowEMA)
|
|
rsiVal = ta.rsi(close, rsiPeriod)
|
|
atrVal = ta.atr(atrPeriod)
|
|
|
|
plot(ema20, color=color.aqua, title="EMA 20", linewidth=2)
|
|
plot(ema50, color=color.red, title="EMA 50", linewidth=2)
|
|
plot(ema200, color=color.green, title="EMA 200", linewidth=2)
|
|
|
|
//=========================
|
|
// Candle data
|
|
//=========================
|
|
body = math.abs(close - open)
|
|
rangeVal = high - low
|
|
upperWick = high - math.max(open, close)
|
|
lowerWick = math.min(open, close) - low
|
|
|
|
isDoji = rangeVal > 0 ? (body / rangeVal) <= 0.15 : false
|
|
|
|
//=========================
|
|
// Patterns
|
|
//=========================
|
|
bullishEngulfing = (
|
|
close[1] < open[1] and
|
|
close > open and
|
|
math.min(open, close) <= math.min(open[1], close[1]) and
|
|
math.max(open, close) >= math.max(open[1], close[1])
|
|
)
|
|
|
|
bearishEngulfing = (
|
|
close[1] > open[1] and
|
|
close < open and
|
|
math.min(open, close) <= math.min(open[1], close[1]) and
|
|
math.max(open, close) >= math.max(open[1], close[1])
|
|
)
|
|
|
|
hammer = (
|
|
rangeVal > 0 and
|
|
body > 0 and
|
|
(body / rangeVal) <= 0.35 and
|
|
lowerWick >= body * 2.0 and
|
|
upperWick <= body
|
|
)
|
|
|
|
shootingStar = (
|
|
rangeVal > 0 and
|
|
body > 0 and
|
|
(body / rangeVal) <= 0.35 and
|
|
upperWick >= body * 2.0 and
|
|
lowerWick <= body
|
|
)
|
|
|
|
bullishDojiBreak = (isDoji[1] and close > high[1] and close > open)
|
|
bearishDojiBreak = (isDoji[1] and close < low[1] and close < open)
|
|
|
|
bullPattern = (
|
|
(useBullishEngulfing and bullishEngulfing) or
|
|
(useHammer and hammer) or
|
|
(useDojiBreak and bullishDojiBreak)
|
|
)
|
|
|
|
bearPattern = (
|
|
(useBearishEngulfing and bearishEngulfing) or
|
|
(useShootingStar and shootingStar) or
|
|
(useDojiBreak and bearishDojiBreak)
|
|
)
|
|
|
|
//=========================
|
|
// Trend filters
|
|
//=========================
|
|
bullTrend = (close > ema200 and ema20 > ema50 and rsiVal > rsiBuyLvl)
|
|
bearTrend = (close < ema200 and ema20 < ema50 and rsiVal < rsiSellLvl)
|
|
|
|
buySignal = bullTrend and bullPattern
|
|
sellSignal = bearTrend and bearPattern
|
|
|
|
plotshape(buySignal, title="BUY", style=shape.labelup, location=location.belowbar, color=color.lime, text="BUY", textcolor=color.black, size=size.small)
|
|
plotshape(sellSignal, title="SELL", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.white, size=size.small)
|
|
|
|
//=========================
|
|
// Storage for latest objects
|
|
//=========================
|
|
var line buySL = na
|
|
var line buyTP1 = na
|
|
var line buyTP2 = na
|
|
var line buyTP3 = na
|
|
var line buyTP4 = na
|
|
|
|
var line sellSL = na
|
|
var line sellTP1 = na
|
|
var line sellTP2 = na
|
|
var line sellTP3 = na
|
|
var line sellTP4 = na
|
|
|
|
var label buyInfoLabel = na
|
|
var label sellInfoLabel = na
|
|
|
|
//=========================
|
|
// Delete helpers
|
|
//=========================
|
|
f_delete_buy() =>
|
|
if not na(buySL)
|
|
line.delete(buySL)
|
|
buySL := na
|
|
if not na(buyTP1)
|
|
line.delete(buyTP1)
|
|
buyTP1 := na
|
|
if not na(buyTP2)
|
|
line.delete(buyTP2)
|
|
buyTP2 := na
|
|
if not na(buyTP3)
|
|
line.delete(buyTP3)
|
|
buyTP3 := na
|
|
if not na(buyTP4)
|
|
line.delete(buyTP4)
|
|
buyTP4 := na
|
|
if not na(buyInfoLabel)
|
|
label.delete(buyInfoLabel)
|
|
buyInfoLabel := na
|
|
|
|
f_delete_sell() =>
|
|
if not na(sellSL)
|
|
line.delete(sellSL)
|
|
sellSL := na
|
|
if not na(sellTP1)
|
|
line.delete(sellTP1)
|
|
sellTP1 := na
|
|
if not na(sellTP2)
|
|
line.delete(sellTP2)
|
|
sellTP2 := na
|
|
if not na(sellTP3)
|
|
line.delete(sellTP3)
|
|
sellTP3 := na
|
|
if not na(sellTP4)
|
|
line.delete(sellTP4)
|
|
sellTP4 := na
|
|
if not na(sellInfoLabel)
|
|
label.delete(sellInfoLabel)
|
|
sellInfoLabel := na
|
|
|
|
//=========================
|
|
// Draw Buy levels
|
|
//=========================
|
|
if buySignal and showTargets
|
|
if showOnlyLatest
|
|
f_delete_buy()
|
|
|
|
entryBuy = close
|
|
slBuy = entryBuy - atrVal * atrSLmult
|
|
tp1Buy = entryBuy + atrVal * tp1mult
|
|
tp2Buy = entryBuy + atrVal * tp2mult
|
|
tp3Buy = entryBuy + atrVal * tp3mult
|
|
tp4Buy = entryBuy + atrVal * tp4mult
|
|
|
|
buySL := line.new(bar_index, slBuy, bar_index + extendBars, slBuy, color=color.red, style=line.style_dashed, width=2)
|
|
buyTP1 := line.new(bar_index, tp1Buy, bar_index + extendBars, tp1Buy, color=color.lime, style=line.style_dashed, width=1)
|
|
buyTP2 := line.new(bar_index, tp2Buy, bar_index + extendBars, tp2Buy, color=color.lime, style=line.style_dashed, width=1)
|
|
buyTP3 := line.new(bar_index, tp3Buy, bar_index + extendBars, tp3Buy, color=color.lime, style=line.style_dashed, width=1)
|
|
buyTP4 := line.new(bar_index, tp4Buy, bar_index + extendBars, tp4Buy, color=color.lime, style=line.style_dashed, width=1)
|
|
|
|
buyInfoLabel := label.new(
|
|
bar_index,
|
|
low,
|
|
"BUY\n" +
|
|
"Entry: " + str.tostring(entryBuy) + "\n" +
|
|
"SL: " + str.tostring(slBuy) + "\n" +
|
|
"TP1: " + str.tostring(tp1Buy) + "\n" +
|
|
"TP2: " + str.tostring(tp2Buy) + "\n" +
|
|
"TP3: " + str.tostring(tp3Buy) + "\n" +
|
|
"TP4: " + str.tostring(tp4Buy),
|
|
style=label.style_label_up,
|
|
color=color.lime,
|
|
textcolor=color.black,
|
|
size=size.small
|
|
)
|
|
|
|
//=========================
|
|
// Draw Sell levels
|
|
//=========================
|
|
if sellSignal and showTargets
|
|
if showOnlyLatest
|
|
f_delete_sell()
|
|
|
|
entrySell = close
|
|
slSell = entrySell + atrVal * atrSLmult
|
|
tp1Sell = entrySell - atrVal * tp1mult
|
|
tp2Sell = entrySell - atrVal * tp2mult
|
|
tp3Sell = entrySell - atrVal * tp3mult
|
|
tp4Sell = entrySell - atrVal * tp4mult
|
|
|
|
sellSL := line.new(bar_index, slSell, bar_index + extendBars, slSell, color=color.red, style=line.style_dashed, width=2)
|
|
sellTP1 := line.new(bar_index, tp1Sell, bar_index + extendBars, tp1Sell, color=color.orange, style=line.style_dashed, width=1)
|
|
sellTP2 := line.new(bar_index, tp2Sell, bar_index + extendBars, tp2Sell, color=color.orange, style=line.style_dashed, width=1)
|
|
sellTP3 := line.new(bar_index, tp3Sell, bar_index + extendBars, tp3Sell, color=color.orange, style=line.style_dashed, width=1)
|
|
sellTP4 := line.new(bar_index, tp4Sell, bar_index + extendBars, tp4Sell, color=color.orange, style=line.style_dashed, width=1)
|
|
|
|
sellInfoLabel := label.new(
|
|
bar_index,
|
|
high,
|
|
"SELL\n" +
|
|
"Entry: " + str.tostring(entrySell) + "\n" +
|
|
"SL: " + str.tostring(slSell) + "\n" +
|
|
"TP1: " + str.tostring(tp1Sell) + "\n" +
|
|
"TP2: " + str.tostring(tp2Sell) + "\n" +
|
|
"TP3: " + str.tostring(tp3Sell) + "\n" +
|
|
"TP4: " + str.tostring(tp4Sell),
|
|
style=label.style_label_down,
|
|
color=color.red,
|
|
textcolor=color.white,
|
|
size=size.small
|
|
)
|
|
|
|
//=========================
|
|
// Alerts
|
|
//=========================
|
|
alertcondition(buySignal, title="Buy Alert", message="BUY signal on {{ticker}}")
|
|
alertcondition(sellSignal, title="Sell Alert", message="SELL signal on {{ticker}}")
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
) |