OPEN-SOURCE SCRIPT
Kewme

//version=5
indicator("EMA 9/15 + ATR TP/SL Separate Boxes (No Engulfing)", overlay=true, max_lines_count=500, max_boxes_count=500)
// ===== INPUTS =====
atrLen = input.int(14, "ATR Length")
slMult = input.float(1.0, "SL ATR Multiplier")
rr = input.float(2.0, "Risk Reward")
// ===== EMA =====
ema9 = ta.ema(close, 9)
ema15 = ta.ema(close, 15)
plot(ema9, color=color.green, title="EMA 9")
plot(ema15, color=color.red, title="EMA 15")
// ===== TREND STATE =====
var int trendState = 0
// ===== ATR =====
atr = ta.atr(atrLen)
// ===== Indecision =====
bodySize = math.abs(close - open)
candleRange = high - low
indecision = bodySize <= candleRange * 0.35
// ===== SIGNAL CONDITIONS (NO Engulfing) =====
buySignal =
ema9 > ema15 and
trendState != 1 and
indecision[1] and
close > ema9
sellSignal =
ema9 < ema15 and
trendState != -1 and
indecision[1] and
close < ema9
// ===== UPDATE TREND STATE =====
if buySignal
trendState := 1
if sellSignal
trendState := -1
// ===== SL & TP =====
buySL = close - atr * slMult
buyTP = close + atr * slMult * rr
sellSL = close + atr * slMult
sellTP = close - atr * slMult * rr
// ===== PLOTS =====
plotshape(buySignal, text="BUY", style=shape.labelup, location=location.belowbar, color=color.green, size=size.tiny)
plotshape(sellSignal, text="SELL", style=shape.labeldown, location=location.abovebar, color=color.red, size=size.tiny)
// ===== VARIABLES =====
var line buySLLine = na
var line buyTPLine = na
var line sellSLLine = na
var line sellTPLine = na
var box buySLBox = na
var box buyTPBox = na
var box sellSLBox = na
var box sellTPBox = na
// ===== BUY SIGNAL =====
if buySignal
// Delete previous
if not na(buySLLine)
line.delete(buySLLine)
line.delete(buyTPLine)
box.delete(buySLBox)
box.delete(buyTPBox)
// Draw lines
buySLLine := line.new(bar_index, buySL, bar_index + 15, buySL, color=color.red, width=2)
buyTPLine := line.new(bar_index, buyTP, bar_index + 15, buyTP, color=color.green, width=2)
// Draw separate boxes
buySLBox := box.new(bar_index, buySL - atr*0.1, bar_index + 15, buySL + atr*0.1, border_color=color.red, bgcolor=color.new(color.red,70))
buyTPBox := box.new(bar_index, buyTP - atr*0.1, bar_index + 15, buyTP + atr*0.1, border_color=color.green, bgcolor=color.new(color.green,70))
// ===== SELL SIGNAL =====
if sellSignal
// Delete previous
if not na(sellSLLine)
line.delete(sellSLLine)
line.delete(sellTPLine)
box.delete(sellSLBox)
box.delete(sellTPBox)
// Draw lines
sellSLLine := line.new(bar_index, sellSL, bar_index + 15, sellSL, color=color.red, width=2)
sellTPLine := line.new(bar_index, sellTP, bar_index + 15, sellTP, color=color.green, width=2)
// Draw separate boxes
sellSLBox := box.new(bar_index, sellSL - atr*0.1, bar_index + 15, sellSL + atr*0.1, border_color=color.red, bgcolor=color.new(color.red,70))
sellTPBox := box.new(bar_index, sellTP - atr*0.1, bar_index + 15, sellTP + atr*0.1, border_color=color.green, bgcolor=color.new(color.green,70))
indicator("EMA 9/15 + ATR TP/SL Separate Boxes (No Engulfing)", overlay=true, max_lines_count=500, max_boxes_count=500)
// ===== INPUTS =====
atrLen = input.int(14, "ATR Length")
slMult = input.float(1.0, "SL ATR Multiplier")
rr = input.float(2.0, "Risk Reward")
// ===== EMA =====
ema9 = ta.ema(close, 9)
ema15 = ta.ema(close, 15)
plot(ema9, color=color.green, title="EMA 9")
plot(ema15, color=color.red, title="EMA 15")
// ===== TREND STATE =====
var int trendState = 0
// ===== ATR =====
atr = ta.atr(atrLen)
// ===== Indecision =====
bodySize = math.abs(close - open)
candleRange = high - low
indecision = bodySize <= candleRange * 0.35
// ===== SIGNAL CONDITIONS (NO Engulfing) =====
buySignal =
ema9 > ema15 and
trendState != 1 and
indecision[1] and
close > ema9
sellSignal =
ema9 < ema15 and
trendState != -1 and
indecision[1] and
close < ema9
// ===== UPDATE TREND STATE =====
if buySignal
trendState := 1
if sellSignal
trendState := -1
// ===== SL & TP =====
buySL = close - atr * slMult
buyTP = close + atr * slMult * rr
sellSL = close + atr * slMult
sellTP = close - atr * slMult * rr
// ===== PLOTS =====
plotshape(buySignal, text="BUY", style=shape.labelup, location=location.belowbar, color=color.green, size=size.tiny)
plotshape(sellSignal, text="SELL", style=shape.labeldown, location=location.abovebar, color=color.red, size=size.tiny)
// ===== VARIABLES =====
var line buySLLine = na
var line buyTPLine = na
var line sellSLLine = na
var line sellTPLine = na
var box buySLBox = na
var box buyTPBox = na
var box sellSLBox = na
var box sellTPBox = na
// ===== BUY SIGNAL =====
if buySignal
// Delete previous
if not na(buySLLine)
line.delete(buySLLine)
line.delete(buyTPLine)
box.delete(buySLBox)
box.delete(buyTPBox)
// Draw lines
buySLLine := line.new(bar_index, buySL, bar_index + 15, buySL, color=color.red, width=2)
buyTPLine := line.new(bar_index, buyTP, bar_index + 15, buyTP, color=color.green, width=2)
// Draw separate boxes
buySLBox := box.new(bar_index, buySL - atr*0.1, bar_index + 15, buySL + atr*0.1, border_color=color.red, bgcolor=color.new(color.red,70))
buyTPBox := box.new(bar_index, buyTP - atr*0.1, bar_index + 15, buyTP + atr*0.1, border_color=color.green, bgcolor=color.new(color.green,70))
// ===== SELL SIGNAL =====
if sellSignal
// Delete previous
if not na(sellSLLine)
line.delete(sellSLLine)
line.delete(sellTPLine)
box.delete(sellSLBox)
box.delete(sellTPBox)
// Draw lines
sellSLLine := line.new(bar_index, sellSL, bar_index + 15, sellSL, color=color.red, width=2)
sellTPLine := line.new(bar_index, sellTP, bar_index + 15, sellTP, color=color.green, width=2)
// Draw separate boxes
sellSLBox := box.new(bar_index, sellSL - atr*0.1, bar_index + 15, sellSL + atr*0.1, border_color=color.red, bgcolor=color.new(color.red,70))
sellTPBox := box.new(bar_index, sellTP - atr*0.1, bar_index + 15, sellTP + atr*0.1, border_color=color.green, bgcolor=color.new(color.green,70))
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.