Request for Buy / sell volume pressure in Trend chart pattern

rajaodu1

Member
VIP
Hi Script gurus

I am looking at these volume pressure histogram bars (https://usethinkscript.com/threads/...ssure-indicators-labels-for-thinkorswim.8466/) and wanted to see the histogram charts in different way like a trend chart. Can you please help to write the script. Here is the logic I am thinking.

Lets take 5 min candle chart. The time / count always starts at 6 PM (EST) and resets next day at 6 PM (EST).


1. At 6 PM, there was 0 volume
2. Between 6.00 - 6.05 PM, there was 100 BUY volume, so the chart goes +100 Up
3. Between 6.05 - 6.10 PM, there was another 100 BUY volume, so the next candle starts at 101 and goes all the way up until 200
4. Between 6.10 - 6. 12 PM, there was another 50 BUY volume, so the next candle starts at 201 and goes all the way up until 250
4a. Between 6.12 - 6.14 PM, there was 100 SELL volume, so the candle goes down from 250 to 150.
4b. Between 6.14 - 6.15 PM, there ws 150 BUY volume, so that candle goes up from 150 to 300. While creating a wick between 150 - 200
5. Between 6.15 - 6.17 PM, there was 300 BUY volume, so the next candle starts at 301 and goes all the way up to 600
5a. Between 6.17 - 6.20 PM, there was 400 SELL volume, so the candle moves down from 600 - 200. While creating a wick between 600 - 301
6. Between 6.20 PM - 6.25 PM, there was 400 SELL volume, so the candle starts at 199 and goes all the way down till -200
7. Between 6.25 - 6.27 PM, there was 50 BUY volume, so the candle starts at -199 and goes up to -150.
7a. Betwen 6.27 PM - 6.30 PM, there was 350 SELL volume, so the candle goes down till -500. While creating a wick from -150 - -200

and so on. This logic ccan be used in all time frame. Hope I am explaining clearly. Thanks for your help




1753824206706.png
 
Solution
@rajaodu1 Can't show wicks as intrabar price/volume changes are not usable, but this should be pretty close.
LfnDkj6.jpeg

Ruby:
declare lower;

input Reset_Time = 1800;

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def BV = V * (C - L) / (H - L);
def SV = V * (H - C) / (H - L);
def HALine = if secondstilltime(Reset_Time)==0 then BV-SV else if IsNaN(HALine[1]+(BV-SV)) then 0 else HALine[1]+(BV-SV);

plot Zero = 0;
plot HAplot = HALine;
HAplot.hide();

def ghaopen = if secondstilltime(Reset_Time)==0 then 0 else HAplot[1];
def ghaclose = if HAplot >= HAplot[1] then HAplot else double.nan;
def ghalow = if HAplot <= HAplot[1] then HAplot else ghaopen;
def ghahigh = if HAplot >=...
@rajaodu1 Can't show wicks as intrabar price/volume changes are not usable, but this should be pretty close.
LfnDkj6.jpeg

Ruby:
declare lower;

input Reset_Time = 1800;

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def BV = V * (C - L) / (H - L);
def SV = V * (H - C) / (H - L);
def HALine = if secondstilltime(Reset_Time)==0 then BV-SV else if IsNaN(HALine[1]+(BV-SV)) then 0 else HALine[1]+(BV-SV);

plot Zero = 0;
plot HAplot = HALine;
HAplot.hide();

def ghaopen = if secondstilltime(Reset_Time)==0 then 0 else HAplot[1];
def ghaclose = if HAplot >= HAplot[1] then HAplot else double.nan;
def ghalow = if HAplot <= HAplot[1] then HAplot else ghaopen;
def ghahigh = if HAplot >= HAplot[1] then HAplot else ghaclose;

AddChart(growColor = color.green, fallColor = Color.red, neutralColor = Color.current, high = ghahigh, low = ghalow, open = ghaopen, close = ghaclose, type = ChartType.CANDLE);

def rhaopen = if secondstilltime(Reset_Time)==0 then 0 else HAplot[1];
def rhaclose = if HAplot < HAplot[1] then HAplot else double.nan;
def rhalow = if HAplot <= HAplot[1] then HAplot else rhaclose;
def rhahigh = if HAplot >= HAplot[1] then HAplot else rhaopen;

AddChart(growColor = color.red, fallColor = Color.green, neutralColor = Color.current, high = rhahigh, low = rhalow, open = rhaopen, close = rhaclose, type = ChartType.CANDLE);
 
Solution

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

I am not looking for relative volume indictors. If I use buy / sell volume bars. They are histogram charts. I am trying to find a logic where I can see the volume in the form of trend, so that it give MORE confluence to the market trend. Since both volume and candle are not a lagging, I am trying to see if I can find any logic using only candle and volume
 
I am not looking for relative volume indictors. If I use buy / sell volume bars. They are histogram charts. I am trying to find a logic where I can see the volume in the form of trend, so that it give MORE confluence to the market trend. Since both volume and candle are not a lagging, I am trying to see if I can find any logic using only candle and volume
If you want to see if there is a relationship between price and volume, I suggest that may be available as a ratio of price/volume. Since the volume is very volatile, I would suggest using a moving average of some periods of both the price and volume. Plotting that ratio may give you what you are looking for.


Code:
input price_MA_data = FundamentalType.CLOSE;
input price_MA_length = 10;
input price_MA_type = AverageType.EXPONENTIAL;

input volume_MA_length = 10;
input volume_MA_type = AverageType.EXPONENTIAL;

def price_MA = MovingAverage(price_MA_type, Fundamental(price_MA_data, period=GetAggregationPeriod()), price_MA_type);

def volume_MA = movingaverage(volume_MA_type, volume, volume_MA_type);

def price_to_volume_MA = price_MA / volume_MA;

plot price_vol_MA_Ratio = price_to_volume_MA;
 
Last edited:
Hi Script gurus

I am looking at these volume pressure histogram bars (https://usethinkscript.com/threads/...ssure-indicators-labels-for-thinkorswim.8466/) and wanted to see the histogram charts in different way like a trend chart. Can you please help to write the script. Here is the logic I am thinking.

Lets take 5 min candle chart. The time / count always starts at 6 PM (EST) and resets next day at 6 PM (EST).


1. At 6 PM, there was 0 volume
2. Between 6.00 - 6.05 PM, there was 100 BUY volume, so the chart goes +100 Up
3. Between 6.05 - 6.10 PM, there was another 100 BUY volume, so the next candle starts at 101 and goes all the way up until 200
4. Between 6.10 - 6. 12 PM, there was another 50 BUY volume, so the next candle starts at 201 and goes all the way up until 250
4a. Between 6.12 - 6.14 PM, there was 100 SELL volume, so the candle goes down from 250 to 150.
4b. Between 6.14 - 6.15 PM, there ws 150 BUY volume, so that candle goes up from 150 to 300. While creating a wick between 150 - 200
5. Between 6.15 - 6.17 PM, there was 300 BUY volume, so the next candle starts at 301 and goes all the way up to 600
5a. Between 6.17 - 6.20 PM, there was 400 SELL volume, so the candle moves down from 600 - 200. While creating a wick between 600 - 301
6. Between 6.20 PM - 6.25 PM, there was 400 SELL volume, so the candle starts at 199 and goes all the way down till -200
7. Between 6.25 - 6.27 PM, there was 50 BUY volume, so the candle starts at -199 and goes up to -150.
7a. Betwen 6.27 PM - 6.30 PM, there was 350 SELL volume, so the candle goes down till -500. While creating a wick from -150 - -200

and so on. This logic ccan be used in all time frame. Hope I am explaining clearly. Thanks for your help

here is something close to what you want. it creates a stairstep pattern from the buying and selling numbers.

user picks an agg time, greater than the chart time.
chart = 5min
agg = 30min
this will create a wider bar for the 30 min, based on 30/5 = 6 bars

if agg time is less than the chart time, then an error label pops up.
if agg time is not a multiple of the chart time, then an error label pops up.

user picks a time for the start of the day. default is 1800 for 6pm.
a vertical line is drawn there

each wide bar (cloud) is calculated by adding up the buying and selling numbers during that period.
it does not reverse during the agg time period (default 30min).

can also plot a histogram of each wide bar height.

each cloud in the image is spanning 6 bars, 30min.

Code:
#vol_pressure_buy_sell_rng_01
# halcyonguy
# 25-08-03

#https://usethinkscript.com/threads/request-for-buy-sell-volume-pressure-in-trend-chart-pattern.21348/
#Request for Buy / sell volume pressure in Trend chart pattern
#rajaodu1  Start 7/29
# I am looking at these volume pressure histogram bars
# and wanted to see the histogram charts in different way like a trend chart.
#
# https://usethinkscript.com/threads/all-buy-sell-volume-pressure-indicators-labels-for-thinkorswim.8466/
# Indicator Forums Indicators
# All Buy / Sell Volume Pressure Indicators & Labels For ThinkOrSwim
# MerryDay  Sep 3, 2019


declare lower;

# use on 1 minute chart
# then pick an agg time

def na = double.nan;
def bn = barnumber();

#---------------------------------
# get chart agg time
def chartagg = getaggregationperiod();
def chartmin = chartagg/(1000*60);
#---------------------------------
# pick an agg time
input agg = AggregationPeriod.five_min;
def aggmin = agg/60000;
#---------------------------------

addlabel(0, chartmin);
addlabel(1, aggmin + " min",color.gray);
addlabel( ((aggmin/chartmin) < 1), ">>>>--- PICK AN AGG TIME LESS THAN CHART TIME ---<<<<", COLOR.CYAN);
addlabel( ((aggmin/chartmin) != floor(aggmin/chartmin) ), ">>>>--- PICK AN AGG TIME THAT IS A MULTIPLE OF THE CHART TIME ---<<<<", COLOR.YELLOW);


def x = floor(bn/(aggmin/chartmin));
#addchartbubble(1, 0,
#x
#, color.yellow, no);


plot z = 0;
z.setdefaultcolor(color.light_gray);

# reset data at 6 pm
input start_time = 1800;

def startbar = SecondsFromTime(start_time)[1] < 0 and SecondsFromTime(start_time) >= 0;

addverticalline(startbar,"-", color.cyan);


def cnt = if startbar then bn else cnt[1];
def cnt2 = 1 + floor((bn-cnt)/(aggmin/chartmin));

# ----------------

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

def grn = close > open;
def red = close < open;

def Buying = floor(V * (C - L) / (H - L));
def Selling = floor(V * (H - C) / (H - L));


def n = 200;
def ht1;
if cnt2 != cnt2[1] then {
 ht1 = fold a = 0 to n
  with b
  while getvalue(cnt2, -a) == cnt2
  do b + (getvalue(buying,-a) - getvalue(selling,-a));
} else {
 ht1 = ht1[1];
}


def ht2;
def h1prev;
if startbar then {
 h1prev = 0;
 ht2 = ht1;
} else if cnt2 != cnt2[1] then {
 h1prev = ht2[1];
 ht2 = h1prev + ht1;
} else {
 h1prev = h1prev[1];
 ht2 = ht2[1];
}


input show_stairstep_pattern = yes;
plot z4 = h1prev;
plot z5 = ht2;
z4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z4.sethiding(!show_stairstep_pattern);
z5.sethiding(!show_stairstep_pattern);


def even = floor(cnt2/2) == (cnt2/2);
def top1 = if even and show_stairstep_pattern then z4 else na;
def top2 = if !even and show_stairstep_pattern then z4 else na;

addcloud(top1, z5, color.red, color.green);
addcloud(top2, z5, color.red, color.green);


input show_histogram = no;
plot z3 = ht1;
z3.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
z3.setdefaultcolor(color.cyan);
z3.sethiding(!show_histogram);

input show_histo_line = no;
plot z2 = ht1;
z2.setdefaultcolor(color.cyan);
z2.sethiding(!show_histo_line);

#------------------------

input test1 = no;
addchartbubble(test1, 0,
ht1 + "\n" +
buying + " B\n" +
selling + " S"
, color.yellow, no);


input test2 = no;
addchartbubble(test2, 0,
ht1 + "\n" +
h1prev + "\n" +
ht2 + " \n"
, color.yellow, no);


addchartbubble(0, 0,
bn + "\n" +
cnt + "\n" +
cnt2
, color.yellow, no);


addchartbubble(0, 0,
secondsfromTime(start_time)
, color.yellow, no);
#

side note, it uses an odd/even counter to drive 2 clouds that alternate drawing, to avoid having diagonal cloud lines connecting the clouds.
 

Attachments

  • 01d-1.JPG
    01d-1.JPG
    58.7 KB · Views: 6
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
301 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