NQ vs ES
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © deivydas.rapalis

//@version=5
indicator("NQ vs ES", overlay = true)

// Calculate the price change percentage for ES and NQ
esPriceChange = ((request.security("ES1!", "D", close) - request.security("ES1!", "D", close[1])) / request.security("ES1!", "D", close[1])) * 100
nqPriceChange = ((request.security("NQ1!", "D", close) - request.security("NQ1!", "D", close[1])) / request.security("NQ1!", "D", close[1])) * 100

// Calculate the spread between NQ and ES price change percentages
spread = nqPriceChange - esPriceChange

// Plot ES price change percentage
plot(esPriceChange, title = "ES", color = color.green)

// Plot NQ price change percentage
plot(nqPriceChange, title = "NQ", color = color.red)

// Plot spread between NQ and ES price change percentages
plot(spread, title = "Spread", color = color.yellow)

// Plot a 0 value line
hline(0, "Zero Line", color = color.gray)
