0

i am unable to remove the syntax error at input. it is showing for below coding. Can someone check and send me back the running script without any syntax. it is for pine script in trading view. thanks for the help. The code is as below and the problem is occurring at : "if crossed" line, showing syntax error.

//@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)

1 Answer 1

0

When programming, every character counts. You had 3 spaces here instead of 4:

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

and under if crossed2 you had this:

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

instead of this:

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

There are only two characters changed but the code will not compile without them.

You were also missing a strategy() declaration statement at the beginning of your script. See the usrman on structuring scripts and on continuing lines. Complete code:

//@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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.