Pine Editor not compiling ta.sma() even though syntax correct

Advertisements

I’m just trying to assign my variable (movingAv) with the value from the built-in simple moving average function. However, i’m getting the error "Could not find function or function reference ta.sma" for the line with my variable declaration on it.

In the code editor "ta.sma" has turned blue so the editor must recognise the function. I’ve looked at similar code from other indicators and it looks the same.

Any ideas what’s happening here?

Many thanks
Adam

study("Renko Reversal alert", overlay=true) 

src = close
len = 10
movingAv = ta.sma(src, len)
plot(movingAv, color=color.blue, title="MA")

//Buy signal if a bearish renko brick is followed by a bullish brick
//Sell signal if a bullish brick is followed by a bearish brick
long = close[1] > open[1] and close[2] < open[2]
long = close[1] < open[1] and close[2] > open[2]
longCross = open[1] < movingAv and close[1] > movingAv
shortCross = open[1] > movingAv and close[1] < movingAv

//Use these alerts to create server-side alerts (right-click on one of the buy or sell arrows on the chart and choose "add alert")
alertcondition(long == true, title = 'Long opportunity', message = '{{ticker}}')
alertcondition(short == true, title = 'Short opportunity', message = '{{ticker}}')
alertcondition(longCross == true, title = 'Long SMA XOver', message = '{{ticker}}')
alertcondition(longCross == true, title = 'Short SMA Xover', message = '{{ticker}}')

//Use this to customize the look of the arrows to suit your needs.
plotshape(long, location=location.belowbar, color=lime, style=shape.arrowup, text="Buy")
plotshape(short, location=location.abovebar, color=red, style=shape.arrowdown, text="Sell")
plotshape(longCross, location=location.belowbar, color=lime, style=shape.arrowup, text="Buy")
plotshape(shorCross, location=location.abovebar, color=red, style=shape.arrowdown, text="Sell")

>Solution :

Did you add at the first line of your script the below?

//@version=5

ta.sma is for pinescript v5 and you’re calling study() which makes me think you’re using //@version=4

The equivalent in version=4 is sma(src, len)
without the ta. before

Leave a ReplyCancel reply