Add custom code to the NNFX Algo Tester

Want to add a very specific rules to your algorithm? Maybe add an indicator with less conventional operation? So for this there is Intermediate.

This tool allows you to increase the features of the NNFX Algo Tester by adding custom code. The 
Intermediate can be added as a common indicator, in any indicator slot, to introduce rules, conditions, custom indicators, and more.
To use this tool you should have some programming knowledge however the template bellow already includes 10 examples of use that can be easily adapted to your case.

Download INTERMEDIATE.mq4:


The INTERMEDIATE.mq4 includes 10 usage examples:

  1. Add a level to a two lines cross indicator. 
    Using the Intermediate it is possible to add one or more additional elements to create a entry signal. 
    For example create a buy signal whenever two lines cross and are above the zero level. And create a sell signal whenever the lines cross and are below the zero level.

  2. Add a line filter to a histogram indicator.
    For example create a buy signal whenever the buy bars are above the line filter. And create a sell signal whenever the sell bars are above the line filter.

  3. Two Level Cross with two variable levels.
    Using a two-level indicator with two variable levels (line filters) instead of fixed levels. Each time the line crosses the upper level upwards, it creates a Buy signal. And each time the line goes below the lower level, it creates a Sell signal. 

  4. Use a Baseline as C1 indicator.
    Using the Intermediate you can create an entry signal using a line and the chart price. In a way that when the price crosses the line it generates a signal.

  5. Join two C1 indicators into one. 
    You can combine several C1 indicators into one. The end result will be just one indicator that will replicate the signals of each indicator individually. 

  6. Add two indicator colors to confirm signals.
    An indicator can provide several elements that indicate similar things. 
    With the Intermediate it is possible to converge several colors, for example, so that the NNFX Algo Tester reads them in the same way.

  7. Change the Exit Indicator when the first order is closed.
    Using the Intermediate you can switch between two different Exit indicators using a specific rule.
    The Intermediate will be placed as Exit Indicator and will have the role of checking two different indicators depending on whether there are one or two open orders in the market.

  8. Implementing a simple over-exposure preventive system.
    Do not add trades to currencies with already open trades (for live trading). 

  9. Adjust the Total Risk according to the EVZ value.
    When the EVZ value is above the upper level then use maximum risk.
    When EVZ is above the low level but below the high level then use half the risk.
    When the EVZ value is below the lower level, use half the risk and open only the first order.

  10. Disable/Enable entries and rules depending on the day of the week.
    Although you can use an indicator and change rules, in this example 
    no indicator is used. The status of the rules changes according to the day of the week only.

As an example, let's use Intermediate to add the MACD indicator.
The MACD is an indicator already included in NNFX Algo Tester but is used as two lines cross, ie a signal is created as soon as the bars and line cross.

This time let's use the MACD indicator with level 0, the level 0 will serve as an additional filter to the signal (first example in the template). That is, the buy signal when the bars are above the line and above level 0. Sell signal when the bars are below the line and below level 0. 

  1. The first step is to install the Intermediate on your MT4. The Intermediate is basically an indicator and should be installed in the same way as any other custom MT4 indicator.
    Just open your MT4 Data Folder, and put the Intermediate.mq4 file in the MQL4/Indicators/ folder.
    Then restart the MT4 or click Refresh on the MT4 Navigator window.

    Once installed, you must modify the Intermediate according to your needs. On the Navigator window right click on the Intermediate and then on Modify.

  2. The MetaEditor will open, where you can see the source code of the Intermediate.

    Each example will change the value of the 5 available buffers according to specific rules. You can use whatever buffers you need.
    In the case of example 1, when the MACD line and the MACD bars are above level 0, then buffer 1 (var_10) is set with the value 10 and the remaining buffers with the value "EMPTY_VALUE".
    This will be interpreted in the NNFX Algo Tester as "Buy".

    Example 1 is active by default, to activate another example you must deactivate example 1 by first commenting the respective code.

  3. After making the necessary changes to the Intermediate we can use it in the NNFX Algo Tester.
    The Intermediate is used in the NNFX Algo Tester as a custom indicator, so we must select a custom option.

    Usually the HISTOGRAM / COLOR option is the one that gives us the most flexibility, that's why the 10 examples use this option. However, you can use other custom options if you wish.

    You can use the Intermediate in any indicator slot, in this case we will use it for C1.
    So the configuration will be as follows:

    Note that as we use buffer 1 (var_10) and buffer 2 (var_20) in the intermediate configuration they correspond to buffer 1 and 2 here.

  4. Now we can run a backtest. The NNFX Algo Tester will create the entries based on the Intermediate.  

    The Intermediate will be shown in the Visual Mode using balls. The green balls correspond to buffer 1 and the red balls to buffer 2. In this case buffer 1 (buy mode) and buffer 2 (sell mode). We can confirm the intermediate operation by placing the MACD on the chart as well (this is not necessary).

As you can see in this small example, the intermediate is a powerful tool that will allow you to increase the potential of the NNFX Algo Tester software, allowing you to include almost everything in your algorithm.