The Rules Editor - Build a simple system Part(1) |
Top Previous Next |
Understanding Mechanica’s system of “pages” Mechanica logically breaks the trading process down into five separate tasks:
To facilitate these various tasks, Mechanica employs the concept of pages. Trading rules, position sizing rules, and other parts of your system are entered directly into the tabbed pages of Mechanica’s Rules Editor, which is a structured text editing utility. Page is simply a metaphor used to refer to one of the five (5) tabbed text-editing screens it contains. The Rules Editor is where the code that comprises your program, or system, is entered. Code refers specifically to the text portion of your system, which is composed of Mechanica Basic language keywords. The words program and system refer to the complete body of your code (and are used interchangeably in this document).
The first three (3) pages contain the code for your Signal Rules. These rules are responsible for trade generation, and are stored in files with the extension *.sig. The last two (2) pages contain the code for your Positions Sizing Rules. These rules are stored in files which carry the extension *.siz. The Signal Rules are always run first, since they are responsible for generating the trades from your system(s). The Positions Sizing Rules are applied later.
Let’s examine the first three (3) pages of the Rules Editor. The first page is the Resources page. This is where you tell Mechanica which data to display in the Grid. The grid is comprised of Columns which you populate with stored or computed data (High, Low, averages, etc.) and other technical indicators and values your program will look at or reference day-to-day. Example: COL1 = HIGH The Trade Entry page is the place to tell Mechanica when and where to enter trades. The code you put here governs Mechanica’s activities while it is searching for a trade entry signal (which it does any time your system is not currently in a trade). Example: IF CLOSE[1] > COL1[1] THEN BUYOPEN The third page is the Trade in Progress & Exit page. This is where you tell Mechanica how to handle an exit stop, and when to exit a trade. Example: SELLSTOP = COL4[1] The code on the Trade In Progress & Exit page governs Mechanica’s activities while it is in a trade, such as determining when to exit, and tracking daily risk calculations. The fourth and fifth pages are the Initial Size and the Resize pages. On the Initial Size page, you (a) tell Mechanica the conditions under which new trades are to be accepted or rejected, and (b) determine the number of contracts or shares to put on, once a trade is accepted. Here is a simple Initial (position) Sizing statement: Example: NEWCONTRACTS = (TOTALEQUITY *.02) / NEWRISK The Resize page is where you will tell Mechanica how, and under what circumstances, open trades are to be resized: The code on these two pages is critical to the ultimate performance of the systems you create, and is discussed in detail later in this help document.
Mechanica’s Rules Editor is a full-featured Windows text-editing facility designed to make it easy for you to enter and modify your program code. When you launch Mechanica, the Rules Editor should be open and ready for use. If not, it opens automatically when you open a Signals file or a Sizing file (File menu, Open). To begin work with the Rules Editor, select the page you want to edit by clicking on its tab, or by pressing its corresponding Function Key (F2 - F6). The cursor will automatically appear at the top left of each page.
Other commonly used Rules Editor keystrokes are listed in the Navigating Mechanica section.
Notes on Terminology:
The term symbol is always used in the context of Mechanica’s Symbol Manager, because under the Tag Symbols tab, we “tag” the symbols we want to test.
|