Buying vs Selling Pressure Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
This indicator will calculate the current buying and selling power of the stock. It's a lower study but comes with paintbar for better visual. You can turn it off from the indicator's settings page.

...when ever one cross the other we can see if asset is bearish =red or bullish= blue

cCXwOJd.png


thinkScript Code

Code:
# Buying vs. Selling Power
# Assembled by BenTen at UseThinkScript.com
# Converted from https://www.tradingview.com/script/XZ3UXRvL-buy-vs-sell-power-x/

declare lower;

input s = 5;
input m = 9;
input l = 14;
input paintbar = yes;

def source = close;
def hilow = ((high - low) * 100);
def openclose = ((close - open) * 100);
def vol = (close / hilow);
def spreadv = (openclose * close);
def pt = spreadv + totalSum(spreadv);

def a = expAverage(pt, l) - expAverage(pt, m);
def b = expAverage(pt, s) - expAverage(pt, m);
def p = a + b;

plot blue = b;
plot red = p;

def bullishRule = b >= p;
def bearishRule = b <= p;

assignPriceColor(if paintbar and bullishRule then Color.Green else if paintbar and bearishRule then Color.Red else Color.Current);
 
This indicator will calculate the current buying and selling power of the stock. It's a lower study but comes with paintbar for better visual. You can turn it off from the indicator's settings page.

This indicator adds the option of using buying selling pressure indicator, buying selling volume basis or close versus open basis to the dataproffile indicator.

There are two dataprofiles in this. The buying bars are green and the portions of red that appear are meant to be the selling portion. I have not fully tested this, but just presenting it for interest and the hopes it may be the start of something useful.

The candles are painted by the input paintbar in BenTen's buying selling pressure indicator

[Edit - Updated code with minor enhancements 20211201 . I will continue to make updates available here]


Capture.jpg
Ruby:
#DataProfile - Using Close based upon the input method. Green is 'buying' and Red is the 'selling' beyond the 'buying'. (The Red is actually the total of buying and selling with the buying overlaid on the red)
#20211130 Sleepyz

input method = {default close_open, buying_selling_volume, buying_selling_pressure};
def c = close;
def o = open;
def h = high;
def l = low;
def v = volume;

# Buying vs. Selling Power
# Assembled by BenTen at UseThinkScript.com
# Converted from https://www.tradingview.com/script/XZ3UXRvL-buy-vs-sell-power-x/

input s = 5;
input m = 9;
input len = 14;
input paintbar = yes;

def source = close;
def hilow = ((high - low) * 100);
def openclose = ((close - open) * 100);
def vol = (close / hilow);
def spreadv = (openclose * close);
def pt = spreadv + TotalSum(spreadv);

def a = ExpAverage(pt, len) - ExpAverage(pt, m);
def b = ExpAverage(pt, s) - ExpAverage(pt, m);
def p = a + b;

def blue = b;
def red = p;

def bullishRule = b >= p;
def bearishRule = b <= p;

AssignPriceColor(if paintbar and bullishRule then Color.CYAN else if paintbar and bearishRule then Color.MAGENTA else Color.CURRENT);



def test;
switch (method) {
case close_open:
    test = if c > o then close else if c < o then double.nan else test[1];
case buying_selling_volume:
    test = if ((c - l) / (h - l) * volume) > ((h - c) / (h - l) * volume) then close else test[1];
case buying_selling_pressure:
    test = if b >= p then close else test[1];
}

def buy   = test;
def Data  = close;
input pricePerRowHeightMode = { default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = { CHART, MINUTE, HOUR, default DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = no;
input profiles = 3;
input showPointOfControl = yes;
input showValueArea = no;
input valueAreaPercent = 70;
input opacity = 100;

def period;
def yyyymmdd = GetYYYYMMDD();
def seconds = SecondsFromTime(0);
def month = GetYear() * 12 + GetMonth();
def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd));
def dom = GetDayOfMonth(yyyymmdd);
def dow = GetDayOfWeek(yyyymmdd - dom + 1);
def expthismonth = (if dow > 5 then 27 else 20) - dow;
def exp_opt = month + (dom > expthismonth);
switch (timePerProfile) {
case CHART:
    period = 0;
case MINUTE:
    period = Floor(seconds / 60 + day_number * 24 * 60);
case HOUR:
    period = Floor(seconds / 3600 + day_number * 24);
case DAY:
    period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case WEEK:
    period = Floor(day_number / 7);
case MONTH:
    period = Floor(month - First(month));
case "OPT EXP":
    period = exp_opt - First(exp_opt);
case BAR:
    period = BarNumber() - 1;
}

def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % multiplier else count[1], 0);
def cond = count < count[1] + period - period[1];
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
    height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    height = PricePerRow.TICKSIZE;
case CUSTOM:
    height = customRowHeight;
}

profile datatype = DataProfile("data" = Data, "startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def con = CompoundValue(1, onExpansion, no);
def pc = if IsNaN(datatype.GetPointOfControl()) and con then pc[1] else datatype.GetPointOfControl();
def hVA = if IsNaN(datatype.GetHighestValueArea()) and con then hVA[1] else datatype.GetHighestValueArea();
def lVA = if IsNaN(datatype.GetLowestValueArea()) and con then lVA[1] else datatype.GetLowestValueArea();

def hProfile = if IsNaN(datatype.GetHighest()) and con then hProfile[1] else datatype.GetHighest();
def lProfile = if IsNaN(datatype.GetLowest()) and con then lProfile[1] else datatype.GetLowest();
def plotsDomain = IsNaN(close) == onExpansion;

plot POC = if plotsDomain then pc else Double.NaN;
plot ProfileHigh = if plotsDomain then hProfile else Double.NaN;
plot ProfileLow = if plotsDomain then lProfile else Double.NaN;
plot VAHigh = if plotsDomain then hVA else Double.NaN;
plot VALow = if plotsDomain then lVA else Double.NaN;

DefineGlobalColor("Profile", Color.LIGHT_RED);
DefineGlobalColor("Point Of Control", GetColor(5));
DefineGlobalColor("Value Area", GetColor(8));

datatype.Show(GlobalColor("Profile"), if showPointOfControl then GlobalColor("Point Of Control") else Color.CURRENT, if showValueArea then GlobalColor("Value Area") else Color.CURRENT);
POC.SetDefaultColor(GlobalColor("Point Of Control"));
POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VALow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetDefaultColor(GlobalColor("Value Area"));
VALow.SetDefaultColor(GlobalColor("Value Area"));
ProfileHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileHigh.SetDefaultColor(GetColor(3));
ProfileLow.SetDefaultColor(GetColor(3));
ProfileHigh.Hide();
ProfileLow.Hide();

profile datatype2 = DataProfile("data" = test, "startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def con2 = CompoundValue(1, onExpansion, no);
def pc2 = if IsNaN(datatype2.GetPointOfControl()) and con2 then pc2[1] else datatype2.GetPointOfControl();
def hVA2 = if IsNaN(datatype2.GetHighestValueArea()) and con2 then hVA2[1] else datatype2.GetHighestValueArea();
def lVA2 = if IsNaN(datatype2.GetLowestValueArea()) and con2 then lVA2[1] else datatype2.GetLowestValueArea();

def hProfile2 = if IsNaN(datatype2.GetHighest()) and con2 then hProfile2[1] else datatype2.GetHighest();
def lProfile2 = if IsNaN(datatype2.GetLowest()) and con2 then lProfile2[1] else datatype2.GetLowest();
def plotsDomain2 = IsNaN(close) == onExpansion;

plot POC2 = if plotsDomain2 then pc2 else Double.NaN;
plot ProfileHigh2 = if plotsDomain2 then hProfile2 else Double.NaN;
plot ProfileLow2 = if plotsDomain2 then lProfile2 else Double.NaN;
plot VAHigh2 = if plotsDomain2 then hVA2 else Double.NaN;
plot VALow2 = if plotsDomain2 then lVA2 else Double.NaN;

DefineGlobalColor("Profile2", Color.GREEN);

datatype2.Show(GlobalColor("Profile2"), if showPointOfControl then GlobalColor("Point Of Control") else Color.CURRENT, if showValueArea then GlobalColor("Value Area") else Color.CURRENT, opacity);
 
Last edited:
This indicator adds the option of using buying selling pressure indicator, buying selling volume basis or close versus open basis to the dataproffile indicator.

There are two dataprofiles in this. The buying bars are green and the portions of red that appear are meant to be the selling portion. I have not fully tested this, but just presenting it for interest and the hopes it may be the start of something useful.

The candles are painted by the input paintbar in BenTen's buying selling pressure indicator
Very cool! I'll be checking this out tomorrow. I appreciate your work!

I was hoping you would be able to help clarify this statement in the code:

#DataProfile - Using Close based upon the input method. Green is 'buying' and Red is the 'selling' beyond the 'buying'. (The Red is actually the total of buying and selling with the buying overlaid on the red).

On "automatic" I see a large block of green with the red bars across. I'm thinking that an absence of a red bar across, the underlying green shows through which would denote a bullish bias?
 
Last edited:
Very cool! I'll be checking this out tomorrow. I appreciate your work!

I was hoping you would be able to help clarify this statement in the code:

#DataProfile - Using Close based upon the input method. Green is 'buying' and Red is the 'selling' beyond the 'buying'. (The Red is actually the total of buying and selling with the buying overlaid on the red).

On "automatic" I see a large block of green with the red bars across. I'm thinking that an absence of a red bar across, the underlying green shows through which would denote a bullish bias?
That is the intent to make that bullish bias at that price point. I just thought of trying to see if this indicator might plot. It needs improvement and testing.
 

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