no viable alternative at character '—'
- User
no viable alternative at character '—'
Assistant
I apologize for the error. It seems the dash characters in the comments might be causing issues. Let me provide a cleaned-up version of the script without any special characters:
//@version=5 indicator(title="On-Chart Watchlist", shorttitle="Watchlist", overlay=true) // 1. Inputs lengthMA = input.int(title="MA Length", defval=20, group="Settings") // Define the watchlist symbols (cannot be dynamic, must be explicit inputs) sym1 = input.symbol("NASDAQ:AAPL", "Symbol 1", group="Watchlist") sym2 = input.symbol("NASDAQ:MSFT", "Symbol 2", group="Watchlist") sym3 = input.symbol("NASDAQ:GOOGL", "Symbol 3", group="Watchlist") sym4 = input.symbol("NASDAQ:AMZN", "Symbol 4", group="Watchlist") // Define colors headerColor = color.new(color.gray, 60) textColor = color.white dataColor = color.new(color.gray, 80) // 2. Data Retrieval Function // Function to fetch both Close price and SMA for a symbol efficiently fetchWatchlistData(string sym, int len) => [secClose, secMA] = request.security(sym, timeframe.period, [close, ta.sma(close, len)]) [secClose, secMA] // 3. Fetch Data (Global Scope) [c1, ma1] = fetchWatchlistData(sym1, lengthMA) [c2, ma2] = fetchWatchlistData(sym2, lengthMA) [c3, ma3] = fetchWatchlistData(sym3, lengthMA) [c4, ma4] = fetchWatchlistData(sym4, lengthMA) // 4. Table Creation and Population // Initialize the table. 'var' ensures it's only created once. // 3 columns (Symbol, Price, MA), 5 rows (Header + 4 symbols) var watchlistTable = table.new(position.top_right, 3, 5, border_width=1) // Helper function to fill data rows fillDataRow(int rowIndex, string symName, float price, float maValue) => // Convert numerical data to strings for display, format using the chart's minimum tick movement priceStr = str.tostring(price, format.mintick) maStr = str.tostring(maValue, format.mintick) table.cell(watchlistTable, 0, rowIndex, symName, bgcolor=dataColor, text_color=textColor) table.cell(watchlistTable, 1, rowIndex, priceStr, bgcolor=dataColor, text_color=textColor, text_halign=text.align_right) table.cell(watchlistTable, 2, rowIndex, maStr, bgcolor=dataColor, text_color=textColor, text_halign=text.align_right) // Function to fill the header row fillHeader() => table.cell(watchlistTable, 0, 0, "Symbol", bgcolor=headerColor, text_color=textColor, text_size=size.small) table.cell(watchlistTable, 1, 0, "Price", bgcolor=headerColor, text_color=textColor, text_size=size.small) table.cell(watchlistTable, 2, 0, str.format("SMA ({0})", lengthMA), bgcolor=headerColor, text_color=textColor, text_size=size.small) // 5. Execution Logic // We only update the table on the very last bar of the chart if barstate.islast // Draw Header (Row 0) fillHeader() // Draw Data Rows (Rows 1 through 4) fillDataRow(1, sym1, c1, ma1) fillDataRow(2, sym2, c2, ma2) fillDataRow(3, sym3, c3, ma3) fillDataRow(4, sym4, c4, ma4)This version should compile without any issues. I've removed any potential special characters that might be causing the "no viable alternative" error. The functionality remains exactly the same - it creates a watchlist table in the top-right corner of your chart showing the symbols, their current prices, and their moving averages.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.