Trading Rule Syntax
Transaction rules use the same syntax as indicators. A rule should yield one of the following
results: "True" or "False". If the
result is "True", the system will perform the relevant transaction (e.g. open a long or a short
position). If the result is "False"
the system takes no action.
As an example of an investment rule: Enter Long: cross(CLOSE, mov(CLOSE,12,Simple)) If the formula is entered into the system as the long position opening rule the system will open it the moment the closing price intersects from below the average of closing prices from the last 12 periods. The situation is similar in the next example: a long position is opened when MACD is> 0 ("macd()" is a built-in function). Enter Long: macd()> 0 Rules may include all indicators created by the user. This is done by the fml() function - see below for syntax: Enter Short: fml("My Formula")> 0 You can combine several functions within a rule using logical operators "AND" and "OR". Enter Long: macd()> 0 AND CLOSE> mov(CLOSE,12,S) The above rule requires that two criteria be met at the same time - MACD > zero and closing price > 12-period closing price average. The following rule uses the "OR" operator to open the position the moment that MACD is < zero or the closing price falls below the average. Close Long: macd() <0 OR CLOSE "AND" and "OR" operators may be used more than once within a rule. The best way to ensure that your commands are correct is to use brackets properly - see below. Enter Long: (macd()> 0 AND C> 100) OR H-L>5 The above transaction will be launched once the following criteria are met:
Interest earned on equity while the system was out of the market. The interest rate can be defined in the "System Testing Options - Annual Interest Rate %" field. You can leave rule fields empty - however an undefined rule will not trigger a transaction. Transaction rules may only refer to unit data (O, H, L, C, V, OI) and indicator functions. You cannot make a reference to the same transaction system (e.g. to the number of days from the previous transaction generated by the system). However, some STOP lines may use such references. Variables can be used as system tester rule permit. However, multiple run idicator formulas (i.e. such formulas which results in an indicator including multiple lines) are allowed, except that the system tester will only use the last line of the formula. More: Using the Alert() function The alert() function is combined with the other functions to extend the validity of a signal by a specified time. The signal is extended by that time even if another signal is generated in the meantime. The following example illustrates the use of this function: Enter Long: RSI(14) <30 AND alert(VOLUME> 500,3) The system would open such long position if RSI were lesser than 30 and the volume greater than 500 at any point in time during the three periods preceding the decrease in the amount of RSI. The "Volume > 500" criterion will be met even if during those periods the volume falls below 500. If you delete the alert() function from the above rule, both criteria (RSI(14) and VOLUME>500) would have to be met at the same time. Using the alert() function enables the user to carry a once fulfilled criterion forward to the next periods.
|
