Platinum Customer
Joined: 12/4/2016 Posts: 5

Good afternoon,
I have created a PCF that uses several COUNTTRUE functions together.
Here is an example of part of the formula:
counttrue(c>c1 and h>h1 ad l>l1,5) + counttrue(co>=max(co,9),5) + 1*counttrue(c<c1 and h<h1 and l<l1,5) + 1*counttrue(oc>=max(oc,9),5)
I am attempting to create another PCF that will take the difference between today's value a yesterday's value. Could you provide me an example of how to do this?
Also, is there a way to reference an existing PCF in a new PCF without having to write the entire PCF out?
Thank you.

Worden Trainer
Joined: 10/7/2004 Posts: 64,508

There is not a way to reference another PCF from within a PCF.
Normally you would just subtract the 1 bar ago version from the current version.
CountTrue(C > C1 AND H > H1 AND L > L1, 5) + CountTrue(C  O >= MAX(C  O, 9), 5)  CountTrue(C < C1 AND H < H1 AND L < L1, 5)  CountTrue(O  C <= MAX(O  C, 9), 5)  CountTrue(C1 > C2 AND H1 > H2 AND L1 > L2, 5)  CountTrue(C1  O1 >= MAX(C1  O1, 9), 5) + CountTrue(C1 < C2 AND H1 < H2 AND L1 < L2, 5) + CountTrue(O1  C1 <= MAX(O1  C1, 9), 5)
But in this case, it would be more efficient to just check if the conditions are true for the current bar and 5 bars ago.
IIF(C > C1 AND H > H1 AND L > L1, 1, IIF(C < C1 AND H < H1 AND L < L1, 1, 0)) + IIF(C  O = MAX(C  O, 9), 1, IIF(O  C = MAX(O  C, 9), 1, 0))  IIF(C5 > C6 AND H5 > H6 AND L5 > L6, 1, IIF(C5 < C6 AND H5 < H6 AND L6 < L6, 1, 0))  IIF(C5  O5 = MAX(C5  O5, 9), 1, IIF(O5  C5 = MAX(O5  C5, 9), 1, 0))
Bruce Personal Criteria Formulas TC2000 Support Articles

Platinum Customer
Joined: 12/4/2016 Posts: 5

Bruce,
I wanted to follow up and clarify what I am looking specifically for.
The COUNTTRUE formula in my last post results in creating an oscillator with both positive and negative numbers. That's the reason I have some of the COUNTTRUE statements starting with a 1 which produces a negative number which is what I want. It may not be the ideal way to write the formula but it does work.
What I am really looking for with this formula is the diffence between the current bars formula value versus the value from yesterday (or from 1 min ago, 2 min. ago, whatever time frame being used). So as an example, if the current bars formula value is 4 and yesterday's formula value is 1 then it would return a value of 3 (41). Seems like a simple subtraction but with many formulas, I was not sure how to write it.
Since the formula produces negative values, I am looking for both the real difference (like in the example) and how to get the ABSOLUTE difference which would just produce a positive number. Hope this makes sense.
Also, with another software, I created this formula but used an 8 period exponential moving average instead of a the counttrue function for 5 periods (simple not exponential). Is there a way to produce this overall formula using the "xavg" function for each statement within the overall formula? I prefer a more weighted formula (exponential) versus a simple formula.
Thanks for your help in advance.
John

Worden Trainer
Joined: 10/7/2004 Posts: 64,508

If I am understanding correctly, we should be able to just use the ABS() function to get your first answer.
ABS(IIF(C > C1 AND H > H1 AND L > L1, 1, IIF(C < C1 AND H < H1 AND L < L1, 1, 0)) + IIF(C  O = MAX(C  O, 9), 1, IIF(O  C = MAX(O  C, 9), 1, 0))  IIF(C5 > C6 AND H5 > H6 AND L5 > L6, 1, IIF(C5 < C6 AND H5 < H6 AND L6 < L6, 1, 0))  IIF(C5  O5 = MAX(C5  O5, 9), 1, IIF(O5  C5 = MAX(O5  C5, 9), 1, 0)))
For the second part, we can start with the raw value.
IIF(C > C1 AND H > H1 AND L > L1, 1, IIF(C < C1 AND H < H1 AND L < L1, 1, 0)) + IIF(C  O = MAX(C  O, 9), 1, IIF(O  C = MAX(O  C, 9), 1, 0))
And get the difference between it and one bar ago.
IIF(C > C1 AND H > H1 AND L > L1, 1, IIF(C < C1 AND H < H1 AND L < L1, 1, 0)) + IIF(C  O = MAX(C  O, 9), 1, IIF(O  C = MAX(O  C, 9), 1, 0))  IIF(C1 > C2 AND H1 > H2 AND L1 > L2, 1, IIF(C1 < C2 AND H1 < H2 AND L1 < L2, 1, 0))  IIF(C1  O1 = MAX(C1  O1, 9), 1, IIF(O1  C1 = MAX(O1  C1, 9), 1, 0))
Then add an exponential moving average.
XAVG(IIF(C > C1 AND H > H1 AND L > L1, 1, IIF(C < C1 AND H < H1 AND L < L1, 1, 0)) + IIF(C  O = MAX(C  O, 9), 1, IIF(O  C = MAX(O  C, 9), 1, 0))  IIF(C1 > C2 AND H1 > H2 AND L1 > L2, 1, IIF(C1 < C2 AND H1 < H2 AND L1 < L2, 1, 0))  IIF(C1  O1 = MAX(C1  O1, 9), 1, IIF(O1  C1 = MAX(O1  C1, 9), 1, 0)), 8)
And take the absolute value.
ABS(XAVG(IIF(C > C1 AND H > H1 AND L > L1, 1, IIF(C < C1 AND H < H1 AND L < L1, 1, 0)) + IIF(C  O = MAX(C  O, 9), 1, IIF(O  C = MAX(O  C, 9), 1, 0))  IIF(C1 > C2 AND H1 > H2 AND L1 > L2, 1, IIF(C1 < C2 AND H1 < H2 AND L1 < L2, 1, 0))  IIF(C1  O1 = MAX(C1  O1, 9), 1, IIF(O1  C1 = MAX(O1  C1, 9), 1, 0)), 8))
Bruce Personal Criteria Formulas TC2000 Support Articles
