Registered User Joined: 9/18/2017 Posts: 20
|
I wanted to see if there was a way I could use PCF to make an if then else statement with two thens.
I tried using SGN but was limited to only high-low
if (open<close) then (high - low) if NOT then (low - high)
Thank you!
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Please try the following in TC2000 v17.
IIF(O < C, H - L, L - H)
Inline IF and converting conditions to indicators
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 9/18/2017 Posts: 20
|
Thanks Bruce!
I have one more question..
I wanted to use this(IIF(O < C, H - L, L - H)) as the source for bollinger bands with a period of 150, and to find the difference between the top and bottom band. I tried using bandwidth but it would give me very high values that werent the number I was looking for. So I wanted to find the difference between the upper and lower band and the find the ratio of that number versus the price of the ticker.
Thank you!
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Please try the following indicator. It assumes a the Bollinger Bands have a period of 150 and std dev setting of 2.00 (the 4 * at the beginning of the formula is twice the std dev setting).
4 * SQR(ABS(SUM((IIF(O < C, H - L, L - H)) ^ 2, 150) - 150 * AVG(IIF(O < C, H - L, L - H), 150) ^ 2) / 150) / C
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 9/18/2017 Posts: 20
|
I have one more question Bruce.. Is there a way that I can do this..
IF ((HAVG((V - AVGV20) / 4 / SQR(((V - AVGV20) ^ 2 + (V1 - AVGV20) ^ 2 + (V2 - AVGV20) ^ 2 + (V3 - AVGV20) ^ 2 + (V4 - AVGV20) ^ 2 + (V5 - AVGV20) ^ 2 + (V6 - AVGV20) ^ 2 + (V7 - AVGV20) ^ 2 + (V8 - AVGV20) ^ 2 + (V9 - AVGV20) ^ 2 + (V10 - AVGV20) ^ 2 + (V11 - AVGV20) ^ 2 + (V12 - AVGV20) ^ 2 + (V13 - AVGV20) ^ 2 + (V14 - AVGV20) ^ 2 + (V15 - AVGV20) ^ 2 + (V16 - AVGV20) ^ 2 + (V17 - AVGV20) ^ 2 + (V18 - AVGV20) ^ 2 + (V19 - AVGV20) ^ 2) / 20) + .5, 20)*(-1)+1) + HAVG((C - AVGC20) / 4 / STDDEV20 + .5, 20)) is less than .02 THEN add 4 * SQR(ABS(SUM((IIF(O < C, H - L, L - H)) ^ 2, 150) - 150 * AVG(IIF(O < C, H - L, L - H), 150) ^ 2) / 150) to the low of price
Thanks!
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You didn't indicate what to return if it wasn't true. The following version returns a division by zero error instead of a numeric value when this is the case. This allows you to plot the indicator using the Dots Plot Style and have it only plot when the requirements are met.
IIF((HAVG((V - AVGV20) / 4 / SQR(((V - AVGV20) ^ 2 + (V1 - AVGV20) ^ 2 + (V2 - AVGV20) ^ 2 + (V3 - AVGV20) ^ 2 + (V4 - AVGV20) ^ 2 + (V5 - AVGV20) ^ 2 + (V6 - AVGV20) ^ 2 + (V7 - AVGV20) ^ 2 + (V8 - AVGV20) ^ 2 + (V9 - AVGV20) ^ 2 + (V10 - AVGV20) ^ 2 + (V11 - AVGV20) ^ 2 + (V12 - AVGV20) ^ 2 + (V13 - AVGV20) ^ 2 + (V14 - AVGV20) ^ 2 + (V15 - AVGV20) ^ 2 + (V16 - AVGV20) ^ 2 + (V17 - AVGV20) ^ 2 + (V18 - AVGV20) ^ 2 + (V19 - AVGV20) ^ 2) / 20) + .5, 20)*(-1)+1) + HAVG((C - AVGC20) / 4 / STDDEV20 + .5, 20) < .02, L + 4 * SQR(ABS(SUM((IIF(O < C, H - L, L - H)) ^ 2, 150) - 150 * AVG(IIF(O < C, H - L, L - H), 150) ^ 2) / 150), 1 / 0)
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 9/18/2017 Posts: 20
|
hmm.. when i made that into a PCF nothing came up on the panel.. what I wanted was:
IF (HAVG((V - AVGV20) / 4 / SQR(((V - AVGV20) ^ 2 + (V1 - AVGV20) ^ 2 + (V2 - AVGV20) ^ 2 + (V3 - AVGV20) ^ 2 + (V4 - AVGV20) ^ 2 + (V5 - AVGV20) ^ 2 + (V6 - AVGV20) ^ 2 + (V7 - AVGV20) ^ 2 + (V8 - AVGV20) ^ 2 + (V9 - AVGV20) ^ 2 + (V10 - AVGV20) ^ 2 + (V11 - AVGV20) ^ 2 + (V12 - AVGV20) ^ 2 + (V13 - AVGV20) ^ 2 + (V14 - AVGV20) ^ 2 + (V15 - AVGV20) ^ 2 + (V16 - AVGV20) ^ 2 + (V17 - AVGV20) ^ 2 + (V18 - AVGV20) ^ 2 + (V19 - AVGV20) ^ 2) / 20) + .5, 20)*(-1)+1) + HAVG((C - AVGC20) / 4 / STDDEV20 + .5, 20)) > .02 = TRUE---> THEN 4 * SQR(ABS(SUM((IIF(O < C, H - L, L - H)) ^ 2, 150) - 150 * AVG(IIF(O < C, H - L, L - H), 150) ^ 2) / 150) + LOW
Hope that clarifies things
thanks
|
|
Registered User Joined: 9/18/2017 Posts: 20
|
Oh I see.. you're saying if it wasnt true.. If it is not true you can put 0
|
|
Registered User Joined: 9/18/2017 Posts: 20
|
Thanks Bruce!
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
The 1 / 0 at the end of the formula is what produces the division by zero error so it doesn't return anything when false. If you replace it with zero, you get the following.
IIF((HAVG((V - AVGV20) / 4 / SQR(((V - AVGV20) ^ 2 + (V1 - AVGV20) ^ 2 + (V2 - AVGV20) ^ 2 + (V3 - AVGV20) ^ 2 + (V4 - AVGV20) ^ 2 + (V5 - AVGV20) ^ 2 + (V6 - AVGV20) ^ 2 + (V7 - AVGV20) ^ 2 + (V8 - AVGV20) ^ 2 + (V9 - AVGV20) ^ 2 + (V10 - AVGV20) ^ 2 + (V11 - AVGV20) ^ 2 + (V12 - AVGV20) ^ 2 + (V13 - AVGV20) ^ 2 + (V14 - AVGV20) ^ 2 + (V15 - AVGV20) ^ 2 + (V16 - AVGV20) ^ 2 + (V17 - AVGV20) ^ 2 + (V18 - AVGV20) ^ 2 + (V19 - AVGV20) ^ 2) / 20) + .5, 20)*(-1)+1) + HAVG((C - AVGC20) / 4 / STDDEV20 + .5, 20) < .02, L + 4 * SQR(ABS(SUM((IIF(O < C, H - L, L - H)) ^ 2, 150) - 150 * AVG(IIF(O < C, H - L, L - H), 150) ^ 2) / 150), 0)
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 9/18/2017 Posts: 20
|
Hey Bruce I had another question regarding PCF coding..
Can you please help me put this into PCF:
newhj=highest(close,20)
newlj=lowest(close,20)
cfj=iff(newhj>(-1*newlj),100/newhj,-100/newlj)
hullmaj=avgline*cfj
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Are you sure this code is correct? I am guessing that highest and lowest correspond to TC2000's MIN() and MAX() functions and not to the GREATEST() and LEAST() functions.
newhj=highest(close,20)
MAXC20
newlj=lowest(close,20)
MINC20
cfj=iff(newhj>(-1*newlj),100/newhj,-100/newlj)
IIF(MAXC20 > -MINC20, 100 / MAXC20, -100 / MINC20)
hullmaj=avgline*cfj
The avgline variable is not defined, so I can't create a formula using it.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 9/18/2017 Posts: 20
|
Sorry can you swap the Avgline with close on that last part? Would i be able to just change the source from price to something else?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
newhj=highest(close,20)
MAX(C, 20)
newlj=lowest(close,20)
MIN(C, 20)
cfj=iff(newhj>(-1*newlj),100/newhj,-100/newlj)
IIF(MAX(C, 20) > -MIN(C, 20), 100 / MAX(C, 20), -100 / MIN(C, 20))
hullmaj=close*cfj
(C) * IIF(MAX(C, 20) > -MIN(C, 20), 100 / MAX(C, 20), -100 / MIN(C, 20))
I rewrote things a bit to make it easier to just substitute whatever you want in for C .
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 9/18/2017 Posts: 20
|
Thanks bruce! perfect
|
|
Registered User Joined: 9/18/2017 Posts: 20
|
The 1 / 0 at the end of the formula is what produces the division by zero error so it doesn't return anything when false. If you replace it with zero, you get the following.
IIF((HAVG((V - AVGV20) / 4 / SQR(((V - AVGV20) ^ 2 + (V1 - AVGV20) ^ 2 + (V2 - AVGV20) ^ 2 + (V3 - AVGV20) ^ 2 + (V4 - AVGV20) ^ 2 + (V5 - AVGV20) ^ 2 + (V6 - AVGV20) ^ 2 + (V7 - AVGV20) ^ 2 + (V8 - AVGV20) ^ 2 + (V9 - AVGV20) ^ 2 + (V10 - AVGV20) ^ 2 + (V11 - AVGV20) ^ 2 + (V12 - AVGV20) ^ 2 + (V13 - AVGV20) ^ 2 + (V14 - AVGV20) ^ 2 + (V15 - AVGV20) ^ 2 + (V16 - AVGV20) ^ 2 + (V17 - AVGV20) ^ 2 + (V18 - AVGV20) ^ 2 + (V19 - AVGV20) ^ 2) / 20) + .5, 20)*(-1)+1) + HAVG((C - AVGC20) / 4 / STDDEV20 + .5, 20) < .02, L + 4 * SQR(ABS(SUM((IIF(O < C, H - L, L - H)) ^ 2, 150) - 150 * AVG(IIF(O < C, H - L, L - H), 150) ^ 2) / 150), 0)
Hey Bruce,
I had a quick question about this part of the formula.. Is there a way that I can plot a horizontal line at the value every time it is true?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Have you tried plotting it as a Custom PCF Indicator using the Last Value Horizontal Plot Style?
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 9/18/2017 Posts: 20
|
Yes, but is there a way to plot the historical points as horizontal lines as well for a given amount of bars back?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
No, about the best you can do is use the Dots Plot Style.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |