编译错误。第10行:多余的输入 ‘:’,期望 ‘行结束,无需行继续’。

huangapple go评论69阅读模式
英文:

Compilation error. Line 10: Extraneous input ':' expecting 'end of line without line continuation'

问题

//@version=5

// 定义RSI周期
period = 14

// 计算RSI
rsi = rsi(close, period)

// 检查看涨背离
if (rsi < 30) and (rsi < rsi[1]) and (close > close[1]):
# 检测到看涨背离,开多仓
strategy.entry("Long", long=true)
strategy.exit("Exit long", "Long", profit=50, stop=-50)

// 检查看跌背离
if (rsi > 70) and (rsi > rsi[1]) and (close < close[1]):
# 检测到看跌背离,开空仓
strategy.entry("Short", short=true)
strategy.exit("Exit short", "Short", profit=50, stop=-50)

英文:

I keep getting compilation errors, I am new to pinescript and cant figure out where I am going wrong.

//@version=5

// Define the RSI period
period = 14

// Calculate the RSI
rsi = rsi(close, period)

// Check for bullish divergence
   if (rsi &lt; 30) and (rsi &lt; rsi[1]) and (close &gt; close[1]):
    # Bullish divergence detected, go long
    strategy.entry(&quot;Long&quot;, long=true)
    strategy.exit(&quot;Exit long&quot;, &quot;Long&quot;, profit=50, stop=-50)

// Check for bearish divergence
    if (rsi &gt; 70) and (rsi &gt; rsi[1]) and (close &lt; close[1]):
     # Bearish divergence detected, go short
     strategy.entry(&quot;Short&quot;, short=true)
     strategy.exit(&quot;Exit short&quot;, &quot;Short&quot;, profit=50, stop=-50)

答案1

得分: 0

您的错误来自于您的 'if' 块的缩进问题。更改缩进和您的代码如下:

//@version=5
// 定义RSI周期
period = 14

rsi = ta.rsi(close, period)

// 检查看涨背离
if (rsi < 30) and (rsi < rsi[1]) and (close > close[1])
    // 检测到看涨背离,做多
    strategy.entry("Long", strategy.long)
    strategy.exit("Exit long", "Long", profit=50, stop=-50)

// 检查看跌背离
if (rsi > 70) and (rsi > rsi[1]) and (close < close[1])
    // 检测到看跌背离,做空
    strategy.entry("Short", strategy.short)
    strategy.exit("Exit short", "Short", profit=50, stop=-50)

希望这可以帮助您解决问题。如果有其他问题,请随时提出。

英文:

You error comes from the indentation of your 'if' block.<br>
Change you indentation and your code to : <br>

//@version=5
// Define the RSI period
period = 14

rsi = ta.rsi(close, period)

// Check for bullish divergence
if (rsi &lt; 30) and (rsi &lt; rsi[1]) and (close &gt; close[1])
    // Bullish divergence detected, go long
    strategy.entry(&quot;Long&quot;, strategy.long)
    strategy.exit(&quot;Exit long&quot;, &quot;Long&quot;, profit=50, stop=-50)

// Check for bearish divergence
if (rsi &gt; 70) and (rsi &gt; rsi[1]) and (close &lt; close[1])
    // Bearish divergence detected, go short
    strategy.entry(&quot;Short&quot;, strategy.short)
    strategy.exit(&quot;Exit short&quot;, &quot;Short&quot;, profit=50, stop=-50)

huangapple
  • 本文由 发表于 2023年1月9日 04:52:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75051194.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定