Buying vs Selling Power Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
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);
 

SleepyZ

Well-known member
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.

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:

Splinter

Member
VIP
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:

SleepyZ

Well-known member
VIP
Lifetime
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.
 

ktbPanther

New member
VIP
This is really great stuff! Could you guide me through what the three different input bases do? Trying to figure it out but struggling.
 

ktbPanther

New member
VIP
Wonder how useful it'd be if we cumulatively integrate both the sell and then the buy volume profiles you've made across price with ticksize resolution. Then subtract the two waveforms and take the derivative of the final data array with respect to price. Then plot it as a profile. With this, I think you'd be able to see the strong buying and selling nodes more clearly. Again, I think... haven't digested this yet.
 

Similar threads

Top