Tutorial: Advanced techniques in EA Wizard

This is not a tutorial to create a complete strategy, but a set of examples how to do more advanced things in EA Wizard.

Contents:

Using EA Parameters

When you run any EA you can notice that it can contain some configurable parameters that allow you to configure it or optimize it to look for optimal values.

How can we add parameters to EAs made by EA Wizard? It is actually very simple.

Maybe you noticed that the Strategy tab in the EA Wizard contains Stategy Parameters section. This is the place where we can define the EA parameters.


Click on the Add new button to add one or more parameters. You can change its name, its type (integer, float, boolean or string) and specify the default value. Let's define a parameter name TrailingStopInPips, with type int and default value 50. It will looklike this.


Now, we have the parameter but it isn't used anywhere. Since it is a parameter for trailing stop, we'd want to use it in our order as a trailing stop.

We can switch to trading rules and when we create or edit our Enter at Market order, we can define the trailing stop there. Just click on the small button with three dots in the Trailing Stop parameter.

This will open the Trailing Stop Dialog where we can choose fro various options, and one of them is - Use from variable.

This way we can let the EA use trailing stop from the parameter that we can change.


Note!
The three dots button next to every parameter always allows you to specify a parameter instead of fixed value, or even opens a new configuration dialog with more choices.


Using global Stop Loss and Profit Target

For every order you can specify its own Stop Loss and Profit Target levels. To make things more simple, it is possible to use Global Stop Loss or Profit Target just once and let every order use it.

Global SL/PT can be defined in the Strategy tab.

There you can either enter a pip value, for example 40, or click on the button to open more advanced settings.


As an example we'll define Stop Loss as fixed pips value - but we'll use EA parameter, so that we can change the value later.
For profit target we'll use simple 2 * ATR(10) formula.

Let's define Stop Loss first. Because we want to use EA parameter, we'll define new parameter StopLossInPips and set it to 50 default value.


Now we'll go to global Stop Loss and click on the button to open the Stop Loss dialog.

There we'll select the option Use from variable and we'll select our variable.
So now we set global Stop Loss to the value in StopLossInPips variable.


Next we click on the button next to the Profit Target field to open the Profit Target dialog.

And we'll choose the ATR based option, with correct coefficients.

We are done, we defined our global Stop Loss and Profit Target levels.


There is one more step to do!
We defined our global SL/PT, but no order is currently using it. To apply it to orders, we have to go each of our orders, click on them to edit them and click on the button next to Stop Loss and Profit Target.


In the dialog that appears we have to select Use global Stop Loss or Use global Profit Target.
Only then our orders will use the globally setSL/PT.

That's all, now our order will use globally defined SL and PT.



Using Money Management

Everytime you create an order you have to specify the number of lots that should be bought or sold like in the picture below.


We can do it like this, but then our EA will trade always with one size of lots and it will be difficult to change it.
It is much better and also simpler to use buid-in money management. Instead of setting the quantity in order, click on the small button at the Quantity field and open the Quantity Dialog.

We have few choices - we can enter quantity (lots size) as a number, or use it from a variable or Use predefined Money Management.
Here we are just saying that the order should use predefined money management, whatever the MM forumla is. You can set it like this for every order.


Money Management can be chosen in the Strategy tab, in Money Management tab.

EA Wizard currently supports two different money management modes to choose:

  • No money management - this sounds like a useles mode, but the point is that you can change the money management for all the orders by choosing the mode here. Trading with fixed lots is the most basic "money management" mode.

  • Money management - risk fixed % of account equity - in this mode EA will trade with growing amount of lots as your account grows. You can specify the Risk in % which is the maximum percentage amount of your account you'll risk per every trade. So if you'll set ot to 5%, you'll never lose more than 5% if the trade goes to loss.

The trade size in risk fixed % of account equity MM is computed from Stop Loss.
For example, if you have $10,000 account and you are willing to risk 4% per trade, this means you will be risking $400 in every trade (4% of $10,000 is $400).
The trade size will depend on your Stop Loss. If your order uses Stop Loss of 50 pips, then the trade size will be computed so that if the Stop Loss is hit, you'll lose only these $400.
In this case the trade size will be 0.8 lots.

Note!
Remember, in order to use money management in your trades, every order must set the Quantity to "Use predefined money management".


Closing open position

Your EA can control your open positions dynamically and close them when the situation isn't going in your favor.
Just like when entering the position, you can create a rule to close a trade if given conditions are met.

Let's say we are in the long trade and we want to close the position if CCI(50) goes below 0.
We can define a new Long exit rule and set the condition like this:


This means that the rule will be activated when we are in long position and CCI(50) is below 0.
Then we define our action:

Close position with Magic Number 11111. We have to specify the Magic Number of the order we want to close, here I assume that our long order has Magic Number 11111.

Note!
Every order must use its unique Magic Number. The Magic Number helps EA to recognize and handle the order.
We can use any value for Magic Number, as long as it is unique.


Using custom indicators in EA Wizard

When you already have custom indicator defined in EA Wizard, it can be used simply like any other built-in indicators. You can use your custom indicator in the trade condition:

Simply open the combo box with Custom Indicators and find the one you want to use. The Custom Indicators combo box contains all custom indicators defined in the system.
Choose your indicator (for exmaple QQE_ADV) and you can compare it to any other value on the right side, even another custom indicator.


Note!
Some custom indicators have multiple output values - for example Keltner Channels returns values for upper, middle and lower channel.
You can choose the output value in the property panel.


Custom indicators can be used also in the order price levels, for example when you define price level for Stop order, or price level for Stop Loss or Profit Target.

Note! MetaTrader folder structure has been changed in build 600+!
It no longer stores indicators and EAs in MetaTrader installation folder, now it uses separate Data Folder instead.
You can find the path to your MT4 Data Folder by opening MetaTrader and going to File -> Open Data Folder

To use the custom indicator in your MetaTrader, the indicator file has to be copied to {MetaTrader Data Folder}/MQL4/Indicators directory, so that our EA can find and use it.


Using Strategy Controls

We don't need to compare only indicator values in our conditions. EA Wizard allows you to create conditions based on the current running orders.
These functions are in the Add condition dialog in Strategy Controls combo box.

There you can create a condition for example to exit the trade after given bars in trade, or to not enter to trade when there were 2 trades today already, etc.

On the image below you can see the condition that is true when Open Profit (in pips) is lower than -50. This means we are more than 50 pips in loss.


Combine it with close position action and you have hidden stoploss tnot visible by broker.

Using this rule the EA watches the trade and it will close it when the open loss is goes over 50 pips.



Using Is Bar Open function

Is Bar Open is useful function that is true when the EA is at the open of new bar.
It is good for trading strategies that check for some indicator values only at the open of a new bar, or at given time.

My Forex Morning Trade startegy is a good example of such strategy - it checks for signal only once a day at open of a bar at a given time.

What is it good for? It speeds up the backtesting and it tells the EA to check the rule only once per bar.
By using this function in your rule you say to EA that it doesn't need to process anything inside the bar, which greatly increases speed of backtesting.