How To Optimize Forex Strategies

In this article, we describe how to optimize Forex strategies in real time and adjust their parameters to the current market conditions.

A standard practice to optimize Forex strategies is via back testing them on the historical market data. The optimum values of the parameters, that every trading strategy has, are determined by running multitude of tests and selecting the combination that produces the best results.

We can call this static optimization. The reason for such a name is that the outcome of the tests are some fixed set of parameter values.  By fixed we mean that it is used unchanged after the testing. The logic behind it is as follows: if with these values the strategy was profitable for long enough time, then these same values should generate profits in the future, as well.

A very obvious question that comes to mind at this point is how much data should we use? What is enough to be confident in the strategy?

Here is one example. We were optimizing our automated trading strategy on Asian sessions – during one month. Asian sessions are the easiest to trade because of their lower volatility. Our strategy had 3 parameters. With optimized  values, monthly profit was a decent 280 pips. However, when we used these same values during the next month, the strategy started losing money.

This example illustrates the fact, that back testing can’t guarantee future performance. Unfortunately.  The Forex markets are unpredictable.

What to do then? Does it makes sence to test at all?

Our take is as follows. Yes, it is impossible to profit all the time. However, proper testing can help in identifying favorable trading conditions where trading risks are lower. And avoid trading in all other cases.

Optimize Forex Strategies Dynamically

In  static approach, we find the best strategy parameters by back testing it on the historical data. These parameter values are then used in the later trading – unchanged.

We are currently working on the algorithm of what we call “dynamic” optimization, where the tests are run in real-time, on live market data.    

The idea is to use the test outcome immediately for adjusting the strategy parameters on-the-fly. This way we will get a feedback loop which works almost in real time. Depending on the hardware, the delay can be as low as 5-10s.

This approach also helps us decide what is the optimum data interval to test on. We can test time intervals of increasing length, ending at current time, until the change in the test results is small enough. We obviously need to weigh the results. The time interval around the current time should have the highest weight.

Dynamic optimization will be an important part of our strategy development toolkit, which already includes a real-time pivot point detecting algorithm. Which generates trade signals at market tops and bottoms.

As you understand, optimizing the pivot point detection process in real time will have an enormous profit potential.

Adjusting The Strategy On-The-Fly

With our strategy definition as a state machine, changing the running strategy is easy.

To remimd you, a state machine for a trading strategy has a predefined set of states (e.g. “flat“, “long” or “short“). It also has number of events (e.g. “buy signal“, “open order” or “close order“). New events can be generated on each tick.

Changing states  is called a transition. There is a set of allowed transitions for each state. Only predefined combinations of states and events can trigger  transitions.

A simplified example. If we are in the state “flat” (i.e.  having no open positions), then if we get an event “buy signal“, we may transition to the state “long“.

In real life, there must be an intermediate state. When the order opening command has been sent but a confirmation hasn’t yet come. There also can be a failure in order fill. But you should get the idea how it works.

This model is very well suited for the real-time adaptation. The states are independent on events. And some events are independent on the market situation (e.g. those for communication with trading server).

What comes to market-dependent events, they are all originated from our pivot point detector which is designed to work in real-time.

To adjust the strategy to the market in real time, we need to periodically run the detector on current market data and find the best parameters as we would do in static case.

The events are generated based on the signals from the pivot point detector. But each signal does’t equal an event. There is a strategy layer on top of the detector that interprets the signals and translates generates events.

This strategy layer applies the best available strategy for each market conditions anyway. So it doesn’t require any changes to work in dynamic optimization mode.