Skip to main content
Article Contents
Print

How Trading Rules Are Evaluated

In back-tests, for each day (or whatever calendar period was selected in the ‘Evaluate the rules every:’ setting in Test System settings) in the test period, each share in each strategy’s trading list is evaluated once against the trading rules of those strategies. The share being evaluated at any one time is called the evaluated security and its data is used wherever the ‘evaluated security’ is referenced in your Trading Rules, Named Terms or Trading Strategy selection expressions. Historical spreads are estimated.

In Live sessions, each share in the trading list of each strategy becomes the ‘evaluated security’ and is evaluated periodically, wherever it’s data is referenced in your Trading Specification. This happens every time new intraday market data is received, or when ShareScope’s OHLC end-of-day database updates arrive. The minimum period (i.e. the number of seconds) between rule evaluations is specified in RuleTrader Live’s Advanced Settings. Live spreads are obtained from today’s bid-offer intraday data.

Rule Evaluation Order And Rule Types

  • Rules are evaluated in the order they are listed in the Strategy Rules tab of the Trading Specification dialog
  • In back-tests (only) rules that sell are evaluated before rules that buy, so capital from any sale is available for any buy
  • Once triggered, no further trading rules are evaluated again that day, for that share. This prevents sells triggering immediately after a buy, or vice-versa, for the same share
  • If the trade size specified by a triggered buy rule exceeds available funds, then it will not be traded in Test sessions, or signalled in Live sessions. This is not something you need test for. However, this can be modified by the System SettingsShow buy trade-signals, even if there is insufficient cash for the trade‘ (Live sessions only) and ‘Actual trade-size must be at least __ % of the target size
  • Available Trading Rule types are Open Position, Increase Position, Decrease Position, Take Profit, Close Position and Stop-Loss. Decrease Position and Take Profit are the same, as are Close Position and Stop-Loss. The different names are there to allow you to distinguish the intent of the trades in Trading Performance Reports
  • Open Position rules are only evaluated for shares without a position. Increase Position works with shares with or without a position, while all other types are only evaluated for shares with a position, as you’d expect. It is not something you need test for
  • Only long positions are supported. RuleTrader may allow short positions in the near future – if this is something you’d like to see please drop us a line at requests@ruletrader.co.uk

The relationship between traded shares and strategies

A share is associated with the Trading Strategies whose List Selectors selected it for the trading list. Only these strategies can open a position in the share. Normally it’s also only those strategies that can increase, decrease or close a position in the share. However, you can override this latter behaviour, so any strategy can change a position created by a share’s associated strategy.

This can be useful when, for example, you have a set of e.g. loss-prevention rules designed to sell all positions in all strategies, when some macro disaster occurs. To enable this check the ‘Allow strategies to increase, decrease, or close a position opened by another strategy’ in System Settings. In the following discussion, mention of the share’s associated strategy should be understood in this context.

What happens when a trading rule is triggered

In back-tests, if a rule is triggered then the trade it specifies is automatically executed.

In RuleTrader Live, when a rule is triggered a trade-signal is displayed in the RuleTrader Signals columns and the name of the triggered rule is displayed in the RuleTrader Rules column. For information on both of these columns please refer to the RuleTrader Columns help topic. You can choose to execute the signalled trade with your broker. Once done, press the Trade Entry button to enter details of the trade. RuleTrader will then transfer this data to the selected ShareScope portfolio and cash-account and then monitor your new position for you.

Once a strategy’s Trading Rule is triggered, no further trading rules are evaluated that day, for that strategy, though they can still be triggered for other strategies. This ensures a sell cannot happen immediately after a buy on the same day for the same strategy.

Action Rules, though, are always evaluated every day, irrespective of trading rules. However, they can only trigger once per day, so if you are using them to update Persistent Terms, then these will be updated once per day (useful if you’re counting days).

Trading Account Priority

If you have multiple trading accounts, then RuleTrader normally executes buy trades in priority order (which is set for each account in the Account Settings). So it starts with the account that has the lowest trade priority and continues up the list until it finds an account that has sufficient cash (in excess of the minimum trade value set in the Trade Sizing tab) to contribute to the buy.

If the account only has enough for part of the buy, then the trade is split between this account and the next account(s) in priority order until sufficient cash is found to make the buy. When the position is sold, cash is returned to each account according to the portion of the position bought by the account.

Normally, any account is used whatever its currency, even when an account’s currency is different to the traded share’s price currency (the price is simply converted automatically). This behaviour can be changed in System Settings, so that account’s with the same currency as the share are traded first.

Company Results Lag

ShareScope does not store the date when a company’s results are released. In Live sessions it’s not an issue, as company results are obviously only available in ShareScope after they are released.

However, in back-tests, if your trading system has access to a company’s results before they were actually released, then this would positively bias the performance of your system. To avoid this, during back-tests RuleTrader assumes the worst-case for the release of company results. For a full listing the exchange requires all companies to have released their results 4 months after the end of their financial year (which is a date that ShareScope does store). So RuleTrader ensures your system can’t see those results until that 4 months has passed. Similarly, for AIM and non LSE shares, RuleTrader enforces a lag of 6 months after the company’s year-end. If you wish, you can adjust these lag periods in the Test Assumptions settings.

Spread Estimation In Back-Tests

RuleTrader estimates historical spreads using three historical estimators, plus today’s time-weighted average spread, then takes the average of all four results to produce the historical average spread used in back-tests. The estimators are designed to err towards a worst-case estimate, so your back-test results should always be conservative, rather than over-optimistic. The three estimators used by RuleTrader are:

  • EDGE Bid-Offer Spread Estimator: described by Ardia, Guidotti, and Kroencke in their July  2021 paper “Efficient Estimation of Bid-Ask Spreads from Open, High, Low, and Close Prices
  • Volume/EMS Spread Estimator: based on the exponential relationship between a share’s spread and the ratio of its trade volume, on a particular day, to its Exchange Market Size (EMS)
  • Market Capital Spread Estimator: based on the exponential relationship between a share’s spread and its market capital on a particular day
Scroll to Top