I'd like to plot the ratio between the close of the current symbol and the close of the S&P 500 'SPY' ETF. However, this ratio should be calculated ONLY on the DOWN days of the current symbol. When an UP day is encountered, the script should plot the ratio calculated on the LAST DOWN DAY, this way keeping the plotted line uninterrupted and unchanged.
Below you can see the code I have so far. The only problem is that on UP days, instead of plotting the ratio calculated on the last down day, it plots a ZERO (constantly breaking down the plotted line).
Can anyone help me, please? I'm new to Pine Scripting.
Thank you!
Alex
Code: Select all
study(title="My Script")
spy_close = security("SPY", period, close)
value = iff (close < close[1], close/spy_close, 0)
plot(value, color=black, transp=0)