# Build a Trading System using Statistical Methods  The process of trading system design is a process of statistical based price prediction. In this post we will illustrate some basics that show if a certain event can give you the statistical edge to predict future price movements. Once you identify a predictive event it becomes much easier to design a trading system around it.

Our process of designing a trading system starts with identifying price patterns beginning from a specific event. Previous research indicates that there is cycle activity in index futures. The cycle is consistent with the monthly observation that companies make their numbers on a monthly basis (Ehlers, 2013). Since a month consists of 20 trading days we can say that a cycle consists of 10 up and 10 down days (Ehlers, 2013). Therefore we start with the presumption that we want to predict price behavior for the next 10 trading days. Our point of reference is 10 days back in history. Here is the EasyLanguage Code for it:

https://gist.github.com/18182324/00eddb440eff9a97aedbca1455ce600b

The event cycle can be changed to any number depending on the asset you want to analyze. As for our case when an event occurs, the percentage change in prices over the next 10 days is computed. The percentage price is assigned to the variable FuturePrice which is limited between -10% and 10%. After limiting the range, FuturePrice is rescaled to vary from zero to 100. As described by Ehlers (2013) the goal is to accumulate the number of occurrences of a FuturePrice in each of the bins over a time span of 10 years of historical data. The number of occurrences creates a probability distribution function of the prices 10 bars into the future beginning with the occurrence of the event. Another provided measure is center of gravity (CG) which measures the average percentage future price of the probability distribution. As shown in the easylanguage code above, a folder is created on the computer named C:\PDFTest when the last bar on the chart is encountered. The file is then imported into excel to view the probability distribution function by plotting it as a vertical bar chart [how to tutorial for calculating probability distributions in excel]. Here is an example of this process with the complete strategy code (Ehlers, 2013):

https://gist.github.com/18182324/00eddb440eff9a97aedbca1455ce600b

Since we are anticipating the event our trading strategy will enter long when the stochastic crosses a threshold of 0.3 with a stochastic length of 8. After our optimization run the best trading length is found at 14 bars into the future. For simplicity reasons we have set the stop loss at 3.8%. A more effective stop loss strategy could be developed by using more sophisticated money management strategies such as optimal f (Vince, 1992). Applying this strategy to 10 years of data gives us the following equity curve:

The following performance report gives us a detailed evaluation of the strategy:

The outlined strategy represents a general framework for the development of a trading system based on a statistical approach. The framework is capable of assessing whether a price will increase or decrease over X bars after an event. In our test data we have used daily bars but the framework is applicable to any data granularity.

References: