Normalize Scale for ADX and CPMO

BrokeTeacher

New member
Hello,

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.
 
Hello,

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. hal_scale

i found this and thought it might be interesting to others
there probably are other scaling studies, but i decided to do this anyway.

this allows user to enter a new range max and min, to scale to. default is 0 to 100
on the first bar, this finds the highest and lowest values of 2 studies , adx and cpmo. (just 1 from cpmo).
then calculates the scaling to a new range.
i think running highestall() code on just bar #1, instead of all the bars, it should reduce the stress on the CPU...


Code:
#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);
#
 

Attachments

  • Capture.JPG
    Capture.JPG
    46.5 KB · Views: 35

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
298 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top