How to create an unbounded Max input in a normalizePlot() script?

netarchitech

Well-known member
Given the following normalizing script:

Code:
script normalizePlot {
    input data   = close;
    input Min    = 0;
    input Max = 100;
    input length = 50;
    def hhData   = Highest(data, length);
    def llData   = Lowest(data, length);
    plot resized = (((Max - Min) * (data - llData)) /
                       (hhData - llData)) + Min;
}

Is there a way to create an unbounded Max input while the Min input remains at zero? Essentially I want to take input Max = 100; and remove the 100 limitation to provide for max values well in excess of 100...

For example, let's say I need to normalize a Volume plot...a Max input value of 100 is obviously not going to cut it. If I hard-code in an arbitrary amount...say 1,000,000...I'll be capping the Volume and preventing the proper display of any values in excess of 1,000,000...

Code:
declare lower;

script normalizePlot {
    input data   = close;
    input Min    = 0;
    input Max    = 1000000;
    input length = 50;
    def hhData   = Highest(data, length);
    def llData   = Lowest(data, length);
    plot resized = (((Max - Min) * (data - llData)) /
                       (hhData - llData)) + Min;
}

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;

# Unfilled Gap down: Use prior close as high
def equivHi = if H < C[1] then C[1] else H;
# Unfilled Gap up: Use prior close as low
def equivLo = if L > C[1] then C[1] else L;

def Buying2 = Round(V * (C - equivLo) / (equivHi - equivLo), 0);
def Selling2 = Round(V * (equivHi - C) / (equivHi - equivLo), 0);

# Selling Volume
plot SV2 = normalizePlot(Selling2);
SV2.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SV2.SetDefaultColor(CreateColor(0, 82, 184));
SV2.SetLineWeight(1);
#SV2.hide();

# Buying Volume
plot BV2 = normalizePlot(Buying2);
BV2.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BV2.SetDefaultColor(CreateColor(0, 182, 254));
BV2.SetLineWeight(5);
#BV2.hide();

202307311025_a_.png


There are a number of volume values above in excess of 1,000,000 being cut off..Do you think there might be a workaround?

Thanks in advance for your time and anticipated potential feedback/solution to this matter. It is much appreciated :cool:
 
@netarchitech, you already know this; but for other readers of this thread:

The normalized plot subroutine is for changing the scale of a BOUND oscillator.
This is useful for when you want to use two oscillators of different scales in a lower study.
https://usethinkscript.com/threads/normalized-macd-for-thinkorswim.9502/

For instance: if you want to know when the awesome oscillator crosses above RSI.
the Awesome oscillator plots on a chart bound by 2 to -2
the RSI is plots on 0 to 100.

Using the normalized plot routine, it is possible to change the awesome plot to 0-100 thus making it possible to compare the two oscillators.

@netarchitech Is looking to create something new: To change the scale of the unbound.
My most frequently used oscillators are unbound: TSI, price spikes, etc
To use them, we generally have to use some sort of threshold routine, so the outliers do not overwhelm the graph. A way of "normalizing" them would be immensely useful. But I don't think it is possible with this script.
 
Hey there @MerryDay,

Thanks for the swift and excellent reply...Your points are well taken...I know I'm pushing the envelope, but I'm hoping one of the resident code wizards here at uTS might mull it over and maybe give it a go...

Looking forward to any/all potential contributors to this thread rising to the challenge to create a script to normalize the unbound...
 
Given the following normalizing script:

Code:
script normalizePlot {
    input data   = close;
    input Min    = 0;
    input Max = 100;
    input length = 50;
    def hhData   = Highest(data, length);
    def llData   = Lowest(data, length);
    plot resized = (((Max - Min) * (data - llData)) /
                       (hhData - llData)) + Min;
}

Is there a way to create an unbounded Max input while the Min input remains at zero? Essentially I want to take input Max = 100; and remove the 100 limitation to provide for max values well in excess of 100...

For example, let's say I need to normalize a Volume plot...a Max input value of 100 is obviously not going to cut it. If I hard-code in an arbitrary amount...say 1,000,000...I'll be capping the Volume and preventing the proper display of any values in excess of 1,000,000...

Code:
declare lower;

script normalizePlot {
    input data   = close;
    input Min    = 0;
    input Max    = 1000000;
    input length = 50;
    def hhData   = Highest(data, length);
    def llData   = Lowest(data, length);
    plot resized = (((Max - Min) * (data - llData)) /
                       (hhData - llData)) + Min;
}

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;

# Unfilled Gap down: Use prior close as high
def equivHi = if H < C[1] then C[1] else H;
# Unfilled Gap up: Use prior close as low
def equivLo = if L > C[1] then C[1] else L;

def Buying2 = Round(V * (C - equivLo) / (equivHi - equivLo), 0);
def Selling2 = Round(V * (equivHi - C) / (equivHi - equivLo), 0);

# Selling Volume
plot SV2 = normalizePlot(Selling2);
SV2.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SV2.SetDefaultColor(CreateColor(0, 82, 184));
SV2.SetLineWeight(1);
#SV2.hide();

# Buying Volume
plot BV2 = normalizePlot(Buying2);
BV2.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BV2.SetDefaultColor(CreateColor(0, 182, 254));
BV2.SetLineWeight(5);
#BV2.hide();



There are a number of volume values above in excess of 1,000,000 being cut off..Do you think there might be a workaround?

Thanks in advance for your time and anticipated potential feedback/solution to this matter. It is much appreciated :cool:
first, that sub uses highest() , not highestall, so all the bars on a chart will not be scaled to be in proper relation with all the others.


your comments about volume capping at 1000000 show you don't understand what that normalizing script is doing. it doesn't matter what values the original data has. normalizing rescales a data set to be within new limits. it doesn't clip any values.

using a max value of 100 on volume would mean that it looks at all the volume bars, and finds the biggest one, and creates a scale based on that bar being 100, then scales all the other bars accordingly, less than that. when plotted, it would look just like the original.

there is nothing being cut off in your picture. those are the values.
you are scaling Selling Volume and buying Volume separately, so they lost the relationship they had with each other.


try and describe what you want to see on the chart without saying any of the previously mentioned words like, bound, normalize,...


experiment
( this is useless until you change highest() to highestall() )
add this to the end of your study to see some values

Code:
addchartbubble(1, 0,
buying2 + "\n" +
selling2
, color.yellow, no);

drag the lower chart vertical axis down, to 'squish' it and make the bubbles visible (below the 0 line)
 
Last edited:
@netarchitech
Not sure what the goal of your quest is.
There is a VIP relational volume indicator; not sure if it will help you:
https://usethinkscript.com/threads/volume-price-trends.16117/

It does not plot actual volume; rather volume in relation to volume and its average.
This tempers out the outliers which otherwise skew any calculations and obliterates the plotting of surrounding bars.
 
Last edited:
@halcyonguy Thanks for the pointers. I appreciate your help. I mistakenly thought the usage of highestall() was not available anymore due to the following:

https://usethinkscript.com/threads/...e-no-update-in-real-time-in-thinkorswim.8794/

I'll work on getting all the erroneous "highest/lowest" references properly changed to "highestall/lowestall" and experiment.


@MerryDay Thanks for the link. I'll check it out. I really appreciate the support!
FYI, as the referenced thread states, HIGHESTALL and all the other ALL functions still function, they just don't update in real time anymore.
 
@MerryDay Thanks for the FYI...I'm sorry to read that scripters lost that functionality. On a more positive note, I really enjoyed your "Volume Price Trends" tutorial...Thanks for suggesting it...In fact, I want to thank you for all of the great content you've contributed to uTS...very thorough and to the point...Great Stuff :cool:
 

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
296 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