taylor_o Updated   
This script helps assess the relative returns of each leg in a two-legged spread. It shows the z-score of each period's returns, along with a moving average of the difference between the two returns. A negative moving average implies that the second leg is strengthening, on a relative return basis, against the first leg, and vice versa. The inputs are:

- timeframe: the timeframe for the calculations. the default is five minutes.
- leg1_sym: the symbol for the first leg
- leg2_sym: the symbol for the second leg
- ma_length: the length of the moving average. by default it is 48, or the previous four hours, given the default timeframe.

The default symbols are RB and HO, simply as an example of an intercommodity spread.
Release Notes:
- made lines transparent so they don't block each other
- added 0 line
Release Notes:
- set background faint pink if returns have different signs
Release Notes:
- colored background faint blue if leg1 advances while leg 2 declines, and orange if leg 2 advances and leg 1 declines
Release Notes:
- moving average line is blue if above 0 (leg1 returns strengthening relative to leg 2), orange if below (opposite).
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.


The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?