Stock Cumulative Percent Change
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SlinginTrades modified from @ connorwinemil

//@version=5
indicator("Stock Cumulative Percent Change", timeframe='', timeframe_gaps=false, overlay=false)
tf = timeframe.period
//tf = input.timeframe('', "TimeFrame", options=['','1','5','15','30','60','120','D','W','M'])
ma_period = input.int(5,"MA Period")

openTime = input.session("0930-0935", "Open time")
closeTime = input.session("1600-2400", "Close time")
premarketTime = input.session("0000-0930", "PreMarket time")

// Returns non 'na' value when in session.
trigger = not na(time(timeframe.period, openTime))
trigger2 = not na(time(timeframe.period, closeTime))
trigger3 = not na(time(timeframe.period, premarketTime))
// Detect when reset time is hit.
reset = (trigger and not trigger[1]) or (trigger2) or trigger3

stock1 = input.symbol(defval="AAPL", title="Symbol 1")
stock2 = input.symbol(defval="MSFT", title="Symbol 2")
stock3 = input.symbol(defval="AMZN", title="Symbol 3")
stock4 = input.symbol(defval="TSLA", title="Symbol 4")
stock5 = input.symbol(defval="GOOGL", title="Symbol 5")
stock6 = input.symbol(defval="NVDA", title="Symbol 6")
stock7 = input.symbol(defval="MSFT", title="Symbol 7")


stock1_pctchange = ((request.security(stock1, tf, close)/request.security(stock1, tf, close[1]))-1)*100
stock2_pctchange = ((request.security(stock2, tf, close)/request.security(stock2, tf, close[1]))-1)*100
stock3_pctchange = ((request.security(stock3, tf, close)/request.security(stock3, tf, close[1]))-1)*100
stock4_pctchange = ((request.security(stock4, tf, close)/request.security(stock4, tf, close[1]))-1)*100
stock5_pctchange = ((request.security(stock5, tf, close)/request.security(stock5, tf, close[1]))-1)*100
stock6_pctchange = ((request.security(stock6, tf, close)/request.security(stock6, tf, close[1]))-1)*100
stock7_pctchange = ((request.security(stock7, tf, close)/request.security(stock7, tf, close[1]))-1)*100

cum = 0.0
val = math.avg(2 * stock1_pctchange,stock2_pctchange,stock3_pctchange,stock4_pctchange,stock5_pctchange,stock6_pctchange,stock7_pctchange)

cum := reset ? 0 : cum[1] + val

ma = ta.sma(cum,ma_period)

plot(cum, color=cum>0 ? cum > cum[1]? color.green: color.yellow:cum< cum[1]?color.red:color.yellow, style=plot.style_columns)
plot(ma,color=ma > 0? color.green:color.red)
alertcondition(ta.crossover(ma,0),title="Momentum Shift Up", message="Momentum Over 0")
alertcondition(ta.crossunder(ma,0),title="Momentum Shift Down", message="Momentum Under 0")


