'Pine script error "Syntax error at input 'symbol'

I am new to pinescript and I have an open source script for tradingview. But I'm struggling with a syntax error and haven't found a solution yet.

I would appreciate if someone could help me with this problem.

Syntax error at input 'symbol'

//@version=4
study(title='Moving Average Cross', shorttitle='Moving Average Cross', overlay=true, precision=6, max_labels_count=500, max_lines_count=500)

f_ma(smoothing, [symbol=src]src[/symbol], length) =>
    iff(smoothing == "RMA",     rma([symbol=src]src[/symbol], length), 
    iff(smoothing == "SMA",    [__tag__=simplemovingaverage]sma[/__tag__] ([symbol=src]src[/symbol], length)),
    iff(smoothing == "EMA",    [__tag__=ema]ema[/__tag__] ([symbol=src]src[/symbol], length), [symbol=src]src[/symbol]))


Solution 1:[1]

  1. This is erroneous copypasta with html tags.

  2. iff function is hard for newbies, try using Pine V5 and its switch function:

//@version=5
indicator("My script")

string i_maType = input.string("EMA", "MA type", options = ["EMA", "SMA", "RMA", "WMA"])


f_ma(smoothing, src, length) =>
    float ma = switch smoothing
        "EMA" => ta.rma(src, length)
        "SMA" => ta.sma(src, length)
        "RMA" => ta.ema(src, length)
        // Default used when the three first cases do not match.
        => ta.wma(src, length)
    ma


s = f_ma(i_maType, close, 20)

plot(s)

here is V5 manual.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Starr Lucky