Strategy Optimization

From FxCodeBaseWiki

Jump to: navigation, search

Contents

Optimize Lua

First of all, please refer to Lua performance optimization tips: Optimisation Tips at lua-users.org.

Optimize JavaScript

First of all, please refer to JavaScript performance optimization tips: Optimisation Tips at developers.google.com.

Handle Responsibility Properly

An indicator is responsible for calculations. A strategy is responsible for making trade decision. Dixi!

Every time when you have to do something else than read and compare the latest indicator values or prices, you are trying to make an indicator instead of a strategy.

The ideal case is when there is an indicator (or a number of them) which implements all the logic and returns something like -1 for sell, 1 for buy and 0 for do nothing. The strategy must only read these commands and call the terminal function to trade.

This is important because the indicator calculation is highly optimized. The properly written indicator is called only for the data has never calculated before and does the calculation as fast as possible. The strategy does all the calculation at every tick.

Use Fast Indicators

The indicators used by the strategy must be also optimal. Please check the indicator performance using Integrated Lua EditorDebugger. If it is not enough, try to optimize indicator's code (see Indicator Optimization).

Avoid Heavy Operations on Every Tick

Access To Trading Tables

Do not touch the trading tables unless you are really have to. Access to the trading tables is very costly operation. Touch them as seldom as you can. By the way, in 2.0 version of SDK there is a version method value of which signals that the table content is changed (rows either added or removed). It's reasonable to keep the information in your strategy and update it only when the version of the table is changed.

Moreover, designing the strategy which trades often (e.g. on tick basis) but relies on the trading tables to check whether the user already has the trades is pretty unsafe. Please remember that on the real connection the information in trades or orders table may be updated a second or even more later than the trade/order is actually executed.

Avoid Needless Indicator Updates

If your strategy uses indicators based on a bar data and works on recently closed bar do not force updating indicators every tick.

Make Loops Body as Small as Possible

Make all possible calculations outside of the loop. Do not forget that Update function is a part of big loop as well. If there is an strategy parameter which switches the mode, just store the reference to the function which implements chosen mode in Prepare function rather than use if ... elseif ... end construction all the time.


This Article in Other Languages

Language: English  • Español • Français • Русский • 中文 • ‪中文(繁體)‬
Personal tools