Buying and Selling Pressure Scan


Category:
0
0

Hi Pete!

I need help with this attempt at a scan for buying pressure. The filter is supposed to look for stocks whose daily buying pressure is 30% of the day’s volume. Unfortunately, the filter below is turning up too many incorrect returns. Take Etsy for example. It showed up in the scan, but as you can see from the picture, the buying pressure on Friday was only 10.3%. I also can’t figure out how to show only results of buying > selling. I would also like the ability to scan the opposite of selling > buying too.

Thanks again!

input percentage = 30;
def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def Buying = V*(C-L)/(H-L);
def Selling = V*(H-C)/(H-L);
def total = buying + selling;
def Buypercent = Buying/total * 100;
plot scan  = percentage >= Buypercent;
Attachments:
Marked as spam
Posted by (Questions: 8, Answers: 18)
Asked on May 6, 2024 1:26 pm
140 views
0
Private answer

That code you provided contains some methods which I advise people to avoid. So I do want to take some time to explain this. Please don't take offense. I just want to make sure that folks who are just learning how to write code do not pick up bad habits which will diminish their future success.

The first mistake to avoid is using variable names with single characters. This sort of thing makes it very difficult to modify and maintain large sections of code. Here is what I want the newbies to avoid:

def O = open;
def H = high;

There is no need to do that and it will only make the code more difficult to read and more challenging to update and maintain in the future. Just use 'open', 'high', 'low', 'close' and 'volume' directly. Like this:

volume * (close - low) / (high - low)

The only reason you would ever want to create a separate variable for one of these price types is if you were creating a custom price type, for example the Hieken-Ashi.

The other item I want the newbies to avoid is the pattern of not including spaces between the variable names and the operators. So here is an example of what I want the newbies to avoid doing:

V*(C-L)/(H-L)

If you use that in a large section of code and need to make changes in the future it will be a nightmare. The best way to write that statement is the example I provided above.

Variable names should fully describe their function and purpose within the code. And camelCase should be used, unless you prefer to use underscore_case. In both methods the first character of each variable  should be lower case.

Ok, now that we have that out of the way we can get to the solution. Your plot scan statement was just backwards. You had them reversed and the scan was returning results for the exact opposite of what you intended. So that was a pretty easy fix. You also asked for two additional signals which you were not able to figure out. For that, I created a new variable for "sellingPreassurePercent", which I then used to create those other two scan signals.

Here is the full solution (please note I have made several changes to get this code to conform to the most recommended format):

input percentThreshold = 30.0;
def buyingPreassure = volume * (close - low) / (high - low);
def sellingPreassure = volume * (high - close) / (high - low);
def totalVolume = buyingPreassure + sellingPreassure;
def buyingPreassurePercent = buyingPreassure / totalVolume * 100;
def sellingPreassurePercent = sellingPreassure / totalVolume * 100;
# use this to scan for buying preassure greater than percent threshold
plot scan = buyingPreassurePercent >= percentThreshold;
# use this to scan selling preassure greater than percent threshold
# plot scan = sellingPreassurePercent >= percentThreshold;
# use this to scan for buying preassure greater than selling preassure
# plot scan = buyingPreassure > sellingPreassure;
# use this to scan for selling preassure greater than buying preassure

Marked as spam
Posted by (Questions: 37, Answers: 4116)
Answered on May 6, 2024 1:47 pm