1

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)
Mike_rem
  • 11
  • 4

1 Answers1

0

Not all functions have the ta namespace. hour(), minute(), and timestamp do not belong to any namespace.

hour and minute are built-in variables which you are shadowing with the below lines:

hour = ta.hour(_time)
minute = ta.minute(_time)

The last part of your function seems to be the return value but you are wrapping code. When you are writing statements on multiple lines the statement should begin with 1 or multiple spaces (different from multiples of 4).

(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
vitruvius
  • 15,740
  • 3
  • 16
  • 26
  • Sorry, I don't understand what I need to change with the hour and minute lines, based on what you said. I'm not familiar with coding or pine-script, so I'm not sure what you mean. as for the last part, I have tried many different line spacing combinations (1 or multiple spaces different from multiples of 4) and it still gives me an error. – Mike_rem Jun 14 '23 at 08:23
  • You need to remove the unnecessary `ta.`s. – vitruvius Jun 14 '23 at 08:35
  • Thanks for the help. See update to OP. Still giving me an error. Error at 20:0 Syntax error at input '('. – Mike_rem Jun 14 '23 at 12:52