Pine脚本错误&quot&quot 27:输入时的语法错误' i。
我尝试了所有内容,但仍然给我这个错误:“ 第27行:输入'i'的语法错误。“似乎也没有凹痕问题。
请帮助。先感谢您。
'''
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © VaheHV
//@version=5
strategy("Momentum Signal", overlay=true)
ema12 = ta.ema(close, 12)
ema26 = ta.ema(close, 26)
ema9 = ta.ema(close, 9)
macdLine = ema12 - ema26
macdSignal = ta.ema(macdLine, 9)
crossover = ta.crossover(macdLine, macdSignal)
crossunder = ta.crossunder(macdLine, macdSignal)
if crossover and macdLine < 0 and macdSignal < 0 and close > ta.ema(close, 200)
strategy.entry("Long", strategy.long)
if crossunder and macdLine > 0 and macdSignal > 0 and close < ta.ema(close, 200)
strategy.entry("Short", strategy.short)
float[] longStopLoss = na
float[] longTakeProfit = na
float[] shortStopLoss = na
float[] shortTakeProfit = na
if strategy.opentrades != 0
for i = 0 to strategy.opentrades - 1
if strategy.position_size > 0
array.push(longStopLoss, ta.lowest(low, 15))
array.push(longTakeProfit, (1.5*(strategy.opentrades.entry_price(i) - longStopLoss[i]) + strategy.opentrades.entry_price(i)))
strategy.exit("LongClose", profit = longTakeProfit[i] * 100, loss = longStopLoss[i] * 100)
else if strategy.position_size < 0
array.push(shortStopLoss, ta.highest(high, 15))
array.push(shortTakeProfit, (strategy.opentrades.entry_price(i) - 1.5*(shortStopLoss[i] - strategy.opentrades.entry_price(i)))
strategy.exit("ShortClose", profit = shortTakeProfit[i] * 100, loss = shortStopLoss[i] * 100)
'''
I tried everything but it still gives me this error: "line 27: Syntax error at input 'i'." It seems there are no indentation issues either.
Help please. Thank you in advance.
'''
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © VaheHV
//@version=5
strategy("Momentum Signal", overlay=true)
ema12 = ta.ema(close, 12)
ema26 = ta.ema(close, 26)
ema9 = ta.ema(close, 9)
macdLine = ema12 - ema26
macdSignal = ta.ema(macdLine, 9)
crossover = ta.crossover(macdLine, macdSignal)
crossunder = ta.crossunder(macdLine, macdSignal)
if crossover and macdLine < 0 and macdSignal < 0 and close > ta.ema(close, 200)
strategy.entry("Long", strategy.long)
if crossunder and macdLine > 0 and macdSignal > 0 and close < ta.ema(close, 200)
strategy.entry("Short", strategy.short)
float[] longStopLoss = na
float[] longTakeProfit = na
float[] shortStopLoss = na
float[] shortTakeProfit = na
if strategy.opentrades != 0
for i = 0 to strategy.opentrades - 1
if strategy.position_size > 0
array.push(longStopLoss, ta.lowest(low, 15))
array.push(longTakeProfit, (1.5*(strategy.opentrades.entry_price(i) - longStopLoss[i]) + strategy.opentrades.entry_price(i)))
strategy.exit("LongClose", profit = longTakeProfit[i] * 100, loss = longStopLoss[i] * 100)
else if strategy.position_size < 0
array.push(shortStopLoss, ta.highest(high, 15))
array.push(shortTakeProfit, (strategy.opentrades.entry_price(i) - 1.5*(shortStopLoss[i] - strategy.opentrades.entry_price(i)))
strategy.exit("ShortClose", profit = shortTakeProfit[i] * 100, loss = shortStopLoss[i] * 100)
'''
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pinescript
中的[]
称为 历史引用运算符。它用于访问变量的历史数据。您不使用
[]
访问数组元素。相反,您应该使用 array.get() 函数。另外,下面一行缺少一个右括号。因此,请检查我的示例中的这一行。
这应该有效:
[]
inpinescript
is called history reference operator. It is used to access historical data of a variable.You don't use
[]
to access array elements. Instead, you should usearray.get()
function for that.Also, below line is missing one closing parentheses. So, check this line in my example.
This should work: