0

I'm new to pinescript and I can't figure out what's wrong with my if syntax. Please help

//@version=4

strategy(title="Weighted Moving ATR", shorttitle="WMATR Stra Test", overlay = true)

//Changing inputs based on ticker
if (syminfo.ticker == "AAPL")
     LenWATR = 43
     MultWATR = 1
else if (syminfo.ticker == "AAL")
     LenWATR = 21
     MultWATR = 1

I keep getting line 13: Mismatched input 'LenWATR' expecting 'end of line without line continuation'.

1
  • Thanks to @bajaco & @ Bjorn Mistiaen. I got it to work! But now is there a way I can debug it to know the LenWATR & MultWATR is the correct value when it's AAPL or AAL? Commented Jan 29, 2021 at 0:43

2 Answers 2

0

The reason you're getting the error is because the indentation is wrong.
You're indenting with 5 whitespaces, but indententations should be a multiple of 4 whitespaces.

You could also write it like this:

//@version=4
strategy(title="Weighted Moving ATR", shorttitle="WMATR Stra Test", overlay = true)

var int LenWATR  = na
var int MultWATR = na

//Changing inputs based on ticker
LenWATR := if syminfo.ticker == "AAPL" 
    43
else if syminfo.ticker == "AAL"
    1
else
    99 // default value

MultWATR := if syminfo.ticker == "AAL" 
    1
else if syminfo.ticker == "AAL"
    1
else
    77 // default value

//Changing inputs based on ticker: short version
LenWATR  := syminfo.ticker == "AAPL" ? 43 : syminfo.ticker == "AAL" ? 1 : 99
MultWATR := syminfo.ticker == "AAPL" ?  1 : syminfo.ticker == "AAL" ? 1 : 77

plot(na)
2
  • Thanks for pointing that out. I had used 4 spaces before and it didn't work for overflow line, I had to use 5, that's why I use 5 here. Now that I used 4 spaces, the error is now said now it said "Syntax error at input 'syminfo.ticker'" Do you know how I'm suppose to use the info from syminfo.ticker? Aslo I use == instead of = now Commented Jan 29, 2021 at 0:38
  • Please show your entire script to see what's wrong. Commented Jan 29, 2021 at 7:50
0

You don't need parenthesis. Also if you are using = in your if statement blocks you are initializing variables in a local scope. If the variables exist elsewhere value assignment should use :=

1
  • I took the parenthese off and now it said "Syntax error at input 'syminfo.ticker'" I thought this is a reserved variable and if my ticker is "AAL" it should be true and execute the line. Do you know how I'm suppose to use the info from syminfo.ticker ? Commented Jan 29, 2021 at 0:33

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.