{QG}Spread Candelsticks
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © QuantG

//@version=5
indicator("QG-Spread Candelsticks")

instrument1 = input.string(defval="NQ1!",title='Instrument1')
instrument2 = input.string(defval="ES1!",title='Instrument2')
mult1 = input.float(defval = 2.0,title='Multiplier1')
mult2 = input.float(defval = 5.0,title='Multiplier2')

var color bullColor = input(title='Bull Color', defval=#26a69a)
var color bearColor = input(title='Bear Color', defval=#ef5350)
candleColor = close >= open ? bullColor : bearColor



calculateSpread(t1, t2, Mult1, Mult2, source) =>
    s1 = request.security(t1, timeframe.period, source)*Mult1
    s2 = request.security(t2, timeframe.period, source)*Mult2
    s1 - s2



_open = calculateSpread(instrument1,instrument2,mult1,mult2,open)
_high = calculateSpread(instrument1,instrument2,mult1,mult2,high)
_low = calculateSpread(instrument1,instrument2,mult1,mult2,low)
_close = calculateSpread(instrument1,instrument2,mult1,mult2,close)

plotcandle(_open, _high, _low, _close, title='Value Candle', color=candleColor, bordercolor=candleColor, wickcolor=color.white)

plot(_close, title='🔌SpreadCandelsticks🔌',display= display.none)
