Tradeview: pinescript error: expecting 'end of line without line continuation'
Tradeview: pinescript error: expecting 'end of line without line continuation'
在 tradeview 中编译以下代码时出现以下错误。基本上,我正在尝试使用 EMA/SMA 字符串来计算 MACD。
第 20 行:不匹配的输入 'ema' 期望 'end of the line without line continuation'
有人可以让我知道我在这里缺少什么吗?有没有更好的编码方式?
此外,我们可以在 if-else 语句中有多行,还是应该只有一行?
study("MACD BB - PRD")
//MACD Inputs
//---------------------------------------------------------------
fastLength = input(defval=12, title="MACD.FastPeriod", minval=1, maxval=50, step=1)
slowLength = input(defval=26, title="MACD.SlowPeriod", minval=1, maxval=200, step=1)
signalLength= input(defval=9, title="MACD.SignalLength", minval=1, maxval=100, step=1)
macdMode = input(defval="EMA", title="MACD.AverageMode", options=["EMA","SMA"])
//Bollinger Bands Inputs
//---------------------------------------------------------------
bbPeriod = input(defval=9, title="MACD.SignalLength", minval=1, maxval=100, step=1)
bbMultipler = input(defval=1, title="MACD.SignalLength", minval=1, maxval=10, step=0.1)
bbMode = input(defval="EMA", title="BollingerBands.AverageMode", options=["EMA","SMA"])
//---------------------------------------------------------------
// MACD calculation
macd = if (macdMode == "EMA")
ema(close, fastLength) - ema(close, slowLength) // line20
else
sma(close, fastLength) - sma(close, slowLength)
您的问题是缩进。您必须将 if 语句主体内的代码移动 4 个空格或 1 个制表符。
// MACD calculation
macd = if (macdMode == "EMA")
ema(close, fastLength) - ema(close, slowLength) // line20
else
sma(close, fastLength) - sma(close, slowLength)
can we have multiple lines inside if-else statement or should I be
having just oneliners?
是的。
TradingView 的 Pine Script Tutorial 可能会对您有所帮助。
在 tradeview 中编译以下代码时出现以下错误。基本上,我正在尝试使用 EMA/SMA 字符串来计算 MACD。
第 20 行:不匹配的输入 'ema' 期望 'end of the line without line continuation'
有人可以让我知道我在这里缺少什么吗?有没有更好的编码方式?
此外,我们可以在 if-else 语句中有多行,还是应该只有一行?
study("MACD BB - PRD")
//MACD Inputs
//---------------------------------------------------------------
fastLength = input(defval=12, title="MACD.FastPeriod", minval=1, maxval=50, step=1)
slowLength = input(defval=26, title="MACD.SlowPeriod", minval=1, maxval=200, step=1)
signalLength= input(defval=9, title="MACD.SignalLength", minval=1, maxval=100, step=1)
macdMode = input(defval="EMA", title="MACD.AverageMode", options=["EMA","SMA"])
//Bollinger Bands Inputs
//---------------------------------------------------------------
bbPeriod = input(defval=9, title="MACD.SignalLength", minval=1, maxval=100, step=1)
bbMultipler = input(defval=1, title="MACD.SignalLength", minval=1, maxval=10, step=0.1)
bbMode = input(defval="EMA", title="BollingerBands.AverageMode", options=["EMA","SMA"])
//---------------------------------------------------------------
// MACD calculation
macd = if (macdMode == "EMA")
ema(close, fastLength) - ema(close, slowLength) // line20
else
sma(close, fastLength) - sma(close, slowLength)
您的问题是缩进。您必须将 if 语句主体内的代码移动 4 个空格或 1 个制表符。
// MACD calculation
macd = if (macdMode == "EMA")
ema(close, fastLength) - ema(close, slowLength) // line20
else
sma(close, fastLength) - sma(close, slowLength)
can we have multiple lines inside if-else statement or should I be having just oneliners?
是的。
TradingView 的 Pine Script Tutorial 可能会对您有所帮助。