A RealTest script is not really describable as "code", or "a program". Rather, it is a collection of named values and formulas that serve as the input parameters to a general-purpose backtesting engine. These items are organized in Script Sections.
Script sections can be combined in a single script and/or kept in separate scripts that are combined using Include.
Either way, there is logically one big script, so we'll refer to this as "the script" or "the combined script".
It mostly does not matter in what sequence the various sections appear within the combined script.
The sequence of items within a section matters for some section types and not for others.
Each script section has its own special purpose and content, with slightly different rules regarding combination and sequencing.
The categories of script sections are:
Category
|
Sections
|
Items
|
Override
|
Script Sequence
|
Item Sequence
|
Data Import
|
Import
|
have specific names and purposes
|
mixed
|
doesn't matter
|
DataSource must come first, last instance wins for overrides, else doesn't matter
|
Data Calculation
|
Data, TestData, StratData
|
have user-defined names and formulas
|
optional
|
doesn't matter
|
is calculation sequence
|
Data Output
|
Results, Graphs, Trades, Charts, Scan, TestScan
|
have user-defined names and formulas
|
optional
|
doesn't matter
|
is display sequence
|
Formula Library
|
Library
|
has user-defined names and formulas
|
always
|
doesn't matter
|
doesn't matter
|
Parameter Values
|
Parameters
|
has user-defined names and value lists
|
always
|
doesn't matter
|
is optimization sequence
|
Strategy Definition
|
Strategy, BenchMark, StatsGroup, Combined, Template
|
have specific names and purposes
|
never
|
determines default daily processing sequence in tests
|
doesn't matter
|
Script Settings
|
Settings etc.
|
have specific names and purposes
|
always
|
doesn't matter
|
last instance wins for overrides, else doesn't matter
|
Each of the above sections may appear zero or more times in the combined script. (Some Run Modes are only available when the script defines the section to which the mode pertains, e.g. Import for import mode, Strategy for test mode, etc.)
The sections that have specific names and purposes (Import, Strategy, Settings) do not allow user-defined items to be added. The script editor will show you which specific items are available as you are typing. Highlight any item name after typing it and then press F1 to learn more about it.
In some cases, specific items are formulas (e.g. EntrySetup in a strategy), in other cases they are some type of constant setting value (e.g. EntryTime in a strategy -- values from a finite list of choices), and in some cases they are folder or file paths (e.g. SaveAs in import).
The sections that have user-defined names are all have the same format, which is name: definition. Name is any name of your choosing, provided it was not already used in a different section with user-defined names and is not a built-in variable name (reserved word) such as "close".
For sections that allow overrides, writing a new item with the same name as a prior one replaces the prior item definition with the new value or formula. This might be done explicitly in the same script or implicitly by including a script that redefines the item.
The Import section is a special case because some of its items logically can have multiple instances, such as DataSource, DataPath, IncludeList, etc. while other items must be defined once for the entire import, such as StartDate, EndDate, SaveAs, Padding, KeepAdjusted. Combining Import sections from different scripts can easily lead to complexity and must therefore be given careful design consideration and testing.
All the other sections that have items with specific names always allow override of any item by defining it again with a different value. This facilitates combining scripts that define the same items, especially settings.
The sections that allow optional name override disallow it by default -- the parser will show an error message if a name is reused and the script doesn't specify AllowSameName: True in Settings.
If this setting is specified then items in any of those sections can be replaced by defining a different item with the same name in the same section type. (It is always an error to try to use the same name in different section types.)
For special use cases where you would like to use the same name in various scripts, sometimes combine those scripts, and NOT override any user-defined names, RealTest provides an optional Namespace mechanism. See that topic for details.
Conditional Comments can also be very helpful when combining scripts.
|