Normalized Volume Zone Oscillator and MovAvgExp

Ficus

New member
Hello ,

I'm trying to create a normalized (no negative values) version of the volume zone oscillator's exponential moving average. I mushed together some normalizing code with the indicator, and I get no errors but the values are still negative. Since I have tried several times I think I will just ask your input. If you know of any similar indicators that would be great. So far this one seems to have a good personality when it interacts with fractal energy and the laguerre RSI, but the indicator is too erratic by itself.

I'd like to build a scan that can be run as a lower study, but the values don't fit for a "crossover" if they're not normalized - am I right? I am also not sure they will scale properly if you zoom in and have them laid on top of each other.
If there's any way to easily add it (and its movavgexp) to the "Laguerre time", I wonder what that would look like.

In the end I hope to have Laguerre RSI, Fractal Energy, Volume Zone Oscillator, and the Volume Zone Oscillator MovAvgExp on the same lower study, which I can run / write a crossover scan for it. I'm not sure if they all need to be on the same study to work properly for these different uses.

Code:
declare lower;

input length = 14;

script normalizePlot {
    input data = close;
    input newRngMin =  -1;
    input newRngMax = 1;
    def hhData = HighestAll( data );
    def llData = LowestAll( data );
    plot nr = ((( newRngMax - newRngMin ) * ( data - llData )) / ( hhData - llData )) + newRngMin;
}

script VZOScr {
   input Length = 13;
   def VP = ExpAverage(Sign(close - close[1]) * volume, length);
   def TV = ExpAverage(volume, length);
   plot VZO = 100 * VP / TV;
}

plot VZOX = normalizePlot(VZOScr("Length" = Length), -100, 100);
 
Last edited:

BenTen

Administrative
Staff
VIP
At one point in the future, you'll realize that some indicators can not be merged. An example of that would be something like the RSI and a moving average. It's like mixing oil with water. I hope that helps.
 

Ficus

New member
plot VZOX = normalizePlot(VZOScr("Length" = Length), 0, 100);

I think that did what I was thinking of.. but I appreciate the feedback. This might not lead anywhere, but it is interesting.
 

Ficus

New member
I was able to normalize all the studies together. These can also be turned into individual studies to use as scans.
I'm still mixed on the usefulness of it but I am seeing that a high (descending) wave of Fractal Energy moving average seems to carry any VZO breakouts.

Code:
declare lower;

#VolumeZoneOscillatorMovAvgExp#
#
# TD Ameritrade IP Company, Inc. (c) 2011-2020
#

input VAvlength = 9;

script normalizePlot {
    input data = close;
    input newRngMin =  -1;
    input newRngMax = 1;
    def hhData = HighestAll( data );
    def llData = LowestAll( data );
    plot nr = ((( newRngMax - newRngMin ) * ( data - llData )) / ( hhData - llData )) + newRngMin;
}

script VZOScr {
    input Length = 13;
    input displace = 0;
    def VP = ExpAverage(Sign(close - close[1]) * volume, Length);
    def TV = ExpAverage(volume, Length);
    def VZO = 100 * VP / TV;
    def price = VZO;
    plot VZOavg = ExpAverage(price[-displace], Length);
}

plot VZOavgX = normalizePlot(VZOScr("Length" = VavLength), 0, 100);

VZOavgX.SetDefaultColor(Color.MAGENTA);
VZOavgX.SetLineWeight(3);

#VolumeZoneOscillator#
#
# TD Ameritrade IP Company, Inc. (c) 2011-2020
#


input Vlength = 9;

script normalizePlot {
    input data = close;
    input newRngMin =  -1;
    input newRngMax = 1;
    def hhData = HighestAll( data );
    def llData = LowestAll( data );
    plot nr = ((( newRngMax - newRngMin ) * ( data - llData )) / ( hhData - llData )) + newRngMin;
}

script VZOScr {
    input Length = 13;
    def VP = ExpAverage(Sign(close - close[1]) * volume, Length);
    def TV = ExpAverage(volume, Length);
    plot VZO = 100 * VP / TV;
}

plot VZOX = normalizePlot(VZOScr("Length" = VLength), 0, 100);
VZOX.SetDefaultColor(Color.PINK);


# RSI-Laguerre Self Adjusting With Fractal Energy Gaussian Price Filter
# Mobius
# V01.12.2016
# Both Fractal Energy and RSI are plotted. RSI in cyan and FE in yellow. Look for trend exhaustion in the FE and a reversal of RSI or Price compression in FE and an RSI reversal.
#  https://usethinkscript.com/threads/rsi-in-laguerre-time-self-adjusting-with-fractal-energy-usage-notes.219/

#Inputs:
# RSI-Laguerre Self Adjusting With Fractal Energy Gaussian Price Filter
# Mobius
# V01.12.2016
# Both Fractal Energy and RSI are plotted. RSI in cyan and FE in yellow. Look for trend exhaustion in the FE and a reversal of RSI or Price compression in FE and an RSI reversal.
#  https://usethinkscript.com/threads/rsi-in-laguerre-time-self-adjusting-with-fractal-energy-usage-notes.219/


#Inputs:
input nFE = 8;#hint nFE: length for Fractal Energy calculation.
input AlertOn = no;
input Glength  = 13;
input betaDev =  8;
input data = close;


script normalizePlot {
    input data = close;
    input newRngMin =  -1;
    input newRngMax = 1;
    def hhData = HighestAll( data );
    def llData = LowestAll( data );
    plot nr = ((( newRngMax - newRngMin ) * ( data - llData )) / ( hhData - llData )) + newRngMin;
}

script RSIScr {

#Inputs:
input nFE = 8;#hint nFE: length for Fractal Energy calculation.
input AlertOn = no;
input Glength  = 13;
input betaDev =  8;
input data = close;

def w = (2 * Double.Pi / Glength);
def beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDev) - 1 );
def alpha = (-beta + Sqrt(beta * beta + 2 * beta));
def Go = Power(alpha, 4) * open +
             4 * (1 – alpha) * Go[1] – 6 * Power( 1 - alpha, 2 ) * Go[2] +
             4 * Power( 1 - alpha, 3 ) * Go[3] - Power( 1 - alpha, 4 ) * Go[4];
def Gh = Power(alpha, 4) * high +
             4 * (1 – alpha) * Gh[1] – 6 * Power( 1 - alpha, 2 ) * Gh[2] +
             4 * Power( 1 - alpha, 3 ) * Gh[3] - Power( 1 - alpha, 4 ) * Gh[4];
def Gl = Power(alpha, 4) * low +
             4 * (1 – alpha) * Gl[1] – 6 * Power( 1 - alpha, 2 ) * Gl[2] +
             4 * Power( 1 - alpha, 3 ) * Gl[3] - Power( 1 - alpha, 4 ) * Gl[4];
def Gc = Power(alpha, 4) * data +
             4 * (1 – alpha) * Gc[1] – 6 * Power( 1 - alpha, 2 ) * Gc[2] +
             4 * Power( 1 - alpha, 3 ) * Gc[3] - Power( 1 - alpha, 4 ) * Gc[4];
# Variables:
def o;
def h;
def l;
def c;
def CU1;
def CU2;
def CU;
def CD1;
def CD2;
def CD;
def L0;
def L1;
def L2;
def L3;
plot RSI;
plot OS;
plot OB;
plot M;

# Calculations
o = (Go + Gc[1]) / 2;
h = Max(Gh, Gc[1]);
l = Min(Gl, Gc[1]);
c = (o + h + l + Gc) / 4;
plot gamma = Log(Sum((Max(Gh, Gc[1]) - Min(Gl, Gc[1])), nFE) /
        (Highest(gh, nFE) - Lowest(Gl, nFE)))
            / Log(nFE);
gamma.SetDefaultColor(Color.Yellow);
L0 = (1 – gamma) * Gc + gamma * L0[1];
L1 = -gamma * L0 + L0[1] + gamma * L1[1];
L2 = -gamma * L1 + L1[1] + gamma * L2[1];
L3 = -gamma * L2 + L2[1] + gamma * L3[1];
if L0 >= L1
then {
    CU1 = L0 - L1;
    CD1 = 0;
} else {
    CD1 = L1 - L0;
    CU1 = 0;
}
if L1 >= L2
then {
    CU2 = CU1 + L1 - L2;
    CD2 = CD1;
} else {
    CD2 = CD1 + L2 - L1;
    CU2 = CU1;
}
if L2 >= L3
then {
    CU = CU2 + L2 - L3;
    CD = CD2;
} else {
    CU = CU2;
    CD = CD2 + L3 - L2;
}

RSI = if CU + CD <> 0 then CU / (CU + CD) else 0;
RSI.SetDefaultColor(Color.Cyan);
RSI.SetLineWeight(3);
OS = if IsNaN(c) then Double.NaN else 0.2;
OS.SetDefaultColor(Color.RED);
OS.HideBubble();
OS.HideTitle();
OB = if IsNaN(c) then Double.NaN else 0.8;
OB.SetDefaultColor(Color.GREEN);
OB.HideBubble();
OB.HideTitle();
M = if IsNaN(c) then Double.NaN else 0.5;
M.SetStyle(Curve.long_dash);
M.SetDefaultColor(Color.Gray);
M.HideBubble();
M.HideTitle();
def FEh = if isNaN(c) then double.nan else .618;

def FEl = if isNaN(c) then double.nan else .382;
plot RSINorm = RSI;
}

plot RSIX = normalizePlot(RSIScr("nFE" = nFE, "AlertOn" = AlertOn, "Glength" = Glength, "betaDev" = betaDev, "data" = data), 0, 100);
RSIX.setDefaultColor(color.CYAN);
RSIX.setlineWeight(1);

# End Code RSI_Laguerre Self Adjusting with Fractal Energy
#######################################

###############################################
#
# TD Ameritrade IP Company, Inc. (c) 2017-2020
#Fractal Energy Movavgexponential





def displace = 0;
input FELength = 10;

###normalize###
script normalizePlot {
    input data = close;
    input newRngMin =  -1;
    input newRngMax = 1;
    def hhData = HighestAll( data );
    def llData = LowestAll( data );
    plot nr = ((( newRngMax - newRngMin ) * ( data - llData )) / ( hhData - llData )) + newRngMin;
}

script FEAvgScr {
    input Length = 10;
    def displace = 0;
    def sumTR = Sum (TrueRange(high, close, low), Length);
    def HMax =  Highest (high, Length);
    def LMax =  Lowest (low, Length);
    def FE = 100 * Log (sumTR / (HMax - LMax)) / Log(Length);
    def price = FE;
    plot FEnormExp = ExpAverage(price[-displace], Length);
}


plot FEavg = normalizePlot(FEAvgScr("Length" = FELength), 0, 100);
FEavg.setDefaultColor(color.LIGHT_GRAY);
FEavg.setLineWeight(3);
 

Similar threads

Top