Boolean % Statistic


Category:
0
0

Hahn, I have learned bundles of information from your website. I genuinely appreciate all that you do! I am having a lot of trouble figuring this study out though.

 

In the screenshot below, there are blue bars and purple bars. For this example, lets say there are a total of 64 bars. I need the study to calculate what % of the time does a blue bar pop up? Also, for this example we can say that a blue bar appears when close > close[1] and a purple bar appears when close < close[1].

 

Thank you very much!

Attachments:
Marked as spam
Posted by (Questions: 34, Answers: 56)
Asked on November 25, 2017 4:53 pm
45 views
0

Very simple math, so the solution should be quite simple to implement. We do need to define the scope of the time variable though. What percent of the time…. We can simply count every single bar on the chart, then divide the number of blue bars by the number of all bars. But do you need this calculation to span a specific amount of time?

( at November 25, 2017 5:25 pm)
0

This is for a 3 month chart, each bar represents one day. I am confused on what to put in the “x” down below

The 64 represents the 64 days in the 3 month chart. This is just for an example.
def percentoftime = (x/64)*100;

( at November 26, 2017 4:23 pm)
0

I don’t know how to make the study count how many times there is a blue bar, that’s the problem. Thank you!

( at November 26, 2017 4:24 pm)
0
Private answer

Ok, having clarified the details I can now provide the solution. This code will keep a running count and for each bar it will calculate the percentage of “purple bars” from among all bars. Screenshot shows how it plots.

declare lower;
def purpleBar = close < close[1];
def purpleBarCount = TotalSum(purpleBar);
def totalBarCount = BarNumber();
plot percentPupleBars = (purpleBarCount / totalBarCount) * 100;

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on November 26, 2017 6:22 pm
0

You’re the best! Thank you!!! ?

( at November 26, 2017 8:16 pm)