Example strategies

These sample EAs serve as a demonstration of various techniques that can be used in EA Wizard.

Each sample contains detailed explanation of the sample logic and functions it uses, and you can download every sample strategy in EA Wizard format.

List of samples:
Play Sound example
Martingale strategy
Trail Stop programatically by EA
Trail Stop to Low of the previous 5 candles


Play Sound example

Example EA that plays sound if CCI crosses above 0.

Very simple example showing the use of Custom Action. The rule simply checks if CCI crosses above 0, in which case it runs Custom Action: PlaySound("alert.wav");

Custom Action allows you to execute any valid MQL code
(or function predefined in file {EA Wizard}/code/CustomFunctions.mq4).

File to download:
Click on file with right button and choose Save as...
PlaySoundStrategy.sqw
Sample strategy can be open only in EA Wizard

Martingale strategy

Example Martingale strategy made in EA Wizard. Principle of Martingale strategy is that after every losing trade it doubles the lots size for the next trade in attempt to compensate the previous losing trade.

Strategy has 3 rules:

Go long 1
This rule checks if there is no open order (Market Position is Flat) and checks for sample entry signal (CCI crosses above 0). If all conditions are true, it opens new order with Profit Target=20 pips with 0.1 lots size

Go long 2
This rule checks if first trade is open and its open profit is equal or lower to -20 pips (means it is losing 20 pips). If yes, it will close the first order and open new long order with profit target 20 pips again, and lots size 0.2

Go long 2
Third rule checks if the second trade open P/L is equal or lower to -20 pips (means it is losing 20 pips). If yes, it will close the second order and open new long order with profit target 20 pips again, and lots size 0.4

Note that rules 2 or 3 are activated only if previous order ended in -20 pips loss.
After three unsuccessful trades with sizes of 0.1, 0.2 and 0.4 lots OR if any of the orders ends with profit, strategy is "restarted" (because there is no further rule to check the loss of the third trade) and the next order will open normally at 0.1 lots.

The strategy is just as a sample, it can be improved to contain more than just 3 martingale steps.
Stop Loss level is tested manually in the condition Open P/L() <= -20, so that we can make the appropriate action when it is hit.

File to download:
Click on file with right button and choose Save as...
Martingale.sqw
Sample strategy can be open only in EA Wizard

Trail Stop programatically by EA

Example how to handle custom trailing stop using EA Wizard

The strategy will open an order and then trails the stop loss programtically using EA Wizard, instead of build-in trailing stop function. This shows how you can create your own trailing stop that could behave differently than the default trailing stop in MT4.

We'll use 2 variables (strategy parameters) to hold information about open profit (LastOpenPL) and to configure desired trailing stop (TrailingStopInPips). Strategy has 3 rules:

Go Long
This rule checks if there is no open order (Market Position is Flat) and checks for sample entry signal (ADX DI+ crosses above 30). If all conditions are true, it opens new order with Stop Loss=50 pips. It also sets variable LastOpenPL = 0;

Long Trailing Stop Set
This rule checks if trade is open and if its open profit is bigger than the value in variable LastOrderPL. If the profit is bigger, it will set the variable LastOrderPL to current open profit. This way, LastOrderPL will contain highest profit the order achieved.

Long Trailing Stop Exit
Third rule checks if the trade is open and if it's current open loss isn't smaller than last highest profit minus TrailingStopInPips. If the condition is true, it means that the order just hit the trailing stop and we have to close the position.

File to download:
Click on file with right button and choose Save as...
TrailingStopSimulation.sqw
Sample strategy can be open only in EA Wizard

Trail Stop to Low of the previous 5 candles

Example how to create a trailing stop that moves Stop Loss always to the low of the previous 5 candles.

The strategy will open an order and then trails the stop loss programtically using EA Wizard, moving it always to the lowest low of the previous 5 candles (number of candles is configurable).

We'll use 2 variables (strategy parameters): BarsBack is the number of candles to compute lowest low, TrailingStopOffset is number of pips to be deducted to lowest low tokeep SL for example 10 pips below the lowest low. Strategy has 3 rules:

Go Long
This rule checks if there is no open order (Market Position is Flat) and checks for sample entry signal (ADX DI+ crosses above 30). If all conditions are true, it opens new order with initial Stop Loss = 50 pips.

Move SL to Low
On open of every new barthis rule checks if trade is open and if it is in profit.
It also checks if the lowest low of previous 5 candles is higher than current StopLoss. This last check is made so that we don't move the Stop Loss backward.

When the conditions are true, it calls function Move SL() to move Stop Loss to lowest low of previous 5 candles minus given TrailingStopOffset.

To determine lowest low of theprevious 5 candles we use function Lowest(5). From this value we deduct the value of TrailingStopOffset, converted to real pips value - this means that the new Stop Loss will be X pips below the low.

File to download:
Click on file with right button and choose Save as...
TrailStopToLow.sqw
Sample strategy can be open only in EA Wizard