Skip to content

stfl/backtestd-expert

Repository files navigation

backtestd-expert

This Metatrader 5 EA is based on the trading strategy of No Nonsense Forex (NNFX) and is particularly optimized for backtesting and instantiation with stfl/backtestd.

Features

  • All of the indicators of the NNFX algo are configurable via inputs
  • All inputs can be used for optimization
  • Testing single indicator (Confirmation or Baseline) can be tested
  • Trailing Stop based on the ATR distance to closing price
  • Multi-currency backtesting and genetic optimization over all symbols
  • Store Side Changes (lines crossing, …) for indicators to SQLite (this may be buggy)
  • Optimized to test on Open Price for very fast backtesting
  • Calculate VP’s win rate or Conditional Value at Risk (CVaR) as Custom Max

Disclaimer

This EA is under development and tailored for my needs and particularly optimized for backtesting performance and configurabilty. This EA should not be used for live trading.

Please contribute to get this EA to a quality level so it can be used for live trading. Testing the EA for bugs and logical mistakes is highly appreciated.

I am not selling this EA because I believe in open source software and I don’t have the time to polish and promote this EA nor I do want to write extensive documentation.

This EA is for developers and people who don’t scare back from looking at the code\ Feel free to fork the repo and adopt to your needs. Please send me your changes as a pull request

Installation

From Release Binary

Download the release binary from github and put it into the directory MQL5/Experts/backtestd/backtestd-expert.ex5

Install From Source

checkout source

You can’t use git clone because the base directory is the MQL5 root directory.

cd \Path\To\MQL5
git init
git remote add origin https://github.com/stfl/backtestd-expert.git
git pull origin master

compile the expert

  • Open MetaEditor
  • select the EA (MQL5/Experts/backtestd/backtestd-expert.mq5) and click compile.

Configuration

The EA can be configured with several inputs.

Backtest Trading Logic and Presets

In order to quickly select different backtesting strategies the following can be quickly selected as an input.

enum BACKTEST_MODE {
    Full             = 0, // A full trade without Take Profit
    TakeProfit       = 1, // Take Profit based on ATR, Calculate Win Rate
    Trail            = 2, // Trailing Stop, no Take Profit
    Manual           = -1, // Manual configuration (No Preset)
};
PresetTrade LogicMetric
Manualselect inputs below
FullA regular tradeCVaR
TrailA trade and an ATR based trailing stopCVaR
TakeProfitAdd a Take Profit to the tradeWin Rate

These are some useful defaults and may be extended or changed in the future. When selecting manual, the following inputs can be used to set the trading logic.

Note: If something other than Manual is selected, these settings will be ignored!

input bool Input_Money_AddTakeProfit = true; // set a TP on the trade
input CUSTOM_METRIC Input_Backtest_Metric = Metric_WinRate;
input TRAILING_MODE Input_Money_TrailingMode = ATRTrail;    // Trailing Stop Mode

To customize the behaviour of the EA there are several inputs like setting the Stop Loss or Take Profit level… These settings are only considered if relevant for the backtest mode.

Check backtestd-expert.mq5 for more details ;)

input int Algo_BaselineWait = 7; // candles for the baseline to wait for other indicators to catch up
input double Money_Risk = 2.0; // Risk per trade
input double Money_StopLevel = 1.5; // Stop Loss level ATR multiplier
input double Money_TakeLevel = 1.0; // Take Profit level ATR multiplier
input double Money_TrailingStopATRLevel = 2.5; // Distance of the trailing stop ATR multiplier

Indicator specific configuration

Below the general input you can find the configuration for all the indicators in the algo. The list is long. It starts with Confirm_… which is for the configuration of the Confirmation indicator and so on.

name
The filename of the indicator.
Signal Class
The Signal Classes for the indicator
shift
How many bars the signal is shifted. (just keep it on 0)
Confirm_double_input 0-14
The actual changable input parameters for the indicator in the same order as when configuring an indicator.
Confirm_buffer0-4
The internal buffers of the indicator used for calculating a signal.
Confirm_param0-4
Additional parameters depending on the signal class

finding values for buffers and params

Buffers and params depend on the Signal Classes and need to be configured. Check the source code of the indicator to figure this out.

Example

In this example we are configuring the tsi-indicator which has 4 input parameters (r, s, sp, sm). ./doc/tsi_inputs.png

If we look at the source code of tsi-indicator.mq5 we find the definition of the buffers:

SetIndexBuffer(0,TSIBuffer,INDICATOR_DATA);
SetIndexBuffer(1,TSISigBuffer,INDICATOR_DATA);
SetIndexBuffer(2,MTMBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,AbsMTMBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(4,EMA_MTMBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(5,EMA2_MTMBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(6,EMA_AbsMTMBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(7,EMA2_AbsMTMBuffer,INDICATOR_CALCULATIONS);

The buffer type INDICATOR_DATA reveals that this is a buffer that is displayed and - sometimes with try an error - we can figure out that the buffers for a TwoLinesCross indictor are 0 and 1.

Everything configured it looks like this.

./doc/EA_inputs2.png

Note: The Confirm_double_input4 was accidently configured but did not effect the functionality of the backtest

Signal Classes

The EA knows about several classes of indicators and describes them as signal classes. In the code these are configured as sub-classes of a CustomIndicator class. This allows easy replacing and implementation of a signal class logic.

classbuffersparamsDescription
Preset--The functionality is defined in the code
TwoLinesCross[up, down]-Two lines crossing
ZeroLineCross[line]-Single line crossing 0
LevelCross[line][level]A line crossing a level
TwoLevelsCross[line][up enter, up exit, down enter, down exit]A Line crossing a two levels
PriceCross[line]-The price is crossing a line (Baseline)
PriceCrossInverted[line]-The price is crossing a line, the signal is triggered the other direction
ColorChange[line]color values: [neutral, up, down]Single line changing color
Semaphore[line]-Signal signs like arrows on the chart
SaturationLevels[line][up enter, up exit, down enter, down exit]A line the enters a saturation (overbought/ oversold) region

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published