使用 heikin ashi 的策略进入和退出,但它在 longcondition 中显示错误
strategy entry and exit using heikin ashi but it shows error in longcondition
在长条件下显示错误。我也添加了错误
错误:
Add to Chart operation failed, reason: line 16: Syntax error at input 'openHA'
有什么办法可以纠正这个错误
我在下面添加了代码-
//@version=4
strategy("Heikin Ashi Strategy on normal candles", shorttitle="HA Strategy", overlay=true)
openHA = security(heikinashi(syminfo.tickerid), timeframe.period, open)
closeHA = security(heikinashi(syminfo.tickerid), timeframe.period, close)
highHA = security(heikinashi(syminfo.tickerid), timeframe.period, high)
lowHA = security(heikinashi(syminfo.tickerid), timeframe.period, low)
fromYear = year > 2019
toYear = year < 2021
longCondition = openHA = lowHA and closeHA[2] > openHA[2]
if (longCondition and fromYear and toYear)
strategy.entry("Long 1", strategy.long)
closeCondition = closeHA = highHA
if (closeCondition)
strategy.close("Long 1")
plot(close)
这是因为你在语句中有两个=
变量赋值。对于“等于”逻辑运算,您使用两个:openHa == lowHA
。 closeCondition
行出现相同的错误,您需要在 if 语句中进行 indent/nest 操作。
if (longCondition and fromYear and toYear)
strategy.entry("Long 1", strategy.long) // <-- this line one tab indented
在长条件下显示错误。我也添加了错误
错误:
Add to Chart operation failed, reason: line 16: Syntax error at input 'openHA'
有什么办法可以纠正这个错误
我在下面添加了代码-
//@version=4
strategy("Heikin Ashi Strategy on normal candles", shorttitle="HA Strategy", overlay=true)
openHA = security(heikinashi(syminfo.tickerid), timeframe.period, open)
closeHA = security(heikinashi(syminfo.tickerid), timeframe.period, close)
highHA = security(heikinashi(syminfo.tickerid), timeframe.period, high)
lowHA = security(heikinashi(syminfo.tickerid), timeframe.period, low)
fromYear = year > 2019
toYear = year < 2021
longCondition = openHA = lowHA and closeHA[2] > openHA[2]
if (longCondition and fromYear and toYear)
strategy.entry("Long 1", strategy.long)
closeCondition = closeHA = highHA
if (closeCondition)
strategy.close("Long 1")
plot(close)
这是因为你在语句中有两个=
变量赋值。对于“等于”逻辑运算,您使用两个:openHa == lowHA
。 closeCondition
行出现相同的错误,您需要在 if 语句中进行 indent/nest 操作。
if (longCondition and fromYear and toYear)
strategy.entry("Long 1", strategy.long) // <-- this line one tab indented