Formula 301 – #2 Basic Controls

We are going to study another basic trading strategy, buy close and sell next open. At the same time, we will go over the basic options in NeoTicker for the control of trading systems.

Buy Close Sell Next Open

Similar to the Buy Open Sell Close system from the first tutorial, this system is just 3 lines,

longnextclose (true, defaultordersize);
longexitatmarket (openpositionlong, openpositionabssize);
plot1 := currentequity;

Here is the system, Buy Close Sell Next Open System. After downloading the system file use indicator manager to install the system file before it can be run in NeoTicker.

It consists of 2 new order placement functions,

LongNextClose (condition, ordersize)

This function will place an order to get the system into a net long position at the size of ordersize if the parameter condition is evaluated to true (not zero).

In real-life situation, this order placement function leads to a lot of complications. For example, if this function is applied on a 5-minute bar, then, what do we consider as the close of the bar? Should that be the last 5 seconds from the supposed ending time of the bar, or, should that be 10 seconds? For a 10-tick bar, should the order be placed at the arrival of the last tick, or, should that be placed at the tick before the arrival of the last tick?

Those questions are both valid and important issues if you are going to deploy your trading systems. I can assure you that there are complete tool set within NeoTicker for dealing with these issues. I raised the questions because they are important considerations and you should be aware of them when you design your systems using next close orders.

Another interesting issue is that NeoTicker does not allow any type of current bar close orders to be placed. The reason is that it is completely against the design principle of NeoTicker due to the fact that orders that try to get the current closing prices are peeking into the future and such orders are contaminated with information that should not be known when you place your orders – namely, the closing price of the current bar.

Providing such order placement functions in NeoTicker is very easy, but we prefer not doing that because it will make your systems not trustable at all.

LongExitAtMarket (condition, ordersize)

This function place an order to sell enough contracts or shares to reduce system from the current net long position into a reduced net long position (if ordersize is less than the current net long size) or into flat position (if ordersize is equal to or greater than the current net long size).

And 2 new position information functions are used to assist the order placement decisions,


This function returns 1 if the system is currently net long. If the system is net short or flat, then it returns 0. It is a very useful function that helps you to block or enable any particular orders from being placed.


This function returns the size of the current position. So, no matter you are net short 10 contracts or shares, or net long 10 contracts or shares, this function only returns the value 10.

It is obvious that this function is designed for systems that have multiple entries leading to variable position size. In real-time deployment situation, it is also the preferred method to get the current exact position size.

Visual Markings

How does this system look like on the chart?

formula301 part2 chart

The markers you see on the chart are enabled when the system has its option, Enable Chart Markings, turned on.

There are 2 ways to toggle this option, you can either do it through the indicator popup menu, Trading System>Enable Chart Markings, or, using the indicator setup window, under system tab, in the Visual options.

Setup Options

In the indicator setup window, under system tab, there are a number of options affecting your backtest results.

formula301 part2 setup

I am going to talk about the more common options here,

Initial Capital – The amount of money that the system starts with. This figure is not really important for simply backtesting purpose. In more advanced trading system that will be deployed, you can use this figure to help the system deciding what to do in terms of position size, or money management.

Interest Rate – it is useful for the measurement of the system’s performance. It does not affect the trading system in general.

Price Multiple – it specifies the value represented by the symbol you are testing. For example, stocks have price multiple equals to 1 because every move of 1.0 for each share equals to $1.00 in face value. Emini S&P has a price multiple of $50 because for every move of 1.0 in its value equals to $50 per contract.

Min Tick Size – it specifies the minimum movement of the symbol you are testing. For stocks, it is simply 0.01. For other instruments like commodities, it is more complicated. For emini S&P, it is 0.25. For emini NQ, it is 0.50. This value affects the trading system’s decision in what price to recognize as the filled price for various orders. It will enforce the system to use the closest Tick as the filled price.

A good example is the emini S&P, which has a minimum tick size of 0.25. If you place an order based on your calculations, say, from some moving average, to go long at 1100.37 limit, then the proper price that the system gets its fill is actually 1100.25, not the moving average value.

Deci / Frac – this option is a visual control option. What it does is to control the price display formatting in the reports. For example, if you are testing your system against a stock, you can simply leave it at 2. That means 2 decimal places. If you are testing against Forex, you can set it to 4, it will then display the price related information with 4 decimal places. And if you are testing bond futures, you can set it to ^32, it will then display everything in fraction.

There is no need to remember all these details, just press the button next to this field; you will be able to specific the formatting code using the more intuitive entry form.

Margin Type – The type we need to use with future contracts is Amount. What it means is that a specific amount of cash is needed for holding one contract. You can then specify the exact amount in the Margin Value field. If you are trading stocks, you will then choose the Cash or Percent type instead.

Margin Value – the value you entered at this field is subjected to interpretation based on the Margin Type field. For example, our current selection of Amount in the Margin Type field means that the Margin Value we have is the exact amount needed on a per contract basis to fulfill the margin requirement.

If you are testing a simple trading system then you can ignore this setting completely.

Order Size – It is also known as the Default Order Size. Within the formula indicators, we use the function DefaultOrderSize to access this value.

Single Entry Per Direction – To reduce complexity caused by complex position management rules, this option is introduced to help system designers to reduce the coding complexity.

Whenever this option is enabled, then orders placed that may increase the current position size in the same direction, will be rejected.

Close Position EOD – If you do no know how to place orders to close out your day trading positions, then you can turn this option on, NeoTicker will try to manage the system for you.

System Performance

This system is simple, but, surprisingly to many people, it does make some money.

formula301 part2 chart overview

To take a more detail look into the performance of the system, you have to use the system performance viewer to review the details of the trading system. You can use the indicator popup menu, Trading System>Open Performance Viewer, to open the system performance viewer.

formula301 part2 sys performance

Aside from the Trade Summary report, you can also review the other reports by selecting them from the list at the left hand side. Here is the Annual Summary.

formula301 part2 sys annual return

Filtered Version

The original system is not as consistent as we hope for. For the past few years, its performance is less than desirable. Can we do something about it?

Its time we utilize the flexibility of formula parameters.

Here is a modified version of the system taking into account of your customized condition, it takes just 1 more line,

makeindicator (cond, fml, data1, param1);
longnextclose (cond, defaultordersize);
longexitatmarket (openpositionlong, openpositionabssize);
plot1 := currentequity;

You can download the system here, Buy Close Sell Next Open Filtered System, after downloading the file use indicator manager to install it before it can be used in NeoTicker.

Since we tried an interesting filter that avoid going long on Tuesday and Friday in last tutorial and is getting some good results, I am going to show you the same filter applied onto this system to see if that really helps,

formula301 part2 filtered chart

Well, the filter is doing its magic again, which further proves that this filter deserves further investigation.


We are learning a few more functions related to trading system. By combining the functions we’ve learned so far, you should be able to produce many basic trading systems already.

Do not just sit there – if you want to learn how to develop your own trading systems, then you have to learn it the way how we learn everything else, keep practicing!

Discuss this article.

Leave a Comment

Blog Developed
By ContentRobot