I realize that my recent postings have been far an few between. Trust me, there has been good reason.
For the past two years, my trading has been very much EA-based. The problem of course was I found myself constantly optimizing and updating my EAs. It's a fairly tedious process and requires a good amount of analysis on my part. All of the EAs were also problematic in the sense that they are 'dumb'. They do not really analyze the market and try to determine if the current trading market is good for them. That's something I've had to do manually.
Now, I new I needed to come up with some sort of self-optimizing EA, or at least an EA smart enough to know whether or not a specific trading strategy is good for a particular market. There were attempts made to try and mechanically determine if a market was trending or ranging, but that didn't work out too well. There was an article on the MQL codebase explaining how to get an EA to optimize itself, but it was tricky to implement and wholly unreliable.
This system is one of my more promising attempts, and can be very heavy on computer resources. It uses the bars on the chart to try and run a very crude backtest. Based off of the information in that backtest the EA can then decide whether or not the market is appropriate for them. The initial system is based off of an old one: New Highs and New Lows.
At its core, if there is a new high, the EA will place a long trade--assuming it expects a breakout--or a short trade--assuming it expects a counter trade. Consequently, if there is a new low, the EA will place a short trade--assuming a breakout--or a long trade--assuming a counter trade.
The system itself is very simple, there is no doubt about that. The underlying analytics took awhile to code and attempt to perfect.
Every day when the day starts, the EA will re-run the crude backtest to determine if the market is still suitable for a particular trading system.
- extern string Remark1 = "== Main Settings ==";
- extern int MagicNumber = 0;
- This number should be unique when multiple EAs are attached to a terminal.
- extern bool SignalsOnly = False;
- If set to true, the EA will only alert you to a trade using any combination of the alerts below.
- extern bool Alerts = False;
- If set to true, the EA will send a pop-up alert when a trading signal arrives.
- extern bool SignalMail = False;
- If set to true, the EA will send you an e-mail (assuming you set up your mail in your MT4 Terminal.) when a trading signal arrives.
- extern bool PlaySounds = False;
- If set to true, the EA will play the file, "alerts.wav" when a trading signal arrives.
- extern bool ECNBroker = False;
- Some brokers require EAs to first place a trade, and then modify the trade with the stoploss and takeprofit. If your broker requires this, set this value to True.
- extern bool CloseOnOppositeSignal = True;
- If set to true, the EA will close a trade if an opposite trading signal appears.
- extern bool EachTickMode = True;
- If set to true, the EA will take a trade immediately if it sees a signal. If set to false, the EA will take a trade only if there is a signal at the end of the bar.
- extern double Lots = 0;
- Fixed lot size
- extern bool MoneyManagement = False;
- Enables/Disables the lot sizing function.
- extern int Risk = 0;
- The percent of your available margin that you are willing to put into a trade.
- extern int Slippage = 5;
- Maximum slippage allowed when placing an order.
- extern int StopLoss = 100;
- Hard Stoploss in pips.
- extern int TakeProfit = 60;
- Hard take profit in pips.
- extern string Remark2 = "";
- extern string Remark3 = "== HiLo Settings ==";
- extern int BarStart = 0;
- This is the number of bars in the chart history that the EA will check when running its backtest. Set to 0 to use all bars on the chart.
- extern int InitialRange = 10;
- The EA looks for new daily highs and lows. This is the number of bars after a new day starts to establish those highs and lows.
- extern double WinPercent = 0;
- This is the minimum win percentage required before an EA decides on which system to use.
- extern double MinimumSuccessScore = 0;
- This is the minimum success score required before an EA decides which system to used.
- extern int MinimumConfidence = 90;
- This is the minimum confidence allowed. Confidence is the number of trades which could not be assign a win or loss.
When you attach this EA to the chart, you'll see the following parameters:
Breakout Win: Number of breakout trades in backtesting that won.
Breakout Loss: Number of breakout trades in backtesting that lost.
Breakout Unsure: Number of breakout trades in backtesting where the EA isn't sure if the trade won or lost.
Counter Win: Number of counter trades in backtesting that won.
Counter Loss: Number of counter trades in backtesting that lost.
Counter Unsure: Number of counter trades in backtesting where the EA isn't sure if the trade won or lost.
Breakout Percent: Percent of trades that won.
Breakout Success Score: The success score of the breakout style trading. (See how I rate systems to understand how I calculate success score.)
Counter Percent: Percent of trades that won.
Counter Success Score: The success score of the counter-trend style trading.
Tester Quality: The percent of trades where the EA is certain of the outcome (win/loss)
High Value: The current daily high price.
Low Value: The current daily low price.
Trading Style: the trading style that the EA uses.
The previous version of the EA didn't have the CloseOnOppositeSignal value enabled. These versions do.
HiLo Trader [TD] Lines paints lines showing where the internal backtesting engine would have placed high and low trades.
I should probably also explain how the backtester works.
The EA can see every bar that is on the chart. Based on how many bars it is told to look back, the EA checks for highs and lows. When a new daily high is made, the EA calculates what the TP and SL are, and then checks the next few bars to see if the TP or SL is between the high and low of that bar (including the entry bar).
- If either the TP or SL is hit in the entry bar, the EA adds to the 'Unsure' count..
- If the TP and SL is hit in the same bar after the entry bar, the EA adds to the 'unsure' count.
- If the TP is hit in a bar after the entry bar, and the SL was never touched, the EA adds to the 'win' count
- If the SL is hit in a bar after the entry bar, and the TP was never touched, the EA adds to the 'lose' count.