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 syntax Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
anderton
Posted : Tuesday, March 22, 2005 10:05:52 PM
Registered User
Joined: 11/27/2004
Posts: 85
Hello Worden trainers,

Is is possible to use "if then else" syntax in the TC2005 pcfs? If so, where could I find the formats for the syntax arguments?

Thanks,

Frank
Craig_S
Posted : Wednesday, March 23, 2005 9:29:49 AM


Worden Trainer

Joined: 10/1/2004
Posts: 18,819
There is no documented way to do this in TeleChart.

You can fake an if/then statement by using the SGN() feature of the language.

A SGN() of a Boolean function will return -1 if the Boolean statement is TRUE and 0 if the statement is false. If you multiply a function by the SGN() the function will return a value other than 0 if the Boolean in the SGN() is TRUE.

Here is an example.

If the close today is greater or equal to the close yesterday, then return the volume for today plus the value of the close, else return 0.

(0-1)*(SGN(C>=C1)*(V+C))

If you put this in as a PCF it will return the value of (V+C) as a positive number (because the whole thing is multiplied by -1) if C>=C1. Otherwise it will return 0. This is not perfect because if C and V are 0 it will also return a 0 even if C>=C1 is TRUE.

You can have different things happen if one thing is true or false. For example:

(0-1)*((SGN(C>=C1)*(V+C))+(SGN(C<C1)*(V-C)))

This will add the volume to the close if C>=C1 and will subtract the volume from the close if C<C1.

Does this help?


- Craig
Here to Help!
bustermu
Posted : Sunday, March 27, 2005 12:14:59 PM
Registered User
Joined: 1/1/2005
Posts: 2,645
If...then...else can always be implimented in the PCF syntax. It is usually easiest to do this using the undocument fact that Boolean statements return -1 if True and 0 if False, as stated by Craig. The documented way is to use the signum function, SGN.

The conditional:

If P then
x = a
Else
x = b
End if

and the PCF:

(1+P)*b-P*a

return the same value, a if P is True and b if P is False.

To illustrate the documented way, we will use Craig's example. The conditional:

If C>=C1 then
x = V+C
Else
x = 0
End if

and the PCF's:

1) (0-1)*(SGN(C>=C1)*(V+C))

2) (0-1)*(C>=C1)*(V+C)

3) (1-SGN(C-C1)*(SGN(C-C1)-1)/2)*(V+C)

all return the same value. The first is Craig's PCF, the second is perhaps the easiest, and the third uses only documented methods.

We have only demonstrated that conditionals can be written using documented methods, but, in fact, it can be proved that this can always be done.

Thanks,
Jim Murphy
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.