#scale_adx_cpmo_0_100
#https://usethinkscript.com/threads/normalize-scale-for-adx-and-cpmo.16585/
#Questions UnAnswered Graveyard
#Normalize Scale for ADX and CPMO
#BrokeTeacher Sep 6, 2023
#I am looking for a way to change the scale units for ADX and CPMO in TOS, so they can be compatible with each other. The be more specific, ADX uses a (0 to 40) scale and CPMO uses a [(-2) to (2)] scale. Is it possible to code a way to make both a (0 to 100) scale? I would greatly appreciate any assistance.
#Hello! I am trying to find a way to standardize the units between two different TOS indicators - specifically ADX and CPMO. Specifically, ADX is mostly a range of (10 to 40) and CPMO is mostly a range of (-40 to 40). Is there a way to code them to both have the same range, like (0% to 100%)? I would greatly appreciate any help from the community. Thank you.
# ADX uses a 0 to 40
# CPMO uses a -2 to 2 ?
# out scale - 0 to 100
def na = Double.NaN;
def bn = barnumber();
script scale {
input inhi = 0;
input inlo = 0;
input outhi = 100;
input outlo = 0;
def inht = inhi - inlo;
def outht = outhi - outlo;
plot outoff = outlo - inlo;
plot outscale = outht/inht;
}
input newhi = 100;
input newlo = 0;
#-----------------------------
#adx
#declare lower;
input show_adx = yes;
input length = 14;
input averageType = AverageType.WILDERS;
def ADX = DMI(length, averageType).ADX;
#ADX.SetDefaultColor(GetColor(5));
#-----------------------------
# cpmo
#declare lower;
input show_cpmo = yes;
input length1 = 35;
input length2 = 20;
input signalLength = 10;
input secondarySymbol = "SPX";
def PrimaryPMO = reference PMO(price = close, length1 = length1, length2 = length2);
def SecondaryPMO = reference PMO(price = close(secondarySymbol), length1 = length1, length2 = length2);
#plot PrimarySignalLine = ExpAverage(PrimaryPMO, signalLength);
#plot SecondarySignalLine = ExpAverage(SecondaryPMO, signalLength);
#plot ZeroLine = 0;
#PrimaryPMO.SetDefaultColor(GetColor(1));
#SecondaryPMO.SetDefaultColor(GetColor(2));
#PrimarySignalLine.SetDefaultColor(GetColor(3));
#PrimarySignalLine.Hide();
#SecondarySignalLine.SetDefaultColor(GetColor(4));
#SecondarySignalLine.Hide();
#ZeroLine.SetDefaultColor(GetColor(7));
#-----------------------------
# scales
def adxhi;
def adxlo;
def cpmohi;
def cpmolo;
def adxoff;
def adxscale;
def cpmooff;
def cpmoscale;
if bn == 1 then {
adxhi = highestall(adx);
adxlo = lowestall(adx);
cpmohi = highestall(PrimaryPMO);
cpmolo = lowestall(PrimaryPMO);
# inhi, inlo, outhi, outlo
# newhi newlo
adxoff = scale(adxhi,adxlo,newhi,newlo).outoff;
adxscale = scale(adxhi,adxlo,newhi,newlo).outscale;
cpmooff = scale(cpmohi,cpmolo,newhi,newlo).outoff;
cpmoscale = scale(cpmohi,cpmolo,newhi,newlo).outscale;
} else {
adxhi = adxhi[1];
adxlo = adxlo[1];
cpmohi = cpmohi[1];
cpmolo = cpmolo[1];
adxoff = adxoff[1];
adxscale = adxscale[1];
cpmooff = cpmooff[1];
cpmoscale = cpmoscale[1];
}
#----------------------------
#plot zadx = if show_adx then adx else na;
plot zadx = if show_adx then ((adx + adxoff) * adxscale) else na;
zADX.SetDefaultColor(GetColor(5));
#plot zPrimaryPMO = if show_cpmo then PrimaryPMO else na;
plot zPrimaryPMO = if show_cpmo then ((PrimaryPMO + cpmooff) * cpmoscale) else na;
#plot zSecondaryPMO = if show_cpmo then SecondaryPMO else na;
zPrimaryPMO.SetDefaultColor(GetColor(1));
#zSecondaryPMO.SetDefaultColor(GetColor(2));
plot znewhi = newhi;
plot znewlo = newlo;
znewhi.SetDefaultColor(color.gray);
znewlo.SetDefaultColor(color.gray);
addlabel(1, "ADX", zadx.TakeValueColor());
addlabel(1, "CPMO", zPrimaryPMO.TakeValueColor());
input test1 = no;
addlabel(test1,"adx");
addlabel(test1, adxhi,color.yellow);
addlabel(test1, adxlo,color.yellow);
addlabel(test1, adxoff,color.yellow);
addlabel(test1, adxscale,color.yellow);
#