Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pinescript: Script could not be translated from:

Tags:

pine-script

I am trying to create a multiple moving average script in TradingView Pinescript. Unfortunately, it keeps throwing the error:

Script could not be translated from: ["EMA","SMA","WMA","HMA","LIN"]

I can't seem to figure out if my syntax is incorrect or if there is something else that I'm missing.

Any help anyone can provide would be greatly appreciated.

study("SPY Indicators", shorttitle="SPY Ind", overlay=true)
//@version=1
// Version 1.0
// Author: Likwid


// Definitions: Price and Timeframes
src = input(close, title = "Source")
resolution = timeframe.period
price = security(syminfo.tickerid, resolution, src)

// Defintions: Moving Average periods and types
ma1Period = input(defval=8, title="Period", inline="1", group="Moving Averages: Zone 1")
ma1Type = input(defval="EMA", title="Type", type=input.string, options=["EMA","SMA","WMA","HMA","LIN"], tooltip="MA Smoothing", inline="1", group="Moving Averages: Zone 1")

ma2Period = input(defval=21, title="Period", inline="2", group="Moving Averages: Zone 1")
ma2Type = input(defval="EMA", title="Type", type=input.string, options=["EMA","SMA","WMA","HMA","LIN"], tooltip="MA Smoothing", inline="2", group="Moving Averages: Zone 1")

ma3Period = input(defval=34, title="Period", inline="3", group="Moving Averages: Zone 2")
ma3Type = input(defval="EMA", title="Type", type=input.string, options=["EMA","SMA","WMA","HMA","LIN"], tooltip="MA Smoothing", inline="3", group="Moving Averages: Zone 2")

ma4Period = input(defval=50, title="Period", inline="4", group="Moving Averages: Zone 2")
ma4Type = input(defval="EMA", title="Type", type=input.string, options=["EMA","SMA","WMA","HMA","LIN"], tooltip="MA Smoothing", inline="4", group="Moving Averages: Zone 2")

ma5Period = input(defval=200, title="Period", inline="5", group="Moving Averages: Other")
ma5Type = input(defval="EMA", title="Type", type=input.string, options=["EMA","SMA","WMA","HMA","LIN"], tooltip="MA Smoothing", inline="5", group="Moving Averages: Other")

vwSwitch = input(title="VWAP", type=input.bool, defval=true, inline="6", group="Moving Averages: Other")
vwPeriod = input(defval=9, title="Period", inline="6", group="Moving Averages: Other")

// Moving Average Calculation
ma1 = ma1Type == "EMA" ? ema(price, ma1Period) :
     ma1Type == "SMA" ? sma(price, ma1Period) :
     ma1Type == "WMA" ? wma(price, ma1Period) :
     ma1Type == "HMA" ? hma(price, ma1Period) :
     ma1Type == "LIN" ? linreg(price, ma1Period, 0) : na

ma2 = ma2Type == "EMA" ? ema(price, ma2Period) :
     ma2Type == "SMA" ? sma(price, ma2Period) :
     ma2Type == "WMA" ? wma(price, ma2Period) :
     ma2Type == "HMA" ? hma(price, ma2Period) :
     ma2Type == "LIN" ? linreg(price, ma2Period, 0) : na

ma3 = ma3Type == "EMA" ? ema(price, ma3Period) :
     ma3Type == "SMA" ? sma(price, ma3Period) :
     ma3Type == "WMA" ? wma(price, ma3Period) :
     ma3Type == "HMA" ? hma(price, ma3Period) :
     ma3Type == "LIN" ? linreg(price, ma3Period, 0) : na

ma4 = ma4Type == "EMA" ? ema(price, ma4Period) :
     ma4Type == "SMA" ? sma(price, ma4Period) :
     ma4Type == "WMA" ? wma(price, ma4Period) :
     ma4Type == "HMA" ? hma(price, ma4Period) :
     ma4Type == "LIN" ? linreg(price, ma4Period, 0) : na
    
ma5 = ma5Type == "EMA" ? ema(price, ma5Period) :
     ma5Type == "SMA" ? sma(price, ma5Period) :
     ma5Type == "WMA" ? wma(price, ma5Period) :
     ma5Type == "LIN" ? linreg(price, ma5Period, 0) : na

// Definitions: Trends
TrendUp1() => ma1 > ma2
TrendDown1() => ma1 < ma2
TrendUp2() => ma3 > ma4
TrendDown2() => ma3 < ma4

trendColor1 = TrendUp1() ? color.green : TrendDown1() ? color.red : color.blue
trendColor2 = TrendUp2() ? color.blue : TrendDown2() ? color.red : color.blue


// Moving Average plots
fill(ma1, ma2, color=trendColor1, transp=70)
fill(ma3, ma4, color=trendColor2, transp=70)

plot(ma5, color=color.red, linewidth=2, style=plot.style_line)
plot(vwSwitch ? vwap(hlc3) : na, color=color.white, linewidth=1, style=plot.style_line)
like image 581
Likwid Avatar asked May 07 '26 03:05

Likwid


1 Answers

The script was missing //@version=4 on the first line.
I've also adjusted the // Moving Average plots section a bit, because you can't use fill() between 2 series.
You can only use fill() between plot() and hline() objects.

//@version=4
study("SPY Indicators", shorttitle="SPY Ind", overlay=true)
// Version 1.0
// Author: Likwid

// Definitions: Price and Timeframes
src = input(close, title = "Source")
resolution = timeframe.period
price = security(syminfo.tickerid, resolution, src)

// Defintions: Moving Average periods and types
ma1Period = input(defval=8, title="Period", inline="1", group="Moving Averages: Zone 1")
ma1Type = input(defval="EMA", title="Type", type=input.string, options=["EMA","SMA","WMA","HMA","LIN"], tooltip="MA Smoothing", inline="1", group="Moving Averages: Zone 1")

ma2Period = input(defval=21, title="Period", inline="2", group="Moving Averages: Zone 1")
ma2Type = input(defval="EMA", title="Type", type=input.string, options=["EMA","SMA","WMA","HMA","LIN"], tooltip="MA Smoothing", inline="2", group="Moving Averages: Zone 1")

ma3Period = input(defval=34, title="Period", inline="3", group="Moving Averages: Zone 2")
ma3Type = input(defval="EMA", title="Type", type=input.string, options=["EMA","SMA","WMA","HMA","LIN"], tooltip="MA Smoothing", inline="3", group="Moving Averages: Zone 2")

ma4Period = input(defval=50, title="Period", inline="4", group="Moving Averages: Zone 2")
ma4Type = input(defval="EMA", title="Type", type=input.string, options=["EMA","SMA","WMA","HMA","LIN"], tooltip="MA Smoothing", inline="4", group="Moving Averages: Zone 2")

ma5Period = input(defval=200, title="Period", inline="5", group="Moving Averages: Other")
ma5Type = input(defval="EMA", title="Type", type=input.string, options=["EMA","SMA","WMA","HMA","LIN"], tooltip="MA Smoothing", inline="5", group="Moving Averages: Other")

vwSwitch = input(title="VWAP", type=input.bool, defval=true, inline="6", group="Moving Averages: Other")
vwPeriod = input(defval=9, title="Period", inline="6", group="Moving Averages: Other")

// Moving Average Calculation
ma1 = ma1Type == "EMA" ? ema(price, ma1Period) :
     ma1Type == "SMA" ? sma(price, ma1Period) :
     ma1Type == "WMA" ? wma(price, ma1Period) :
     ma1Type == "HMA" ? hma(price, ma1Period) :
     ma1Type == "LIN" ? linreg(price, ma1Period, 0) : na

ma2 = ma2Type == "EMA" ? ema(price, ma2Period) :
     ma2Type == "SMA" ? sma(price, ma2Period) :
     ma2Type == "WMA" ? wma(price, ma2Period) :
     ma2Type == "HMA" ? hma(price, ma2Period) :
     ma2Type == "LIN" ? linreg(price, ma2Period, 0) : na

ma3 = ma3Type == "EMA" ? ema(price, ma3Period) :
     ma3Type == "SMA" ? sma(price, ma3Period) :
     ma3Type == "WMA" ? wma(price, ma3Period) :
     ma3Type == "HMA" ? hma(price, ma3Period) :
     ma3Type == "LIN" ? linreg(price, ma3Period, 0) : na

ma4 = ma4Type == "EMA" ? ema(price, ma4Period) :
     ma4Type == "SMA" ? sma(price, ma4Period) :
     ma4Type == "WMA" ? wma(price, ma4Period) :
     ma4Type == "HMA" ? hma(price, ma4Period) :
     ma4Type == "LIN" ? linreg(price, ma4Period, 0) : na
    
ma5 = ma5Type == "EMA" ? ema(price, ma5Period) :
     ma5Type == "SMA" ? sma(price, ma5Period) :
     ma5Type == "WMA" ? wma(price, ma5Period) :
     ma5Type == "LIN" ? linreg(price, ma5Period, 0) : na

// Definitions: Trends
TrendUp1() => ma1 > ma2
TrendDown1() => ma1 < ma2
TrendUp2() => ma3 > ma4
TrendDown2() => ma3 < ma4

trendColor1 = TrendUp1() ? color.green : TrendDown1() ? color.red : color.blue
trendColor2 = TrendUp2() ? color.blue : TrendDown2() ? color.red : color.blue


// Moving Average plots
p_ma1 = plot(ma1)
p_ma2 = plot(ma2)
p_ma3 = plot(ma3)
p_ma4 = plot(ma4)
fill(p_ma1, p_ma2, color=trendColor1, transp=70)
fill(p_ma3, p_ma4, color=trendColor2, transp=70)

plot(ma5, color=color.red, linewidth=2, style=plot.style_line)
plot(vwSwitch ? vwap(hlc3) : na, color=color.white, linewidth=1, style=plot.style_line)
like image 160
Bjorn Mistiaen Avatar answered May 09 '26 20:05

Bjorn Mistiaen