Search code examples
pine-scriptpine-script-v5tradingview-api

Can't Import data from CSV to pinescript


I'm trying to import my data from a CSV file & draw horizontal lines based on the prices in my CSV file, here is the code:

(My CSV file has 4 columns & column number 1 & 3 are the prices)

//@version=5
indicator("Top 5 Prices", overlay=true) 
 
// Retrieve data from CSV file 
csvData = request.security("MyCsvFilePath", "D", close) 
 
// Define arrays to store top 5 bid and ask pricesvar float[] top5BidPrices = array.new_float(0) 
var float[] top5AskPrices = array.new_float(0) 
 
// Check if CSV data is available if not na(csvData) 
// Extract top 5 bid prices    
for i = 0 to 4 
        array.push(top5BidPrices, csvData[i, 1]) // Column index 1 for bid prices 
// Extract top 5 ask prices    
for i = 0 to 4 
        array.push(top5AskPrices, csvData[i, 3]) // Column index 3 for ask prices 
// Draw horizontal lines at top 5 bid prices
for i = 0 to 4 
        line.new(bar_index[1], top5BidPrices[i], bar_index, top5BidPrices[i], width=1, color=color.blue) 
// Draw horizontal lines at top 5 ask prices    
for i = 0 to 4 
        line.new(bar_index[1], top5AskPrices[i], bar_index, top5AskPrices[i], width=1, color=color.red)else

When I run it I get this error:

Error at 10:40 Mismatched input ',' expecting ']'.

which is this part: csvData[i, 1]

Can anyone help me fix it, please?

I tried changing csvData[i, 1] to csvData[i][1], but it's still not working ...


Solution

  • You cannot import files in pinescript.

    You can somehow convert your data to a string via macros and then try to parse that string in pinescript.