Using Scans, Trading Signals and Custom Indicators Within a Scan or Trading Signal

The expressive power and ease of use of the RTL language has been improved substantially in Version 4.5 by the capability of referencing other scans, trading signals, and custom indicators when formulating an RTL expression for a scan or trading signal. New tokens have been introduced into RTL to enable the user to embed an existing scan (token SCAN), custom indicator (token CI), or trading signal (token SIGNAL) into the RTL expression. Multiple SCAN, CI, and SIGNAL tokens can be incorporated into a scan or trading signal just like multiple moving average (MA) tokens. When multiples are used, the user must rename the token(s) to distinguish them from one another.

Here is an example of using a custom indicator inside a scan. First create a custom indicator called "MA_Oscillator" with the RTL formula:

MA_ST - MA_LT

Where MA_ST is a simple short term moving average and MA_LT is a simple long term moving average. This custom indicator when added to a chart window oscillates around the zero line, crossing the zero line whenever the moving average lines cross over.

Now, we can use this custom indicator in a scan to look for moving average crossovers. Create a new scan. From the token list on the left choose CI:Custom Indicator and add it to the list on the right. When you do this Investor/RT will ask which custom indicator you want to use. Choose "MA_Oscillator" from the list of custom indicators. The token list on the right will now contain only one entry with a token of CI. Complete the scan definition using the RTL formula:

(CI.1 < 0 and CI >= 0) or (CI.1 > 0 and CI <= 0)

This scan tests for moving average crossovers from either direction. CI.1 can also be written CI1 (without the period). We use the optional period to separate the token from the historical qualifier to improve readability. Save the scan and run it to find all issues displaying either a bullish or bearish moving average cross over in the current time frame. Add this scan as a "Scan Marker" indicator to a chart. Investor/RT will then mark each bar in the chart for which there is a moving average cross over. Note that the terms of the moving average involved in this analysis are part of the definition of the "MA_Oscillator" custom indicator, not the scan itself, which only references this indicator using the token CI. You can call up the definition of "MA_Oscillator", edit the terms or moving average type preferences of the indicator and save the indicator and Investor/RT will redraw the scan markers accordingly.

In the same way, a scan or trading signal can include other scans and/or trading signals. For example, if you have already created scans called "MACD_Bullish" and "Stochastic_Bullish", you can easily create another scan testing for either of these conditions. Create a new scan, choosing the SCAN token from the list on the left, and choosing "MACD_Bullish" when the list of scans appears. The token in the right side list will initially be called "SCAN". Rename the token to read "MACD_BU". Then add the SCAN token a second time, choosing "Stochastic Bullish" and renaming its token "STOC_BU". Then complete the scan definition with the RTL formula:

MACD_BU or STOC_BU

The scan above will test for either of the referenced scans being true. Similarly,

MACD_BU and STOC_BU

tests for both referenced scans being true.

Sometimes it is useful to see if both conditions have been true within the last few bars since you may miss signals if you look only for both conditions happening on exactly the same bar. The MAX function can be used to test any condition within some specified time in the past. For example:

MAX(MACD_BU, 3) > 0 and MAX(STOC_BU, 5) > 0

tests for a MACD buy signal occurring within the last three bars accompanied by a stochastic buy signal any time within the preceding five bars. Scan, custom indicator and trading signal token can be qualified historical by appending a period and a number to the token. So another way to test to see if MACD_BU has been true during the preceding three bars is to use the formula:

MACD_BU OR MACD_BU.1 OR MACD_BU.2

Whenever a language includes "self-referencing" capabilities, the expressions of the language become eligible for endless loops. In natural languages these are called paradoxes; in computer programming languages they can become infinite loops. Now that RTL contains self-referencing tokens, Investor/RT must guard against such uses of the language to prevent infinite loops. For example, SCAN_A may reference SCAN_B, which in turn makes reference to SCAN_C. If SCAN_C happens to include a test for SCAN_A, the evaluation cycle would repeat forever if left unchecked. Before evaluating scans and trading signals, Investor/RT performs an "endless loop" test. If an illegal scan reference is detected, an error message is displayed and the scan or trading signal is not evaluated.