Price/Volume Value Histogram for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
dD1zqSH.png

Author Message:
An interesting implementation of mine to measure an asset changes based on asset price velocity and volume velocity. The indicator acts as asset value calculator. Long and Short.
==Points System Rules==
UPTRENDING
If Current Close is higher than previous Close and Current Volume is bigger than previous Volume: Adds Close Points and Volume Points
Otherwise check
If Current Close is higher than previous Close: Adds Only Close Points

DOWNTRENDING
If Current Close is lower than previous Close and Current Volume is bigger than previous Volume: Reduces Close Points and Volume Points
Otherwise check
If Current Close is lower than previous Close: Reduces Only Close Points

==Plotting==
Result of the values are summed up to a histogram.
Obviously on increasing prices and volume the histogram will be above zero line and on the Bullish side (green color), otherwise, on the Bearish side (red color).

You can't cheat the price movement, it's just what it is.
Optional to smooth it by EMA (set to true by default).

CODE:
CSS:
#// This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License
#// © dman103
#study("Price/Volume value histogram","P/V value histogram",overlay=false,precision=3)
# Converted by Sam4Cok@Samer800 - 01/2023
Declare lower;
input lookBack = 7;              # "Look back"
input colorBars = yes;           # "Color bars"
input percent_factor_volume = 0; # "Percent to reduce from volume factor [0 - normal, 100 - disable volume]"
input emaSmooth = yes;           # "EMA smoothing"
input emaLength = 7;             # "EMA Length"

def na = Double.NaN;
def reduced_percent;
if BarNumber()==1 {
    reduced_percent = if (percent_factor_volume==0) then 1 else 0;
    } else {
    reduced_percent = AbsValue(percent_factor_volume/100-1);
}
def points_array;
def points;
def points_max;
def max_totals;
def points_totals;
#//Positive
if close>close[1] and (volume>volume[1]) {
    points_array = (close/close[1])*(max(min(volume/volume[1],2)*reduced_percent,1));
    points = points[1] + 1;
    points_totals = points_array / points;
    points_max = points_max[1] + points_totals;
    max_totals = if points_max[1] == 0 then points_totals[1] else points_totals;
    } else if close>close[1] {
    points_array = (close/close[1]);
    points = points[1] + 1;
    points_totals = points_array / points;
    points_max = points_max[1] + points_totals;
    max_totals = if points_max[1] == 0 then points_totals[1] else points_totals;
#//Negative
    } else
if  close<close[1] and (volume>volume[1]) {
    points_array = -((close[1]/close)*(max(min(volume/volume[1],2)*reduced_percent,1)));
    points = points[1] + 1;
    points_totals = points_array / points;
    points_max = points_max[1] + points_totals;
    max_totals = if points_max[1] == 0 then points_totals[1] else points_totals;
    } else if close<close[1] {
    points_array = -(close[1]/close);
    points = points[1] + 1;
    points_totals = points_array / points;
    points_max = points_max[1] + points_totals;
    max_totals = if points_max[1] == 0 then points_totals[1] else points_totals;
    } else {
    points_array = points_array[1];
    points = points[1];
    points_max = points_max[1];
    points_totals = points_totals[1];
    max_totals = max_totals[1];
}

def sumTotal = fold i1 = 1 to lookBack + 1 with p1 do
               p1 +  points_totals[i1] / i1;
def sum_total = sumTotal;
plot ZeroLine = if isNaN(close) then na else 0;
ZeroLine.SetDefaultColor(Color.GRAY);

def _result = if emaSmooth then ExpAverage(sum_total,emaLength) else sum_total;
def ExtUp = _result>=0 and _result>_result[1];
def    Up = _result>=0 and _result<_result[1];
def ExtDn = _result<0 and _result<_result[1];
def    Dn = _result<0 and _result>_result[1];
plot plot_result = if isNaN(close) then na else _result;
plot_result.SetLineWeight(4);
plot_result.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plot_result.AssignValueColor(if ExtUp then Color.GREEN else
                             if Up    then Color.DARK_GREEN else
                             if ExtDn then Color.RED else
                             if Dn    then Color.DARK_RED else Color.GRAY);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if ExtUp then Color.GREEN else
                 if Up    then Color.DARK_GREEN else
                 if ExtDn then Color.RED else
                 if Dn    then Color.DARK_RED else Color.GRAY);

# --- END CODE
 
Last edited by a moderator:

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