Formula 301 – #1 Trading System Concept and Our First System

In Formula 301, we are going to focus on writing trading systems with the indicator formula language. The assumption is that you know the basics of writing indicator with the formula language. I will present trading systems that illustrate the usage of specific trading system related writing techniques.

(Lawrence – I understand that Formula 201 is not written yet at this point in time. If you do not know how to write indicators with the formula language yet, don’t worry, you will still be able to follow these tutorials and learn the basics of system writing along the way. 2005 Oct 6)

Indicator is the Host of Trading System Object

To understand how trading system works in NeoTicker, I am going to explain how trading system are managed within NeoTicker.

Trading systems are extensions of the indicator instances. An indicator instance is created or initiated when you add one in a chart, utilize one in a quote window formula, or using one in the pattern scanner through indicator filtering. Out of all the indicator instances you have created, only the ones that exist within charts can route the orders to the Order Interface, which has the ability to fire order to your brokerage account, or, if you choose to, the Trade Simulator. This restriction is imposed for an obvious reason – we do not want you to place orders by mistakes, like you mistakenly used an indicator in a quote window which fires order on your behalf.

That does not mean that you cannot use indicators that have trading systems in quote window, quote memo, etc. You can access all the plot values and various calculated results of these indicators just like any normal indicators. The only difference is that you cannot route orders from these indicator instances.

The NeoTicker Model of System Writing

Now, we are going to discuss the metaphor used by NeoTicker in implementing trading systems.

Each trading system attached to the indicator instance records your order placement actions and order management actions. The orders when processed (either simply based on historical account, or by order processing through the brokerage interface), results in trades being recorded, and eventually positions created from the trades.

This approach is called realistic formalization because it actually captures exactly what we do in real life – we have to place an order, wait for the fill confirmation (resulting in a trade) and then positions are created (that we are long, short, or flat with the market we trade).

The disadvantage of realistic formalization is that it deviates from the more common approach (what most other trading programs do) of skipping all these details and simply draw the conclusion based on the historical data. For backtesting purpose, where accountability is not that important, and collecting the necessary statistics is the objective, you will not find a lot of problems with the shortcut approach.

The advantage of realistic formalization is that it outshines the shortcut approach in all aspects when the system is indeed expected to be deployed in real life. That is especially more important when the trading systems are actually integrated with real brokerage interface (or in realistic simulation) – every order can be accounted for and every trades can be traced down for analysis, worst case scenerios can be projected easily, order abnormalies can be tested in simulation, orders with multiple fills can be simulated, and systems that work with multiple symbols can be properly tracked.

Writing a trading system using actual order placement in NeoTicker is no more complex than the shortcut approach. It actually gives you the extra control of every order, enabling you, the system designer, the ability to properly design and manage the system exactly the way it is supposed to be when you deploy the model.

Formula Based Trading Systems

Indicators written in formula are called formula indicators. To implement trading systems in formula indicators, you need to utilize the trading system functions.

There are a number of functions related to trading system implementation,

1. order placement functions

2. order management functions

3. position information functions

4. account information functions

To implement basic trading systems, all we need are just a few basic order placement functions.

The more advanced trading system functions are useful when your system gets more complex, which requires more detail manipulation of the orders with more complex position management.

A Basic System – Buy Every Open and Sell At the Close

Here is a trading system based on 3 lines of code only, Buy Open Sell Close System. Right click on the link select save to save the system to your local drive and use indicator manager to install downloaded system file.

The system effectively consists of only 3 statements,

longatmarket (true, defaultordersize);
longexitnextclose (true, defaultordersize);
plot1 := currentequity;

What it does is very simple – it buys on every open and then exit at the close of the same bar. The performance of the system is reported through the plotting of the equity level.

I will explain the usage of each function in details.

LongAtMarket (condition, ordersize)

The LongAtMarket function instructs NeoTicker to place an order to buy at market with enough size (contracts or shares) to make the system net long at the ordersize, if the expression condition is evaluated to true (a value not equal to 0).

For example, if the trading system is flat at the moment, then LongAtMarket (true, 100) will buy 100 shares or contracts. On the other hand, if the system is currently short the market 200 shares or contracts, then LongAtMarket (true, 100) will buy 300 shares or contracts to make up the difference so that the system will become net long 100 shares or contracts when it is filled.

The condition parameter true is a constant which always evaluate to 1, that will ensure the LongAtMarket function to place an order every time it is evaluated.

Notice the function DefaultOrderSize used at the ordersize parameter is a trading system function that returns the user defined DefaultOrderSize which is set in the Indicator Setup window, or, through using the Symbol Info Manager.

LongExitNextClose (condition, ordersize)

When the parameter condition is evaluated to true (any value not equal to 0), an order will be placed to reduce the current long position by the size of the ordersize parameter at the close of the next bar. If the trading system is currently in a flat situation (no position at all) or in a short position, then even if the condition is evaluated to true, no order will be placed.

For example, if the system is net long 200 shares, then LongExitNextClose (true, 100) will place an order to sell 100 shares at the close of next bar. Or, if the system is net long 100 shares, then LongExitNextClose (true, 200) will place an order to sell 100 shares only, because the total long position is only 100 shares.


The CurrentEquity function is an account information function. It returns the current equity level of the trading system based on the accumulated performance of the system so far throughout the history of the chart.

For this simple system, we have already used 4 different trading system functions!

The System Performance

Here is how the chart looks like when the trading system is applied to daily emini S&P over the past 5 years.

formula301 part1 order placing

One important issue related to trading system is the settings that you can adjust in the Indicator Setup window. For emini S&P, you need to set the price multiple to 50 and minimum tick size to 0.25. You can also change the Default Order Size right in the same system tab,

formula301 part1 system setup

It is pretty obvious that this is a system that lose money. Well, the market is not really friendly towards somebody who simply try to take advantage of the classic market bias of going up over time, isn’t it?

A Twist In The System

Here is a new version of the same trading system with basic filtering, Buy Open Sell Close System Filtered.
Right click on the link and save file into your local dirve, then use indicator manager to install the downloaded file.

What this new system does is that it only trading on days that meet our criteria specified in the parameter.

makeindicator (cond, fml, data1, param1);
longatmarket (cond, defaultordersize);
longexitnextclose (cond, defaultordersize);
plot1 := currentequity;

Since I want the flexibility to change the condition easily for research purpose, the parameter is declared as a formula parameter, that enables the user the ability to access the Formula Editor when necessary. In our code, however, it is simply a string and in order to utilize it, we need to use the fml indicator to evaluate the formula stored within the parameter.

For example, if we specify the following condition to not trade on Tuesday and Friday,

formula301 part1 filter setup

The system will perform so much better (well, at least making some money) I think you will be shocked,

formula301 part1 filter chart


Remember that robust and profitable systems do not have to be very complex, its the ideas behind that counts. The usual obstacle for most people is that they do not know where to start and how to translate their ideas into something that can be backtested properly.

The subject of trading system writing, however, is very complex; due to the fact that there are so many types of trading systems based on vastly different underlying concepts. I will try my best to walk you through the basics techniques, and provide you with the necessary tools, so that you can translate your ideas into trading systems you want.

Discuss this article.

2 Comments on “Formula 301 – #1 Trading System Concept and Our First System”

  1. bill Says:

    this lesson is a good start to better understanding trading systems…I hope to see more
    and hopefully also a little about compresseries so that accurate enty/exit signals can be implemented

  2. Lawrence Chan Says:

    compressseries is a more advanced topic and will be covered in both Formula 201 on constructing complex indicators and Formula 301 on creating more complex trading systems.

Leave a Comment

Blog Developed
By ContentRobot