This Metatrader 5 EA is based on the trading strategy of [[https://nononsenseforex.com/][No Nonsense Forex]] (NNFX) and is particularly optimized for backtesting and instantiation with [[https://github.com/stfl/backtestd][stfl/backtestd]].
** Features
** 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
** 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 :ATTACH: :PROPERTIES: :ID: f568e1ce-3bad-471d-b2a8-95ffc23bf052 :END: 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) };
| Preset | Trade Logic | Metric | |------------+----------------------------------------+----------| | Manual | select inputs below | | | Full | A regular trade | CVaR | | Trail | A trade and an ATR based trailing stop | CVaR | | TakeProfit | Add a Take Profit to the trade | Win 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 [[file:Experts/backtestd/backtestd-expert.mq5][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.
** 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/
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.
| class | buffers | params | Description | |--------------------+------------+--------------------------------------------+---------------------------------------------------------------------------| | 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 |