CTX RTL token

RTL context (scan, backtest, optimization

The CTX token provides a way to determine whether the evaluation of an RTL formula (scan, signal, or custom indicator) is taking place in the context of a backtest, or in the context of a backtest during optimization, or in the context of a quotepage scan. This token may be useful in cases where you may want a trading signal to be computed or a V# variable to be set differently depending on the context. This makes it possible to write one signal instead of two to take the different context into account. For example, you may have a trading system that uses V#22 as a trailing stop value. If you have a trading rule that sets the value of V#22, this would present a problem if you were running an optimization to determine the optimal value of V#22. Using the CTX token you can augment the trading rule by adding:

IF (CTX != CTX_OPTI) THEN SET(V#22, <expression>);

CTX_OPTI is one of several numeric constants added to RTL. Its value (2) is the value RTL will give for CTX when an optimization is the context. The expression CTX = 2 is equivalent but we encourage the use of the CTX_* constants to make the intent of the RTL formula clearer.

The numeric constant tokens that can be used for comparison with CTX are:

  • CTX_BKTST ñ Context is a backtest, optimization is NOT in progress.
  • CTX_OPTI - Context is a backtest, optimization in progress.
  • CTX_QPSCAN ñ A quotepage is being scanned using the scan or signal. This context does not apply to custom indicators.
  • CTX_OTHER ñ This context is a catch all to indicate that the context is NOT one of the previous three.