New to pine-scripting, trying to create a custom indicator in Tradingview and I'm getting this error message:
Syntax error at input 'end of line without line continuation'
from this code:
//@version=5
indicator("Session Liquidity", overlay=true)
// Input parameters
numDaysBack = input(5, "Number of Days Back")
// Calculate time offset based on NY timezone (Eastern Standard Time)
nyOffset = 5 * 60 * 60 * 1000 // 5 hours offset
// Convert NY time to TradingView server time
nyTime = time + nyOffset
// Function to check if the time falls within the desired hours
shouldDrawLine(_time) =>
hour = ta.hour(_time)
minute = ta.minute(_time)
(hour == 3 and minute == 0) or // 3am
(hour == 8 and minute == 0) or // 8am
(hour == 13 and minute == 0) or // 1pm
(hour == 19 and minute == 0) or // 7pm
(hour == 0 and minute == 0) // midnight
// Draw vertical lines
for i = 0 to numDaysBack - 1
lineTime = ta.timestamp(year(timenow), month(timenow), dayofmonth(timenow) - i, 0, 0) - nyOffset
if shouldDrawLine(lineTime)
line.new(bar_index[lineTime], low, bar_index[lineTime], high, color=color.red, width=2)
From what I understand, it could be an indentation issue, and I have tried various indentation combinations, but its still giving me trouble. The script editor is telling me the issue is with line 20, specifically (the line that ends with "3am").
Thanks for any help.
Update:
Revised code still giving error message;
Error at 20:0 Syntax error at input '('.
Revised code;
study("Session Liquidity", overlay=true)
// Input parameters
numDaysBack = input(5, "Number of Days Back")
// Calculate time offset based on NY timezone (Eastern Standard
Time)
nyOffset = 5 * 60 * 60 * 1000 // 5 hours offset
// Convert NY time to TradingView server time
nyTime = time + nyOffset
// Function to check if the time falls within the desired hours
shouldDrawLine(_time) =>
hour = hour(_time)
minute = minute(_time)
(hour == 3 and minute == 0) or // 3am
(hour == 8 and minute == 0) or // 8am
(hour == 13 and minute == 0) or // 1pm
(hour == 19 and minute == 0) or // 7pm
(hour == 0 and minute == 0) // midnight
// Draw vertical lines
for i = 0 to numDaysBack - 1
lineTime = timestamp(year(timenow), month(timenow),
dayofmonth(timenow) - i, 0, 0) - nyOffset
if shouldDrawLine(lineTime)
line.new(x1=lineTime, y1=low, x2=lineTime, y2=high,
color=color.red, width=2, extend=extend.both)