提问人:Riv 提问时间:1/26/2023 最后编辑:Riv 更新时间:1/26/2023 访问量:44
Pinescript - 输入“long_entry”时出现语法错误
Pinescript - Syntax error at input 'long_entry'
问:
我对 prinescript 有疑问。我不知道如何解决这个问题,第 23 行。当我使用 if 语句时,我使用 ?: 我没有收到错误。
//@version=5
indicator("Test 1", overlay = true)
// Define the indicators
ema = ta.ema(close, 200)
atr14 = ta.atr(14)
long_entry = false
short_entry = false
// Define the conditions for consecutive open and close prices
long_condition = (close[2] < open[2] and close[1] < open[1] and close > open[1]) and (close > open)
or (close[3] < open[3] and close[2] < open[2] and close > open[2]) and (close > open)
or (close[4] < open[4] and close[3] < open[3] and close > open[3]) and (close > open)
or (close[5] < open[5] and close[4] < open[4] and close > open[4]) and (close > open)
or (close[6] < open[6] and close[5] < open[5] and close > open[5]) and (close > open)
short_condition = (close[2] > open[2] and close[1] > open[1] and close < open[1]) and (close > open)
or (close[3] > open[3] and close[2] > open[2] and close < open[2]) and (close < open)
or (close[4] > open[4] and close[3] > open[3] and close < open[3]) and (close < open)
or (close[5] > open[5] and close[4] > open[4] and close < open[4]) and (close < open)
or (close[6] > open[6] and close[5] > open[5] and close < open[5]) and (close < open)
// Define the conditions for long and short positions
if long_condition and close > ema and barstate.isconfirmed
long_entry := true
if short_condition and close < ema and barstate.isconfirmed
short_entry := true
// Define the stop loss
long_stop = close - (atr14 * 2)
short_stop = close + (atr14 * 2)
我环顾四周,但找不到解决方案。
答:
0赞
vitruvius
1/26/2023
#1
如果块必须缩进四个空格或一个制表符。下面的 if 语句中有五个空格:
// Define the conditions for long and short positions
if long_condition and close > ema and barstate.isconfirmed
long_entry := true
if short_condition and close < ema and barstate.isconfirmed
short_entry := true
因此,将其更改为:
// Define the conditions for long and short positions
if long_condition and close > ema and barstate.isconfirmed
long_entry := true
if short_condition and close < ema and barstate.isconfirmed
short_entry := true
注意:脚本必须至少有一个输出函数调用(例如绘图、条形色等)。
评论
0赞
Riv
1/27/2023
伙计,我的标签增加了 5 个空格。无论如何,谢谢它奏效了。
评论