英文:
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 < 30) and (rsi < rsi[1]) and (close > close[1]):
# Bullish divergence detected, go long
strategy.entry("Long", long=true)
strategy.exit("Exit long", "Long", profit=50, stop=-50)
// Check for bearish divergence
if (rsi > 70) and (rsi > rsi[1]) and (close < close[1]):
# Bearish divergence detected, go short
strategy.entry("Short", short=true)
strategy.exit("Exit short", "Short", 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 < 30) and (rsi < rsi[1]) and (close > close[1])
// Bullish divergence detected, go long
strategy.entry("Long", strategy.long)
strategy.exit("Exit long", "Long", profit=50, stop=-50)
// Check for bearish divergence
if (rsi > 70) and (rsi > rsi[1]) and (close < close[1])
// Bearish divergence detected, go short
strategy.entry("Short", strategy.short)
strategy.exit("Exit short", "Short", profit=50, stop=-50)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论