Reputation: 13
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?
Upvotes: 1
Views: 7114
Reputation: 671
Pinescript v5 supports switch
statements: https://www.tradingview.com/pine-script-reference/v5/#op_switch
Upvotes: 0
Reputation: 852
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)
Upvotes: 1