Posts Tagged ‘Forex system’

Statstical Forex System — Example MT4 Expert Advisor

Wednesday, August 20th, 2008

After saying so much about the statistical Forex systems, I think it’s time to give an example of one. But first, I have to warn that this exert advisor «as is» wasn’t profitable during tests — it had its losses and gains, but spread losses took over eventually, so I can’t suggest using it on your real money account. This expert advisor is good only as an example of an actual statistical Forex system. It uses Tom DeMark’s pivot points calculated over the last 5 bars, which are then normalized by subtracting the current Open price. I used it on EUR/USD H1 chart, but I believe that it can be used on any other currency pair and timeframe. It consists of two .mq4 files:

The first file is StatGathererExample.mq4 — as it appears from its name, this MetaTrader EA will only gather statistics. Run it via strategy tester on a 1-2 year history period (it doesn’t have to be a good quality history, because it has nothing to do with price ticks, and uses just your OHLC data from bars; just be sure to have enough bars in your chart). This EA gathers statistics over a period of time and stores it to MapPath file («rl.txt» by default) in your /tester/files/ directory. Copy it to /experts/files/ for further use by the actual expert advisor.

And the second file is StatRunnerExample.mq4 — this EA is used for the actual trading and on-the-fly statistics gathering. This EA uses MapPath file («rl.txt» by default) from your /tester/files/ (for strategy tester) or /experts/files/ (for actual use) to get the initial statistics. It also continues to gather its own statistics and appends it to the initial file, saving it after deinitilizing.

You can freely use these examples to construct your own statistical Forex systems. I am also currently developing a statistical expert advisor that would be profitable and I promise to share it after the testing period.

Statistical Forex System — Complexity of a System

Monday, August 18th, 2008

The final part of my introduction into statistical Forex system development is dedicated to the complexity of the resulting expert advisor (or automated program if you want to create such strategy for anything else than MetaTrader platform).

When traders think about Forex system, they come to a conclusion that a simple trading system can’t be profitable, because it doesn’t capture all the market parameters that influence the dynamics of the currency pairs. Partially I agree with this point of view but, in my opinion, the complexity of a Forex system should be limited. With the statistical Forex systems the complexity of different parts may vary.

  1. The amount of different information and the number of data types that is gathered for the statistical system are the important parameters, which if increased produce a more complex system. One may decide to gather not a single timeframe information, but rather statistics from several timeframes and record not only the price quotes (or OHLC data for bars/candles) but also many indicators, calculations and other parameters. This will lead to rather large database of the statistics that would be hard to interpret in a right way, but if interpreted correctly it will surely yield better results than a more simple strategy.
  2. Gathering statistics before the actual strategy running is extremely important and is a necessary step, in my opinion. But making a system that can continue gathering statistics when it runs in a real-time is also important. It shouldn’t add much complexity to your expert advisor, but it will help to react faster on the market changes. Of course, such on-the-fly data gathering can’t substitute the pre-running gathering.
  3. Changing the way of the interpretation and statistics comparing is a really advanced method to add the complexity to your statistical system. Having several functions to compare the past and the current data can be helpful if you have some method to choose from these functions. Personally I couldn’t develop a system that would use such an interesting functionality.
  4. The complexity of the actual order carrying and position handling is a rather obvious field for the system improvement and upgrading, but it hardly can be connected to the statistics that can be gathered. The only way that would work, in my opinion, is if your system uses real chart-to-chart comparison - that’s a really difficult method, but it opens a whole new set of opportunities for position and order adjustment. In other cases, simple buy/sell/hold decisions are the best market actions available for the statistical Forex systems.

Those are the most obvious ways to make your trading system more complex. Some minor changes can also improve it to make it react more flexibly on the market volatility and evolution. If you have experience with really complex Forex systems that are based on the trading statistics, feel free to comment on this post.

Statistical Forex System — Decision Making

Sunday, August 17th, 2008

After statistical Forex systems were introduced in my blog, I’ve described the problems of timeframe selection and statistics gathering. Now it’s time to discuss the decision making problem of such trading systems.

When a completed strategy has enough statistical information and a sample from the current market situation it should have some methods of comparing the statistical information with the sample and make the decision regarding its further actions on the market. For the majority of the systems these decisions would be limited only to buy, sell, hold and close previous position actions, while more advanced systems may include position adjustment actions into their arsenal.

The most obvious way to make the decision for the statistical Forex system is to calculate the differences between the sample data and the data stored in the statistics and the lowest difference will point out the most probable recorded outcome. For example, if you recorded RSI indicator values and the current RSI reading is 75.2, while the lowest difference from your statistics is 0.1 and it suggests that the price goes down near that RSI level, then your system should probably generate a sell signal. This method looks simple, but it’s also flawed as the comparing multiple parameters of the two samples is impossible.

In general, quotes-derived parameters should be compared with some method similar to Euclidean distance (best distance, average distance, etc.) with possible weighing of the different parameters according to their importance. Meanwhile, the comparison of the time- and fact-based parameters should be rather strict — e.g. if you recorded some information specific for Fridays and it’s Monday today, then you should disregard this information.

Another noteworthy idea regarding decision making would also require a special statistics gathering method used in the system. Using self-organizing maps (or Kohonen maps) is a popular decision making method that is widely used in finance. Unfortunately, my own tests of the self-organizing maps within the statistical Forex systems (in a form of MetaTrader expert advisor) didn’t bring any interesting results. There are many other ways of utilizing the self-organizing structures to store and compare the quote-derived statistical information, but their complexity doesn’t look to be necessary in such systems.

Chart-to-chart comparison can be used if the statistics stored is a raw or normalized market data, which brings a lot of opportunities based on the graphical chart analysis and the difference calculations. It’s also necessary to note that such comparison would require a lot more CPU power and time to complete. It would also produce a more long-term aimed result than the immediate decision that would be true for the next bar or candle.

In my opinion, it’s optimal strategy to store the statistics in three separate «containers», where statistics in the first container would correspond to the buy action, in the second — to the sell action and third — hold action. Finding the best Euclid distance for the current market sample among all three «containers» gives you a hint for your next action. In this case, it’s more important to collect the right data and to format it in a right way for further comparison.

Statistical Forex System — Gathered Information

Monday, August 11th, 2008

Earlier I’ve described the statistical Forex systems and introduced the problem of choosing the right timeframe to gather the statistics for such systems. Today I will try to describe the problem of choosing the right information that is collected for the statistical trading system.

Gathering the statistics over a chosen period of time for the given market instrument is the next step to create a successful statistical Forex strategy. But what data should be used for this statistics? Is it a good idea to record bare chart data? Should you gather any additional information? Here is my view on all possible statistics type that can be used in the process:

Pure market quotes. This includes high, low, close and open rates for bars and bid or ask rates for ticks (if you think that tick-based statistics is a good idea). This method of statistics gathering is the most obvious. You gather the market quotes then compare them with the current situation and decide whether to buy, sell or hold. But there is a problem with the changing of quotes range. For instance, 1 year ago EUR/USD was in 1.4000-1.5500 range, a month ago it was far above 1.5500 level, so the data gathered in another price range would be completely useless. Alternatively a normalization of some sort can be used to store such statistics — e.g. store not a quote like 1.5404 but its relation to the next bar’s open price — 1.5404/1.5423 = 0.998768073. This way you’ll have data that is informative in any price range, but still uses no indicators or other complex calculations.

Indicators. These are probably the best data to be recorded as the statistics. Even standard MetaTrader indicators allow recording a lot of information and then using it to compare with real-time current market situation. With a large part of the indicators the normalization similar to the one used with the raw market data will be necessary. It’s probably a good idea to use indicators that change in the certain range — like RSI, DeMarker, Stochastics, Larry William’s Percentage Range, Money Flow Index, etc. The length of the arrays of the indicator values recorded for each tick or bar is also an important parameter of the statistics gathering. Remember that the longer this length is the more uninformative this statistics becomes. Ideally, it’s better to use single value of each indicator that is unique for the current bar or tick.

Additional information. It can include the time of the day to capture the trends and patterns that are specific for some trading sessions only. Another parameter that fall into this category is the day of the week — trading usually differs depending on the busyness of the day (often with less price action on Fridays). The statistics can also note if the day is some major holiday, current daylight saving time mode for the major countries and the volumes of the trades (although in Forex they are not very informative).

Complex calculations. This can include not only calculations based on the market data and indicators, but incorporate the additional information such as time and the day of the week into the calculations. In this case the produced number-formatted statistics would be easy to compare to the real market data. Considering the current development level of the PC industry it wouldn’t be a hard task to incorporate even the most complex calculations in the MetaTrader expert advisor that utilizes a statistical Forex strategy. Additionally these calculations can be accompanied by the various pivot points and resistance/support levels to help with choosing the position’s parameters.

Statistical Forex System — Choosing Statistics Timeframe

Sunday, August 10th, 2008

In one of the previous posts I’ve introduced the statistical Forex system definition and marked up the important problems that should be solved in the process of its creation. Here I will try to explain more about the problem of the statistics gathering.

Choosing the timeframe for the statistics that will be gathered for your system consists of two parts — choosing the chart timeframe discreteness and choosing the length of the period over which the statistics will be gathered.

Choosing the right chart timeframe is a matter of balance between the uninformative short-term data with many samples and the small quantity of the more specific information. If you choose a tick or 1-minute timeframe discreteness you’ll have to face a large amount of data and a lot of CPU power used up on gathering, calculating and finding this data; finding some patterns in these vast arrays of information wouldn’t be an easy task and the further strategy building will very complicated in this case. On the other hand, using daily or weekly periods will give you too little information. For example, one year of the market analysis of D1 charts will give you just a little more than 200 data samples. In my opinion, considering the 24 hours a day and 5 days a week nature of the Forex market, the best choices here are M30, H1 or H4 timeframes as they give you a fair amount of samples with a decent informativity, because such samples will have a greater variation. Alternatively you can use multi-timeframe statistics, but that would lead to a really complex system, which, of course, will have a better potential.

Sampling period’s length is an important parameter of the statistics gathering. Using a small period will allow you to recognize the most up-to-date rate patterns and your strategy will probably benefit from them in the short to medium term. Unfortunately, short sampling period can contain too little of these patterns and if the market changes they will probably fail to help with the recognition of the changed price dependencies. Long sampling period will give a very wide array of patterns which can be used in comparing. But the difference between the market today and the market several years ago can bee too large, so those patterns can lead your system to a high inaccuracy ratio. Getting statistics over the past 2-3 years is a balanced decision here. You catch more than one long-term trend and you get a lot of the medium- and short-term trends caught into your statistics with such period, while really outdated data isn’t spoiling your statistics.

Of course, these decisions should also depend on your system, the nature of the data you will be collecting and the timeframe that it will use in the actual trading. But don’t forget the negative and positive sides of the different data timeframe and the sampling periods — try to avoid the extreme values that could possibly ruin your strategy.

Statistical Forex Systems

Wednesday, August 6th, 2008

Statistical Forex system is a system that relies on the information which was previously collected from the market and the amount of this information is proportional to the period of time, on which the market is analyzed. Common input parameters optimized over the period of time aren’t considered as the statistical information, thus not every optimized system or expert advisor is statistical. Statistics is collected into a special file in a format that is recognized by the system; optionally the system may update this statistics. Designing a statistical Forex system is a complex problem that involves market analysis, rules developing and real-time evaluator building.

If you want to build such trading system, you need to answer these questions first:

What period of time to use for statistics gathering? Intuition suggests that the longer the period the better will be statistics, but in fact there could be some problems if system collects the information from the time periods that due to some reasons are unrelated to the current market’s mechanics.

What information will get into statistics data? This is probably the most important question if you want to create your own statistical expert advisor. Will you record raw quotes, indicators values or some custom calculations? What indicators or calculation methods to use? What else should be recorded?

How will your system compare current market situation with the statistical data? You have some data that is associated with the rising market, some — with the falling market and the rest of your statistics is associated with the sideways market. What methods can you use to compare current market data with your statistics to make your next trading decision?

Will it learn or will it be taught? The statistical Forex system doesn’t have to collect statistics, but it may be designed to do so. This addition has its advantages and disadvantages.

How complex will it be? Statistical Forex EA can be a very simple program, but it can be also developed as a powerful analyzing and comparing program. It can be capable of recognizing not only price action patterns, but also correlation with the days of the week and the trading hours, as well as look into the past to see the start of the trend or the previous price patterns.

MT4 expert advisor built as statistical Forex system can be very profitable, but its creation is not a trivial task. I’ll try to elaborate more on these questions and the details of their solutions in the next posts.



InstaForex Broker