Home                           

 Try Investor/RT             

 Investor/RT Tour           

 Getting Started              

 What's New                  

 Testimonials                 

  Q&A - Broken down by Topic . . .      Complete List of Questions - All Topics
     Charts and Technical Indicators      TPO Charts
     RTL: Scans, Signals, and Custom Indicators      Importing and Exporting
     Trading Systems and Backtesting      Schedules
     Quotepages, Portfolios and Custom Columns      Alarms / Alerts
     Data: Historical Data, the Database, and Data Services      User Variables (T# and V#)
     Custom Instruments: Spreads and Pairs      General / Miscellaneous
     Controls, Windows, and the Button Indicator      Autotrading
     Slide Shows      Product Line

 
Q&A Home

Investor/RT Answer
Answers to Common Questions

   

Question

I have several questions regarding the RTL language with respect the if/then/else statements, nested statements, comments, and multiple statements or expressions.  Where can I find this information?
   

Answer

Can you break expressions up on multiple lines?

Yes, just end each line with a semi-colon. The following Signal gives an example:

SET(V#1, MA / CL);
IF(V#1 > 0) THEN (SET(V#2, HI)) ELSE (SET(V#3, LO));
V#1 > 0

The actual true/false result of the signal will be the result of the last line (V#1 > 0). The first two lines just server to manage variables.

Can you nest if-then-else statements?

Currently, this doesn't work very reliably. However, in general, you can use certain tricks to get around this limitation. For instance, assume you wanted to do the following:

IF(CL > OP) THEN (IF(CL > OP.1) THEN (SET(V#5, 3)) ELSE (SET(V#5, 2)) ELSE (SET(V#5, 1));

While that expression won't parse properly, you could instead do the following:

SET(V#5, (CL > OP) * ((CL > OP.1) * 3 + (CL <= OP.1) * 2) + (CL <= OP) * 1);

Or you could just use two lines with:

IF(CL <= OP AND CL <= OP.1) THEN (SET(V#5, 1)) ELSE (SET(V#5, 2));
IF(CL > OP) THEN SET(V#5, 3);

How do you insert comments into RTL syntax?

Just enclose your comments like this: /* comment goes here */;

For example:

SET(V#1, MA / CL); /* Set V#1 to ration of MA over CL */
IF(V#1 > 0) THEN (SET(V#2, HI)) ELSE (SET(V#3, LO));
V#1 > 0 /* return true if V#1 is above zero */

Anything within the /* comment brackets */ is purely for documentation.

Can you include multiple statements within the scope of an if/else/then if statement?

Yes. You can AND or OR together as many true/false expressions as you like within the if statement:

IF(CL > CL.1 AND CL.1 > CL.2 AND CL > CL.3) THEN (SET(V#1, HI));

And you can AND together as many statements as you like within the THEN or ELSE:

IF(CL > CL.1) THEN (SET(V#1, CL) AND SET(V#2, CL.1)) ELSE (SET(V#1, CL.1) AND SET(V#2, CL));