Home Forex Education Forex Daily Topic Trading System design – A Summary of your Best Options to Code...

Trading System design – A Summary of your Best Options to Code your Strategy

218
0

In our latest article, we have seen that manually backtesting our strategy is cumbersome if performed correctly. Also, It is usually subjected to errors and the interpretation of the trader. Therefore, a basic knowledge of trading algorithm development and computer coding is a desirable task for any trader. The good news is, nowadays, there are many easy ways to do it since high-level languages are very close to natural language.

High-level languages to quickly build your Forex strategies.

MetaQuotes Language (MQL4/5) 

In this respect, the primary language we could think of to build your strategy in Forex is MetaQuotes Language 4 (MQL4). This language is a specialized subset of C++ , holding an extensive built-in library of indicators and trading signals.

Spending your time and efforts to master MQL4/5 is worthwhile because Metatrader 4 includes a suitable trading strategy tester and optimizer.

If you are new to programming, you could start by analyzing and modifying existing free-available EA’s. Starting with simple strategies is excellent because they will be easier to understand and change. Also, in trading, simple usually is much better than complex.

Python

Python is the reference language for data science. Its popularity and its extensive library on data science are well-known. What is less known is, Python also has comprehensive packages dedicated to trading.

As an example, you can have a look at this list taken from Open Source Python frameworks:

With Python, you can go as easy as backtest your strategy with three simple lines of code using the fastquant package.

from fastquant import backtest, get_stock_data
jfc = get_stock_data("JFC", "2018-01-01", "2019-01-01")
backtest('smac', jfc, fast_period=15, slow_period=40) 

source: Backtest Your Trading Strategy with Only 3 Lines of Python

Of course, first, you have to create the code for your strategy.

Market Data 

For backtesting purposes, you will need to download your historical market data with the necessary timeframe. The file, in CSV or Excel format, can be easily read by your Python code.

If, later on, you are going to apply your EA live, you will need a real-time streaming data feed. If this is the case, you will need to create an interface to your broker through an MT5 TradeStation (MT4 is not equipped with it).

Easylanguage and Tradestation / Multicharts

Tradestation and Multicharts are dedicated high-level trade stations. Easylanguage, a specialized subset of Pascal, was developed by the Tradestation team to create indicators and trading signals. Both platforms are terrific places to develop trading algorithms, and backtesting is straightforward.

Easylanguage, as its name indicates, was designed to make it as close to natural language as possible. The ample set of its built-in library makes coding simple, so the developer’s primary focus is the trading algorithm.

As this example, please read the code of an adjustable weighting percent blended moving average.

inputs: period1(50),period(20),factor(0.5);

variables: slow(0),fast(0), blended(0), var1(0), var2(0);

slow= average(close,period1);
fast= average(close,period2);

var1 = factor;

if var1<0 then var1=0;
if var1>1 then var1=1;

var2= 1-factor;
blended= (slow*var1)+(fast*var2);

plot1(blended,"blended");

 

You will see it is relatively easy to understand and follow. Anyway, it would be best if you dedicated some time to really master the language, to avoid or at least minimize coding errors.

Pine Script and Tradingview

Pine script is another specialized language to easily program your own studies and trading strategies if you have an account on Tradingview (which you may open for free). As in the case of Easylanguage, Pinescript is designed to be easily understood. 

Pine studies are used to display indicator information and graphs on a chart. It is preceded by the study() declaration. If you wished to create a strategy for backtesting, you have to use the strategy() declaration.

As with other languages, the best way to begin is by reading other people’s code and modifying it for your own purposes.

Coding strategies in pine script is similar to Easylanguage or MQL5. You create a code taking in mind that it will cycle on each bar in the chosen timeframe. 

We took this example of a MACD indicator from the Pine script quick start guide:

//@version=4

study("MACD")

fast = 12, slow = 26
fastMA = ema(close, fast)
slowMA = ema(close, slow)

macd = fastMA - slowMA
signal = sma(macd, 9)

plot(macd, color=color.blue)
plot(signal, color=color.orange)

Backtesting in Pine script is easy. But, there is no way to perform automated optimization. You will have to do it manually. You should go to the performance summary and the list of trades to find the causes of the lack of performance, apply parameter changes, and see if you get any improvement of that adjustment.

In our next article, we will go through the steps to develop a strategy using the Pine script.

LEAVE A REPLY

Please enter your comment!
Please enter your name here