Trading Related Tokens

Tokens are available in RTL to provide access to brokerage position and working order information when using the trading order features of Investor/RT. When trading orders are sent, Investor/RT will monitor the status of those trading orders and when Investor/RT receives a fill notification, it will record the status of the user's position. The RTL tokens are TR_FILL (the latest fill price for the instrument), TR_POS (the position size, positive for long, negative for short, zero for no position open), TR_TARG and TR_STOP are named variable you can use to store computed stop and limit prices for use in trading orders. These tokens may be used in trading signals to make signal firing dependent upon the state of the trade. For example, a custom column in a quotepage could calculate a stop or target price based on the TR_FILL price and record values which in turn are used when submitting limit or stop orders. The TR_FILL token yields the same value as the ENTRY token, and the TR_POS yields the same value as the POS_SIZE token, except when the signals are executing under a trading system indicator, since ENTRY and POS_SIZE are set by the trading system. We recommend that TR_FILL and TR_POS be used since these token refer specifically and unambiguously to the results reported to Investor/RT by the trading order status feedback from the brokerage.

TR_FILLSECS when you are in a position, evaluates as the number of seconds since the last fill in the position. TR_FILLTIME is number of the form hhmm.ss indicating the time of most recent fill.

The RTL token TR_WORK can be employed in trading signals to make the firing of the signal dependent upon the status of currently working orders. The Trading Rule indicator allows you to put a trading rule into a chart that becomes active only when your market position for the charted symbol is FLAT. The trading rule's signal is tested while you are flat and if the signal is true on the current bar, a trading order is submitted to the broker, e.g. to place a limit order to buy 1 contract. Until the limit order is filled, you remain FLAT. It is important that the trading signal only fire once, otherwise the trading rule might submit multiple limit orders.

This is an example where the TR_WORK token solves a dilemma. By adding the condition (TR_WORK = 0) to the trading rule's signal, the signal is guaranteed to fire true only when there are no orders already working.

TR_WORK evaluates to a number that indicates whether there are orders working and what kind of orders they are. TR_WORK is zero when there are no orders working. Positive values indicate a buy order is working; negative values indicate that a sell order is working. RTL has seven numeric constant tokens, named to reflect the seven status conditions:

WS_NONE is value 0, no orders working.

WS_FLAT_BUY is value 1, current position is FLAT, a buy order is working.
WS_LONG_BUY is value 2, current position is LONG, a buy order is working.
WS_SHRT_BUY is value 3, current position is SHRT, a buy order is working.

WS_FLAT_SELL is value -1, current position is FLAT, a sell order is working.
WS_SHRT_SELL is value -2, current position is SHRT, a sell order is working.
WS_LONG_SELL is value -3, current position is LONG, a sell order is working.

The values have been designed to enable flexible testing for single or multiple conditions easily, e.g.

TR_WORK > 0 tests for a buy working, regardless of position state.
TR_WORK < 0 tests for a sell working, regardless of position state.
TR_WORK = 0 tests for nothing working.
TR_WORK != 0 tests for either a buy or sell order working, regardless of position.

ABS(TR_WORK) = 1 tests for position FLAT, with either a buy or sell order working.
ABS(TR_WORK) = 2 tests for a buy or sell order working that extends the present LONG or SHRT position.
ABS(TR_WORK) = 3 tests for a buy or sell order working that will reduce or close the present position.

The TR_WORK token can be used within any RTL signal, e.g. a signal within the chart associated with a Signal Marker Indicator or a Trading Rule Indicator, or a signal that is used in a rule in a Trading System running in the chart via the Trading System Indicator. TR_WORK references within signals that are used during backtesting will evaluate to zero (no orders working) since Investor/RT backtesting fills are always immediate, on the present bar or upon opening of the next bar during backtesting. When a trading system is run live using the Trading System indicator however, TR_WORK will evaluate to the actual status of working orders in progress with the broker (or with the Investor/RT built-in trading simulator).

The TR_WORK value for each symbol is viewable in a quote page by adding the column named Working Order Status. Thus you can create a custom column referencing this built-in column, and color code the quotepage cell background for each symbol depending on various values of TR_WORK, e.g. shades of green when a buy order is working, shades of red when a sell order is working for the symbol, neutral backgound when TR_WORK is zero, nothing working. A right-click or double-click on any Working Order Status cell in a quotepage opens the Order Status window. This window shows all working order in the current session and their status (working, cancelled, filled).

The TR_WORK token is available for display in chart annotation indicators. For example, setup an annotation with the text %TR_WORK %TICKER in your trading chart. When you have a buy order working the annotation will say something like "FLAT, Working Buy @ES#". Within the annotation setup you can also check mark the Show/Posn box and the annotation indicator will then show both the working order status, the ticker and the trading position, e.g. "LONG, Working Sell @ES# LONG 1 at 1855". Investor/RT normally adds a position status annotation automatically to charts. You may edit this pre-existing annotation indicator, typically displayed in the upper left corner of the chart, and add the annotation text "%TR_WORK %TICKER" to add the working order status display to your trading chart(s).

An easy way to get familiar with TR_WORK is to use the Trading Simulator built into Investor/RT. In the Data > Configure Data Source/Broker window, set the Brokerage Destination to Trading Simulator. Open a quote page, e.g. the Trading List quote page and add the column Working Order Status. Also open a chart for the symbol you will trade and setup the annotation to display the %TR_WORK text. Use the Trading Order desk to simulate various scenarios, e.g. place a limit order to buy 1 contract at a nearby limit price. The quote page display of working order status will update to reflect that working order and the chart annotation will show the working order. After the order fills, the working order status goes to "No working orders". Then place additional working orders and watch the status values change as orders are placed and fills occur.

RTL tokens TR_POS (trading position size) and TR_WORK (working order status) can now be used to formulate RTL signals that trigger trading orders only under certain position and working order status conditions.

Tokens were introduced in Version 12.6 to enable RTL formulas to access the stop or limit price of a currently working trading order, or the order id number of a particular working order. For example, the RTL expression, SET(V#33, TR_SELL_STOP) will place the stop price of the current working sell stop order if there is one working, if not V#33 will be set to zero. Using these stop and limit price tokens, RTL may be formulated, for example, to monitor how far away the last trade price is from a stop or limit price and produce a signal if that distance in price or tick increments is over some threshold. The action associated with the signal could, for example, issue a revise order trading order for the sell stop order to move it up, i.e. a trailing stop. To issue a revise order trading order, the order id of the order you wish to revise must be known. RTL tokens have also been added for accessing the order id number of a particular working order. For example, the token TR_BUY_STOP_OID evaluates to the order id number of the currently working buy stop order. This value can be SET into a V# variable and the revise order trading order will have to specify that V# number as the order id to be revised. Since the OID token evaluates as 0 if there is no working order of the type implied by the token name, these tokens provide a way to test whether a particular kind of order is working, e.g. the expression (TR_SELL_STOP_OID > 0) evaluates as true if there is a sell stop working. The tokens may also be shown inside charts using the Annotation indicator. An annotation with the text Buy Stop ID %TR_BUY_STOP_OID Price %TR_BUY_STOP will display the order id and stop price when there is an order of this type working. Here is the complete list of RTL tokens for accessing price and order id number of working orders.

  • TR_BUY_STOP_OID Buy Stop Order ID”
  • TR_BUY_LMT_OID Buy Limit Order ID”
  • TR_BUY_STOPLMT_OID Buy StopLimit Order ID"
  •  
  • TR_SELL_STOP_OID Sell Stop Order ID"
  • TR_SELL_LMT_OID Sell Limit Order ID"
  • TR_SELL_STOPLMT_OID Sell Stop Limit Order ID"
  •  
  • TR_BUY_STOP Buy Stop Price"
  • TR_BUY_LMT Buy Limit Price"
  • TR_BUY_STOPLMT_STOP Buy StopLimit Stop Price"
  • TR_BUY_STOPLMT_LMT Buy StopLimit Limit Price"
  •  
  • TR_SELL_STOP Sell Stop Price"
  • TR_SELL_LMT Sell Limit Price"
  • TR_SELL_STOPLMT_STOP Sell StopLimit Stop Price"
  • TR_SELL_STOPLMT_LMT Sell StopLimit Limit Price"

Investor/RT Trading Strategy setups allow trading orders to be submitted that contain from 1 to 3 OCO brackets of working stops and targets. Then tokens above, e.g. TR_BUY_STOP_OID refer to the first target and stop in such situations. Advanced usage requires RTL tokens to refer to stop and target prices and order ID for the second and third set of brackets as well. These tokens have the same names as those listed above but include #2 or #3 in the name. For example, TR_#2BUY_STOP_OID refers to the second bracket buy stop order ID; TR_#3SELL_STOP refers to the third bracket SELL stop price. To see the full list of TR_ tokens available, open the RTL setup window (File > New > RTL...) and choose Primative Data Tokens from the token selection menu. Scroll down the alphabetical list to see all of the TR_ tokens listed.