//@version=6 indicator("ATR SL/TP Calculator", overlay=true, max_lines_count=500, max_labels_count=500) // === INPUTS === atrLen = input.int(14, "ATR Period", minval=1) atrMult = input.float(1.5, "ATR Multiplier for SL", step=0.1, minval=0.1) rr1 = input.float(1.0, "Take Profit 1 (R:R)", step=0.5) rr2 = input.float(2.0, "Take Profit 2 (R:R)", step=0.5) rr3 = input.float(3.0, "Take Profit 3 (R:R)", step=0.5) direction = input.string("Long", "Direction", options=["Long", "Short"]) showOnLast = input.int(1, "Show on last N bars", minval=1, maxval=50) slColor = input.color(color.red, "SL Color") tp1Color = input.color(color.new(color.green, 30), "TP1 Color") tp2Color = input.color(color.new(color.lime, 30), "TP2 Color") tp3Color = input.color(color.new(color.teal, 30), "TP3 Color") // === ATR === atr = ta.atr(atrLen) // === CALCULATIONS === slDist = atr * atrMult isLong = direction == "Long" entryPrice = close slPrice = isLong ? entryPrice - slDist : entryPrice + slDist tp1Price = isLong ? entryPrice + slDist * rr1 : entryPrice - slDist * rr1 tp2Price = isLong ? entryPrice + slDist * rr2 : entryPrice - slDist * rr2 tp3Price = isLong ? entryPrice + slDist * rr3 : entryPrice - slDist * rr3 // === DISPLAY === isLastBars = bar_index >= last_bar_index - showOnLast + 1 // Plot lines plot(isLastBars ? slPrice : na, "Stop Loss", slColor, 2, plot.style_circles) plot(isLastBars ? tp1Price : na, "TP1 (" + str.tostring(rr1, "#.#") + "R)", tp1Color, 1, plot.style_cross) plot(isLastBars ? tp2Price : na, "TP2 (" + str.tostring(rr2, "#.#") + "R)", tp2Color, 1, plot.style_cross) plot(isLastBars ? tp3Price : na, "TP3 (" + str.tostring(rr3, "#.#") + "R)", tp3Color, 1, plot.style_cross) // === INFO TABLE === var table t = table.new(position.top_right, 2, 7, border_width=1) if barstate.islast table.cell(t, 0, 0, "ATR SL/TP", text_color=color.yellow, bgcolor=color.new(color.black, 70), text_size=size.small) table.cell(t, 1, 0, direction, text_color=isLong ? color.green : color.red, bgcolor=color.new(color.black, 70), text_size=size.small) table.cell(t, 0, 1, "ATR(" + str.tostring(atrLen) + "):", text_color=color.white, bgcolor=color.new(color.black, 70), text_size=size.tiny) table.cell(t, 1, 1, str.tostring(atr, format.mintick), text_color=color.aqua, bgcolor=color.new(color.black, 70), text_size=size.tiny) table.cell(t, 0, 2, "Entry:", text_color=color.white, bgcolor=color.new(color.black, 70), text_size=size.tiny) table.cell(t, 1, 2, str.tostring(entryPrice, format.mintick), text_color=color.white, bgcolor=color.new(color.black, 70), text_size=size.tiny) table.cell(t, 0, 3, "SL:", text_color=color.white, bgcolor=color.new(color.black, 70), text_size=size.tiny) table.cell(t, 1, 3, str.tostring(slPrice, format.mintick) + " (" + str.tostring(slDist, format.mintick) + ")", text_color=slColor, bgcolor=color.new(color.black, 70), text_size=size.tiny) table.cell(t, 0, 4, "TP1 (" + str.tostring(rr1, "#.#") + "R):", text_color=color.white, bgcolor=color.new(color.black, 70), text_size=size.tiny) table.cell(t, 1, 4, str.tostring(tp1Price, format.mintick), text_color=tp1Color, bgcolor=color.new(color.black, 70), text_size=size.tiny) table.cell(t, 0, 5, "TP2 (" + str.tostring(rr2, "#.#") + "R):", text_color=color.white, bgcolor=color.new(color.black, 70), text_size=size.tiny) table.cell(t, 1, 5, str.tostring(tp2Price, format.mintick), text_color=tp2Color, bgcolor=color.new(color.black, 70), text_size=size.tiny) table.cell(t, 0, 6, "TP3 (" + str.tostring(rr3, "#.#") + "R):", text_color=color.white, bgcolor=color.new(color.black, 70), text_size=size.tiny) table.cell(t, 1, 6, str.tostring(tp3Price, format.mintick), text_color=tp3Color, bgcolor=color.new(color.black, 70), text_size=size.tiny)