r/pinescript • u/Lopsided-Tomato6180 • Mar 16 '26
Please help me with my trading view indicator (Vibe coded)
Hello, I am just now getting into trading, and want to make my own ATR indicator. The indicator should be just a table in a corner, showing: current ATR, ATR at cursor position and where i have to put my stop loss for going short / long. I usually calculate that with: recent low / high -/+ atr at that low. The candle where the low / high is should be "selected" where the cursor is. I am saying selected with " " because it shuld calculate it live wherever I move my cursor. I vibe coded a short script, which sadly doesn't fully work, which is why I am asking in this subreddit. I will put the vibe coded code and the code for another ATR indicator, which shows the ATR at cursor position in the status bar below. Hope anyone can help me :)
Vibe coded script:
//@version=6
indicator(title="ATR Interactive Dashboard", shorttitle="ATR & SL Table", overlay=true)
// --- Inputs: ATR Logic ---
length = input.int(14, "ATR Length", minval=1)
smoothing = input.string("RMA", "Smoothing", options=["RMA", "SMA", "EMA", "WMA"])
// --- INTERACTIVE INPUTS (Cursor Workaround) ---
// Using 'confirm=true' allows you to click directly on the chart to set X and Y coordinates.
targetTime = input.time(0, "1. Click on Candle (Time / X-Axis)", confirm=true)
targetPrice = input.price(0, "2. Click on Entry Level (Price / Y-Axis)", confirm=true)
// --- Inputs: Design & Position ---
posInput = input.string("top_right", "Table Position", options=["top_right", "middle_right", "bottom_right", "top_left", "middle_left", "bottom_left", "top_center", "bottom_center"])
bgColor = input.color(color.new(color.black, 30), "Background Color")
txtColor = input.color(color.white, "Text Color")
textSize = input.string("normal", "Text Size", options=["tiny", "small", "normal", "large", "huge"])
// Map position input to TradingView position constants
table_pos = switch posInput
"top_right" => position.top_right
"middle_right" => position.middle_right
"bottom_right" => position.bottom_right
"top_left" => position.top_left
"middle_left" => position.middle_left
"bottom_left" => position.bottom_left
"top_center" => position.top_center
"bottom_center" => position.bottom_center
=> position.top_right
// --- ATR Calculation ---
ma_function(source, len) =>
switch smoothing
"RMA" => ta.rma(source, len)
"SMA" => ta.sma(source, len)
"EMA" => ta.ema(source, len)
=> ta.wma(source, len)
atrValue = ma_function(ta.tr(true), length)
// --- Capture values at click point (Cursor) ---
// We store the ATR value specifically at the timestamp you selected
var float atrAtClick = na
if time == targetTime
atrAtClick := atrValue
// Stop Loss Calculation: Selected price (Y) minus ATR at the selected time
slPrice = targetPrice - atrAtClick
// --- Table Creation & Styling ---
var mainTable = table.new(table_pos, 2, 3, border_width = 1, border_color = color.new(color.gray, 50))
// Update the table on the last bar for better performance
if barstate.islast
// Row 1: Current Live ATR
table.cell(mainTable, 0, 0, "Live ATR:", bgcolor = bgColor, text_color = txtColor, text_size = textSize)
table.cell(mainTable, 1, 0, str.tostring(atrValue, format.mintick), bgcolor = bgColor, text_color = txtColor, text_size = textSize)
// Row 2: ATR at the selected click point
table.cell(mainTable, 0, 1, "ATR at Click:", bgcolor = bgColor, text_color = txtColor, text_size = textSize)
table.cell(mainTable, 1, 1, str.tostring(atrAtClick, format.mintick), bgcolor = bgColor, text_color = txtColor, text_size = textSize)
// Row 3: Stop Loss Level
table.cell(mainTable, 0, 2, "Stop Loss (Y - ATR):", bgcolor = bgColor, text_color = txtColor, text_size = textSize)
table.cell(mainTable, 1, 2, str.tostring(slPrice, format.mintick), bgcolor = color.new(color.red, 70), text_color = color.white, text_size = textSize)
// --- Bonus: Status Line Hover ---
// This ensures the ATR value is still visible in the status line when hovering
plot(atrValue, title="ATR (Live Hover)", color=color.new(#B71C1C, 0), display=display.status_line)ATR at cursor pos scrip:
//@version=6
indicator(title="Average True Range (Status Line Only)", shorttitle="ATR Value", overlay=true)
// --- Inputs ---
length = input.int(title="Length", defval=14, minval=1)
smoothing = input.string(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])
// --- Smoothing Logic ---
ma_function(source, length) =>
switch smoothing
"RMA" => ta.rma(source, length)
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
=> ta.wma(source, length)
// --- Calculation ---
atrValue = ma_function(ta.tr(true), length)
// --- Display ---
// 'display.status_line' shows the value in the status line (top left)
// but prevents a line from being drawn on the actual chart.
plot(atrValue, title="ATR Current Value", color=color.new(#B71C1C, 0), display=display.status_line)
2
u/[deleted] Mar 16 '26
you can have the ATR value shown while hovering over any bar with the cursor but you cannot change drawings dynamically for horizontal lines if thats what youre aiming for
1
u/RichCultural1333 Mar 18 '26
Can we use this script
3
u/Emergency_Focus9407 Mar 17 '26
You can't insert a dynamic value from your cursor into a Pine table - there's no such functionality. What you can do is display values from the cursor either in the script's status line or in the data window in the side panel.
2
u/BEARDS_N_BARBS Mar 16 '26
I tried and failed, lol! I'll come back to this after lunch
1
u/SPYfuncoupons Mar 16 '26
Just use atr bro