#### DYLDAUB JANUARY 2021 #######
# length and type of the same bar price difference MA.
input avgLength = 5;
input avgType = {SMA, EMA, WLD, INE, default AMA};
# overbought and oversold are visual aids.
# overbought with be drawn when OHLC are the same,
# and oversold will be drawn when they are not the same.
input overbought = 1.0;
input oversold = -1.0;
# weighting of flat bars to close, meaning if current bar is
# ...not flat then adjust price histogram by the weighted close.
# Set to zero to force previous flat bar value
# ...to be used, and not weight by close.
input weight = 2;
## VROC
def day = GetDay();
def isNewDay = day != day[1];
# volume displacement length, and std. dev. average length.
input vrocLength = 14;
# increment spike counters by this amount.
input vrocInc = 0.4;
# num. of std. deviations for signaling larger spikes.
input NumDevUp = 3.5;
# use a line for the VROC spike signal instead of plot.
input useLinesForVROC = No;
# increase or decrease (make negative) to adjust VROC signal location.
input vrocSigOffset = 1.0;
def tVROC = if volume[vrocLength] <> 0 then (volume / volume[vrocLength] - 1) else 0;
def isSpike = tVROC < tVROC[1] and tVROC[1] > tVROC[2];
# store the previous tVROC value because that's the peak.
def spikes = if isSpike then tVROC[1] else spikes[1];
def rHSpikes = if isNewDay then vrocInc else if isSpike and tVROC[1] > spikes[1] then rHSpikes[1] + vrocInc else rHSpikes[1];
def rLSpikes = if isNewDay then vrocInc else if isSpike and tVROC[1] < spikes[1] then rLSpikes[1] + vrocInc else rLSpikes[1];
plot SpikeDiff = rHSpikes - rLSpikes;
SpikeDiff.AssignValueColor(if SpikeDiff > 0 then Color.CYAN else Color.MAGENTA);
# Standard deviation of VROC spike.
def sDev = StDev(tVROC, vrocLength);
def upperVROC = Average(tVROC, vrocLength) + NumDevUp * sDev;
plot VROCSpike = if !useLinesForVROC and tVROC > upperVROC then overbought + vrocSigOffset else Double.NaN;
VROCSpike.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
VROCSpike.HideBubble();
VROCSpike.HideTitle();
VROCSpike.AssignValueColor(SpikeDiff.TakeValueColor());
AddVerticalLine(useLinesForVROC and tVROC > upperVROC, "", SpikeDiff.TakeValueColor(), 3);
## VOLUME SPIKES
# determines type of volume spike signals.
# Off is no display, StdDev is using std. deviations,
# HighVol is using spikes above highest average.
input volumeSignals = {Off, default StdDev, HighVol};
# use a line for the volume spike signal instead of plot.
input useLinesForVolume = No;
# increase or decrease (make negative) to adjust VROC signal location.
input volumeSigOffset = 0.5;
# spectrum color displacement and std. dev. average length for volume.
input volumeLength = 10;
def isUU = close > close[volumeLength] and volume > volume[volumeLength];
def isUD = close > close[volumeLength] and volume < volume[volumeLength];
def isDU = close < close[volumeLength] and volume < volume[volumeLength];
def isDD = close < close[volumeLength] and volume > volume[volumeLength];
# num. of std. deviations for volume spikes.
input volNumDevUp = 2.75;
def sDevVol = StDev(volume, volumeLength);
def volUpper = if volumeSignals == volumeSignals.StdDev then Average(volume, volumeLength) + volNumDevUp * sDevVol else Highest(volume[1], volumeLength);
def isVolumeSpike = volumeSignals != volumeSignals.Off and volume > volUpper;
plot VolumeSpike = if !useLinesForVolume and isVolumeSpike then overbought + volumeSigOffset else Double.NaN;
VolumeSpike.SetPaintingStrategy(PaintingStrategy.SQUARES);
VolumeSpike.SetLineWeight(3);
VolumeSpike.HideBubble();
VolumeSpike.HideTitle();
VolumeSpike.AssignValueColor(if isUU then Color.GREEN else if isUD then Color.BLUE else if isDU then Color.ORANGE else if isDD then Color.RED else Color.GRAY);
AddVerticalLine(useLinesForVolume and isVolumeSpike, "SPIKE", if isUU then Color.GREEN else if isUD then Color.BLUE else if isDU then Color.ORANGE else if isDD then Color.RED else Color.GRAY, 2);