# How to normalize OnBalanceVolume indicator?

#### kykuang

##### New member
I had hard time to normalize this onbalanceVolume Indicator provided in TOS. My goal is to make it similar to this attached photo..... Any help will greatly appreciated

def OBV = TotalSum(Sign(close - close[1]) * volume);

def HH = AbsValue(HighestAll(OBV));
def LL = AbsValue(LowestAll(OBV));

def OBV1 = LL+ OBV; # offset negative value

plot x = 100 * OBV1 / max(HH, LL);
x.SetDefaultColor( Color.GREEN);

Wanted OBV

Last edited:
I had hard time to normalize this onbalanceVolume Indicator provided in TOS. My goal is to make it similar to this attached photo..... Any help will greatly appreciated

def OBV = TotalSum(Sign(close - close[1]) * volume);

def HH = AbsValue(HighestAll(OBV));
def LL = AbsValue(LowestAll(OBV));

def OBV1 = LL+ OBV; # offset negative value

plot x = 100 * OBV1 / max(HH, LL);
x.SetDefaultColor( Color.GREEN);

Wanted OBV

This is the Schaff indicator with a standard normalized method for the OBV.

Ruby:
``````#
# TD Ameritrade IP Company, Inc. (c) 2015-2016
#

declare lower;
input fastLength = 20;
input slowLength = 50;
input KPeriod = 10;
input DPeriod = 3;
input over_bought = 75;
input over_sold = 25;
input averageType = AverageType.EXPONENTIAL;

def macd = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def fastK1 = FastKCustom(macd, KPeriod);
def fastD1 = MovingAverage(averageType, fastK1, DPeriod);
def fastK2 = FastKCustom(fastD1, KPeriod);
plot STC = MovingAverage(averageType, fastK2, DPeriod);
STC.SetDefaultColor(GetColor(8));

plot line50 = 50;
plot line0 = 0;
plot line100 = 100;
line50.SetDefaultColor(GetColor(7));
line50.SetLineWeight(1);
line50.SetStyle(Curve.FIRM);
line0.SetDefaultColor(GetColor(7));
line0.SetLineWeight(1);
line0.SetStyle(Curve.SHORT_DASH);
line100.SetDefaultColor(GetColor(7));
line100.SetLineWeight(1);
line100.SetStyle(Curve.SHORT_DASH);

plot line80 = 90;
plot line20 = 10;
line80.SetDefaultColor(Color.BLACK);
line20.SetDefaultColor(Color.BLACK);

def stc1 = STC;
def buy = if stc1 > stc1[1] then 1 else if buy[1] == 1 and stc1 >= stc1[1] then 1 else 0;
def sell = if stc1 < stc1[1] then 1 else if sell[1] == 1 and stc1 <= stc1[1] then 1 else 0;

# --- script end ----

script normalized {
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;
}

def OBV = TotalSum(Sign(close - close[1]) * volume);

plot x  = normalized(OBV);``````

87k+ Posts
334 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?