Search code examples
pine-scripttradingtradingview-api

TradingView - Incorrect for statement, Expecting to expression


I am trying to create a loop to print all Kukoin exchenge pairs.

But an error is displayed. How can I fix this problem?

Incorrect for statement, Expecting to expression

//@version=5
study("EMA 89 EMA 200 Kucoin Alerts")
exchange = input("Kucoin")

symbols = syminfo.ticker

for i = 1 to #symbols
    symbol = symbols[i]
    security(exchange,symbol,60)
    ema89 = ema(close, 89)
    ema200 = ema(close, 200)

Solution

  • Pine script doesn't work like that.

    In pine script, you can execute a script on a specific chart which has only one ticker. You cannot execute the script on multiple tickers at a time, and you can't execute a script on all tickers of one exchange (since it is still more then one ticker).

    You can, if you want, receive data from other tickers to you current ticker using the request.security() function (which on older versions of pine script was just security()) but keep in mind you have some limits, most noticeable:

    1. You can get the data from the other tickers, but you can't execute the script itself on those other tickers.
    2. There is a limit of 40 calls per script.

    If you're looking to use the TradingView data for some kind of a screener, consider the above limitations.