Yield Spread Histogram
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AJMourot

//@version=5
indicator("Yield Spread Candles", shorttitle="Yield Spread", overlay=true)

// Fetch data for "US10Y-US02Y"
yieldSpread = request.security("US10Y-US02Y", "D", close)

// Calculate color based on yield spread value
candleColor = yieldSpread > 0 ? color.new(color.green, 0) : color.new(color.red, 0)

// Plot colored candles
plot(open, color=candleColor, style=plot.style_histogram, linewidth=0)
plot(close, color=candleColor, style=plot.style_histogram, linewidth=1)

// Plot yield spread histogram filling entire space
plot(yieldSpread, color=candleColor, style=plot.style_histogram, linewidth=0)

// Plot white line across zero
plot(0, color=color.new(color.white, 0), linewidth=2, title="Zero Line")
