首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >脚本无法翻译:

脚本无法翻译:
EN

Stack Overflow用户
提问于 2021-05-14 16:00:49
回答 1查看 5.7K关注 0票数 1

我试图创建一个多移动平均脚本在TradingView拼音。不幸的是,它一直抛出错误:

脚本无法翻译成:"EMA“、"SMA”、"WMA“、"HMA”、"LIN“

我似乎找不出我的语法是否不正确,或者我是否遗漏了什么东西。

任何人能提供的任何帮助都将不胜感激。

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-14 19:49:14

脚本第一行缺少//@version=4

我还稍微调整了// Moving Average plots部分,因为您不能在两个系列之间使用fill()

您只能在plot()和hline()对象之间使用fill()

代码语言:javascript
复制
//@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)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67537333

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档