Can anyone help me to modify the Z-Score indicator (see below) such that it will plot the Z-Score for the following ((AAPL+MSFT+AMZN+GOOG+FB+TSLA)/6) in a subgraph below a chart of the NASDAQ 100 Index (NDX). I’ve made numerous attempts but have been unsuccessful. Thanks!
Code:
#Computes and plots the Zscore
#Provided courtesy of ThetaTrend.com
#Feel free to share the indicator, but please provide a link back to ThetaTrend.com
declare lower;
input price = close;
input length = 20;
input ZavgLength = 20;
#Initialize values
def oneSD = stdev(price,length);
def avgClose = simpleMovingAvg(price,length);
def ofoneSD = oneSD*price[1];
def Zscorevalue = ((price-avgClose)/oneSD);
def avgZv = average(Zscorevalue,20);
#Compute and plot Z-Score
plot Zscore = ((price-avgClose)/oneSD);
Zscore.setPaintingStrategy(paintingStrategy.HISTOGRAM);
Zscore.setLineWeight(2);
Zscore.assignValueColor(if Zscore > 0 then color.dark_green else color.dark_green);
plot avgZscore = average(Zscorevalue,ZavgLength);
avgZscore.setPaintingStrategy(paintingStrategy.LINE);
#This is an optional plot that will display the momentum of the Z-Score average
#plot momZAvg = (avgZv-avgZv[5]);
#Plot zero line and extreme bands
plot zero = 0;
plot one = 1;
plot negone = -1;
plot two = 2;
plot negtwo = -2;
zero.setDefaultColor(color.black);