'How to encode "Pin to scale" (Z) into Pine Script? V5
In my development process, I am embedding indicators (2 RSIs) into my own indicator. But in that manual case I am working based on, one of them must be joined to the other (Move to existing pane … in TradingView's context-menu), then for the other one, for matching their scale, Pin to scale must be set to Z.
How can we do the same in the script?
Here's my (not spotless but technically functional) double RSI code, if needed:
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"Bollinger Bands" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
maTypeInput = "SMA"
maLengthInput = input.int(14, title="MA Length", group="MA Settings")
bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="MA Settings")
up100 = ta.rma(math.max(ta.change(rsiSourceInput), 0), 100)
down100 = ta.rma(-math.min(ta.change(rsiSourceInput), 0), 100)
rsi100 = down100 == 0 ? 100 : up100 == 0 ? 0 : 100 - (100 / (1 + up100 / down100))
rsiMA100 = ma(rsi100, 100, maTypeInput)
up25 = ta.rma(math.max(ta.change(rsiSourceInput), 0), 25)
down25 = ta.rma(-math.min(ta.change(rsiSourceInput), 0), 25)
rsi25 = down25 == 0 ? 100 : up25 == 0 ? 0 : 100 - (100 / (1 + up25 / down25))
rsiMA25 = ma(rsi25, 25, maTypeInput)
I've tried an idea came to my mind but couldn't get the same graph result compared to what we can see on the manually joined and scaled graphs. Here's my fail below. The lower double RSI pane shows the sample, the upper double RSI pane shows my failed attempt. I thought that I simply have to multiple the 25s RSI by 4 (because 100/25…).

Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

