I have a script that plots price lines based on some calculations, however I am currently defining variables based on inputs. The goal here is to define variables dynamically based on the current symbol.
Example
For some reason, this logic is displaying "Invalid statement: if at 1:1" and "Syntax error: Semicolon expected at 1:1". Can anyone help? I really can't tell what I am missing, or if switch statement would be better.
I was able to accomplish something in the meantime, however I am not sure this is the most efficient way of defining the variables:
Example
- If the current symbol is AMD, define Price1 as 50 and Price2 as 20.
- If the current symbol is SPX, define Price1 as 3000 and Price2 as 2900.
For some reason, this logic is displaying "Invalid statement: if at 1:1" and "Syntax error: Semicolon expected at 1:1". Can anyone help? I really can't tell what I am missing, or if switch statement would be better.
Code:
if GetSymbol() == "SPX" {
Price1 = "2900";
Price2 = "3000";
} else
if GetSymbol() == "AMD" {
Price1 = "50";
Price2 = "20";
} else {
Double.NaN;
}
I was able to accomplish something in the meantime, however I am not sure this is the most efficient way of defining the variables:
Code:
def Price1 = if (GetSymbol() == "AMD") then 50
else if (GetSymbol() == "SPX") then 2900
else if (GetSymbol() == "SPY") then 290
else if (GetSymbol() == "AAPL") then 286
else if (GetSymbol() == "STZ") then 164
else Double.NaN;
def Price2 = if (GetSymbol() == "AMD") then 20
else if (GetSymbol() == "SPX") then 3000
else if (GetSymbol() == "SPY") then 300
else if (GetSymbol() == "AAPL") then 292
else if (GetSymbol() == "STZ") then 168
else Double.NaN;