【问题标题】:Pine Script: How to remove "syntax error at input 'crossed' "Pine 脚本:如何删除“输入‘交叉’时的语法错误”
【发布时间】:2021-05-02 10:07:12
【问题描述】:

我无法删除输入时的语法错误。它显示以下编码。有人可以在没有任何语法的情况下检查并将运行脚本发回给我吗?它用于交易视图中的 pine 脚本。 谢谢您的帮助。 代码如下,问题发生在:“if crossed”行,显示语法错误。

//@version=4

par1=input(21)
par2=input(55)
ema1=ema(close,par1)
ema2=ema(close,par2)
buy=ema1>ema2
sell=ema2>ema1
mycolor= iff(buy,color.green,iff(sell,color.blue,color.red))
barcolor(color=mycolor)

ema100=ema(close,100)
ibuy=crossover(ema1,ema2)
iSell=crossunder(ema1,ema2)
//iSell=crossunder(close,ema1)
Varp=tostring(close[1])
crossed =crossover(ema(close,par1),ema(close,par2))

if crossed
   I = label.new(bar_index,na,tostring(close))
       color=color.green,
       textcolor=color.white,
       style=label.style_labelup,yloc=yloc.belowbar)
crossed2 =crossunder(ema(close,par1),ema(close,par2))
if crossed2
   I = label.new(bar_index.na,tostring(close))
       color=color.red,
       textcolor=color.white,
       style=label.style_labeldown,yloc=yloc.abovebar)

plot(ema(close,par1),"EMA Short",color=color.blue)
plot(ema(close,par2),"EMA Long",color=color.orange)

longCondition = crossover(ema(close,par1),ema(close,par2))
if (longCondition)
strategy.entry("My Long Entry Id",strategy.long)

shortCondition = crossunder(ema(close,par1),ema(close,par2))
if (shortCondition)
strategy.entry("My Short Entry Id",strategy.short)

【问题讨论】:

    标签: pine-script


    【解决方案1】:

    编程时,每个字符都很重要。你这里有 3 个空格而不是 4 个:

        I = label.new(bar_index,na,tostring(close),
    

    if crossed2 下你有这个:

       I = label.new(bar_index.na,tostring(close))
    

    而不是这个:

        I = label.new(bar_index,na,tostring(close),
    

    只更改了两个字符,但没有它们代码将无法编译。

    您还缺少脚本开头的strategy() 声明语句。请参阅usrman on structuring scriptscontinuing lines。 完整代码:

    //@version=4
    strategy("S")
    
    par1=input(21)
    par2=input(55)
    ema1=ema(close,par1)
    ema2=ema(close,par2)
    buy=ema1>ema2
    sell=ema2>ema1
    mycolor= iff(buy,color.green,iff(sell,color.blue,color.red))
    barcolor(color=mycolor)
    
    ema100=ema(close,100)
    ibuy=crossover(ema1,ema2)
    iSell=crossunder(ema1,ema2)
    //iSell=crossunder(close,ema1)
    Varp=tostring(close[1])
    crossed = crossover(ema(close,par1),ema(close,par2))
    
    if crossed
        I = label.new(bar_index,na,tostring(close),
          color=color.green,
          textcolor=color.white,
          style=label.style_labelup,yloc=yloc.belowbar)
    crossed2 =crossunder(ema(close,par1),ema(close,par2))
    if crossed2
        I = label.new(bar_index,na,tostring(close),
          color=color.red,
          textcolor=color.white,
          style=label.style_labeldown,yloc=yloc.abovebar)
    
    plot(ema(close,par1),"EMA Short",color=color.blue)
    plot(ema(close,par2),"EMA Long",color=color.orange)
    
    longCondition = crossover(ema(close,par1),ema(close,par2))
    if (longCondition)
        strategy.entry("My Long Entry Id",strategy.long)
    
    shortCondition = crossunder(ema(close,par1),ema(close,par2))
    if (shortCondition)
        strategy.entry("My Short Entry Id",strategy.short)
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      相关资源
      最近更新 更多