Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

If then else arguments Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
dsgofman
Posted : Monday, September 18, 2017 9:44:36 PM
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!

Bruce_L
Posted : Tuesday, September 19, 2017 8:18:00 AM


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
dsgofman
Posted : Tuesday, October 17, 2017 7:46:47 PM
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!

Bruce_L
Posted : Wednesday, October 18, 2017 9:43:17 AM


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
dsgofman
Posted : Thursday, October 19, 2017 12:40:09 PM
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!

Bruce_L
Posted : Thursday, October 19, 2017 12:53:35 PM


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
dsgofman
Posted : Thursday, October 19, 2017 1:18:50 PM
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

dsgofman
Posted : Thursday, October 19, 2017 1:19:42 PM
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

dsgofman
Posted : Thursday, October 19, 2017 1:20:22 PM
Registered User
Joined: 9/18/2017
Posts: 20

Thanks Bruce!

Bruce_L
Posted : Thursday, October 19, 2017 1:23:30 PM


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
dsgofman
Posted : Tuesday, October 31, 2017 8:10:11 PM
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
 
Bruce_L
Posted : Wednesday, November 1, 2017 9:24:40 AM


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
dsgofman
Posted : Wednesday, November 1, 2017 10:10:21 AM
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?

Bruce_L
Posted : Wednesday, November 1, 2017 10:18:15 AM


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
dsgofman
Posted : Wednesday, November 1, 2017 10:55:38 AM
Registered User
Joined: 9/18/2017
Posts: 20

Thanks bruce! perfect

dsgofman
Posted : Monday, November 6, 2017 11:41:26 AM
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?
Bruce_L
Posted : Monday, November 6, 2017 11:45:41 AM


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
dsgofman
Posted : Monday, November 6, 2017 12:16:52 PM
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?

Bruce_L
Posted : Monday, November 6, 2017 12:22:27 PM


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
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.