Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
725 views
in Technique[技术] by (71.8m points)

if statement - if Syntax in pine script

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'.

question from:https://stackoverflow.com/questions/65913271/if-syntax-in-pine-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...