|
The Trades Section is where the additional columns to display in any Trade List Window are defined.
The first 13 columns of every trade list — Trade, Strategy, Symbol, Side, DateIn, TimeIn, QtyIn, PriceIn, DateOut, TimeOut, QtyOut, PriceOut and Reason — are always present and are not customizable. Everything to the right of Reason comes from this section.
Here is an example of a script (the default trades.RTS) which adds some custom columns:
.png)
Applying this script causes the new columns to be shown in all open trade windows. Here is the resulting trade list, with the fixed columns through Reason followed by the custom ones defined above:
.png)
The context of a Trades formula
The formulas used in the Trades section will most often refer to syntax elements that begin with T.
When a Trade List Window is opened, RealTest loops through all the trade records that are embedded in the results record for that test and calculates each of the formulas in the Trades section for that trade. The context of any T. variable is therefore the specific trade being evaluated in this loop.
Trade List formulas can also refer to any stock bar elements such as Open, High, Low, Close and also any Data section elements. The context when bar/data elements are referenced will always be the bar on which the trade was exited. To refer to the entry bar of a trade, use T.Bars as an offset. For example, the close of the entry bar will be C[T.Bars]. To refer to the EntrySetup bar (the last completed bar at entry time), use C[T.Bars+1] unless EntryTime was ThisClose (market-on-close).
The exception is an item tagged with the {factor} attribute: it is evaluated as of the trade’s setup bar instead, with no offset needed, so that its column shows exactly the value a Factor Scan uses. To see both readings of the same indicator, define it twice — once tagged, once not.
Items that refer to other items
Any item can refer to any item defined earlier in the same section, by name and without regard to case. An item whose name begins with an underscore is calculated but not displayed, which lets a column be built up in readable steps. The default script uses that to derive the excursion columns: _UP and _DN measure the favorable and adverse moves, _MFE and _MAE pick the right one according to T.Side, and only PctMFE and PctMAE become columns.
Formatting and column headings
A format specification comment can be included in any item. If no format is specified, the item will use default number formatting. Both the short-glyph form ({$-2}, {%2}, {#}) and the named-attribute form ({format: dollar, places: 2, negred: 1}) are accepted. The minus sign in {$-2} is what makes losing trades show in red in the screen shot above.
A quoted string in the format block (or {name: "..."}) overrides the column heading, which is the way to use a heading that would not be a legal item name.
Literal strings or string functions such as Format can also be used in custom trade list columns.
Filter and Sort
In addition to the above, there are two special Trades items that can optionally be added: Filter and Sort. Neither one produces a column, and neither name can be used as a column name.
The filter formula is evaluated for each trade to determine whether to include it in the list. A trade is included only if the Filter formula evaluates to "TRUE" or a non-zero value.
The sort specification lets you name the column(s) to use for initial sorting of the rows of the trade list after it is generated. Give a comma-separated list of column names, most significant first, each optionally prefixed with - for descending order — the default script’s commented-out example is -DateOut, Symbol. The names may be any of the 13 fixed columns or any displayed column defined in this section; an unrecognized name is reported as a script error.
Trade list output files
The same set of columns defines the CSV written by SaveTradesAs, so adding a column here adds a field to that file. The exception is SaveTradesType: Compact writes only the fields needed for imported trade list playback and ignores this section.
To apply Trades section formulas to all currently open Trade List windows, press F4 or click Apply. To open the script behind a trade list, press F9 or use the context menu.
See also Default Scripts and Output Format Specification.
|