Hello,
pls see the included screenshot of a 15min chart of $AMD with ZScore lower indicator.
The code of the Zscore indicator is included below:
-------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
As indicated in the screenshot, while price increased steeply for over 100minutes from the open, Zscore peaked at +3 standard deviations, at the end of the very first 15min candle..and started dropping steeply.
I'm not well versed with scripting, but is there a way to customize this indicator, to truly capture & display the price volatility (in standard deviations), up until the price actually starts stagnating(or reversing)? ( and not drop steeply like this one , even with steep upside volatility). You could argue, the subsequent candles , after the first 15min close, were not as huge and so Zscore is showing a decline in price volatility and is the expected behavior....,but I'm not using Zscore necessarily for divergences, but to reflect the actual price volatility , going to +4,+5 etc, as needed.
So in this case, would like the Zscore plot to move up in tandem with the price (even at a lower rate/angle to reflect reduced volatility compared to the first candle) and only decline when the price stagnates/enters a range (or reverses). Yes, I can use other indicators like RSI or Stochastics to reflect price momentum, but wanted to see if we can adjust Zscore, as mentioned above.
Any help appreciated.
Thanks again
Here's another example of what I'm referring to, with ZScore. Today's $TSLA sell-off from the open, on a 15min chart.
ZScore went into an oversold zone and hit its lowest SD (-2.8) on the 2nd 15min candle and started reversing up..,while the price volatility to the downside continued,until 10:30am.
I do have Bollinger Bands plotted on my production 15min chart , that can show the unbounded volatility to either side, but need this to be a lower study.
In "normal" volatility conditions, in most cases a standard deviation of 2-3 puts the price into overbought(or oversold) conditions and allows for mean reversion trades, but this fails when there is a big move, such as the examples included. I dont mind, having a couple of ZScore studies, one for normal conditions with 2-3 as overbought/oversold and another for big moves, but either way, need the Zscore plot to go beyond the the current max values shown.
pls see the included screenshot of a 15min chart of $AMD with ZScore lower indicator.

The code of the Zscore indicator is included below:
-------------------------------------------------------------------------------------------------------------
Code:
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 avgZscore = average(Zscorevalue,ZavgLength);
avgZscore.setPaintingStrategy(paintingStrategy.LINE);
plot Zscore = ((price-avgClose)/oneSD);
Zscore.setPaintingStrategy(paintingStrategy.HISTOGRAM);
Zscore.setLineWeight(2);
#Zscore.assignValueColor(if Zscore > 0 then color.green else color.red);
#Diff.SetDefaultColor(GetColor(5));
Zscore.DefineColor("Positive and Up", Color.DARK_GREEN);
Zscore.DefineColor("Positive and Down", Color.LIGHT_GREEN);
Zscore.DefineColor("Negative and Down", Color.DARK_RED);
Zscore.DefineColor("Negative and Up", Color.ORANGE);
Zscore.AssignValueColor(if Zscore >= 0 then if Zscore > Zscore[1] then Zscore.color("Positive and Up") else Zscore.color("Positive and Down") else if Zscore < Zscore[1] then Zscore.color("Negative and Down") else Zscore.color("Negative and Up"));
#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 two = 2;
plot one = 1;
plot negone = -1;
plot negtwo = -2;
def three = 3;
def negthree = -3;
zero.setDefaultColor(color.yellow);
two.setDefaultColor(color.red);
one.setDefaultColor(color.orange);
negone.setDefaultColor(color.light_green);
negtwo.setDefaultColor(color.green);
AddCloud(three, two, Color.dark_RED, Color.CURRENT);
AddCloud(negtwo, negthree, Color.dark_GREEN, Color.CURRENT);
As indicated in the screenshot, while price increased steeply for over 100minutes from the open, Zscore peaked at +3 standard deviations, at the end of the very first 15min candle..and started dropping steeply.
I'm not well versed with scripting, but is there a way to customize this indicator, to truly capture & display the price volatility (in standard deviations), up until the price actually starts stagnating(or reversing)? ( and not drop steeply like this one , even with steep upside volatility). You could argue, the subsequent candles , after the first 15min close, were not as huge and so Zscore is showing a decline in price volatility and is the expected behavior....,but I'm not using Zscore necessarily for divergences, but to reflect the actual price volatility , going to +4,+5 etc, as needed.
So in this case, would like the Zscore plot to move up in tandem with the price (even at a lower rate/angle to reflect reduced volatility compared to the first candle) and only decline when the price stagnates/enters a range (or reverses). Yes, I can use other indicators like RSI or Stochastics to reflect price momentum, but wanted to see if we can adjust Zscore, as mentioned above.
Any help appreciated.
Thanks again
Here's another example of what I'm referring to, with ZScore. Today's $TSLA sell-off from the open, on a 15min chart.

ZScore went into an oversold zone and hit its lowest SD (-2.8) on the 2nd 15min candle and started reversing up..,while the price volatility to the downside continued,until 10:30am.
I do have Bollinger Bands plotted on my production 15min chart , that can show the unbounded volatility to either side, but need this to be a lower study.
In "normal" volatility conditions, in most cases a standard deviation of 2-3 puts the price into overbought(or oversold) conditions and allows for mean reversion trades, but this fails when there is a big move, such as the examples included. I dont mind, having a couple of ZScore studies, one for normal conditions with 2-3 as overbought/oversold and another for big moves, but either way, need the Zscore plot to go beyond the the current max values shown.
Last edited by a moderator: