#PLOTTING PERCENTAGE DIFFERENCE BETWEEN TWO SYMBOLS FROM REGULAR TRAING HOURS OPEN
# **** WORKS ON INTRADAY CHART ONLY ****
# **** WORKS ON INTRADAY CHART ONLY ****
# **** WORKS ON INTRADAY CHART ONLY ****
#NOTE: This may study may not work well outside of regular trading hours or using tickers/securities with missing 1 minute bars.
#Works best with extended hours off (not visible) on chart and during the regular trading hours.
#
input symbol_1 = "AAPL";
input symbol_2 = "SPY";
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD());
def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
def openprice1 = if firstBarOfDay then open(symbol_1) else openprice1[1];
def openprice2 = if firstBarOfDay then open(symbol_2) else openprice2[1];
def closeprice1 = close(symbol_1);
def closeprice2 = close(symbol_2);
def return1 = 100 * (closeprice1 - openprice1) / openprice1;
def return2 = 100 * (closeprice2 - openprice2) / openprice2;
plot dif = return1 - return2;
AddLabel(yes, "difference: " + Round(dif) + "%" );