1
votes

After looking through the Pine-Script documentation I could not figure out there "Switch" style conditional statement.

I'm trying to subtract the opening and the closing from only the green candles.

This is my current code:

//@version=3 study(title="High Minus Low", shorttitle="HM0", overlay=true)

openall  = high[0]+high[1]+high[2]
closeall = open[0]+open[1]+open[2] total = openall + closeall

plot(total)

I only want to grab the latest 3 green candle bars using a conditional statement.

Is this possible?

1
Why don't you use nested if's? - Baris Yakut

1 Answers

1
votes

There is no "switch" statement in PineScript. However you may use 'if' statements for your task. For example

green_delta = 0.0
if close > open
    green_delta := open - close 
plot(green_delta)