I was able to write my first EA that actually turned a profit in back testing. I am a price action trader so I don’t spend a whole lot of time looking at indicators, but that doesn’t mean that indicator rule based systems don’t work. I have tried to write a bunch of different rule based eaS that didn’t work very well. Last Friday it hit me about what would make a good EA, then on Sunday night I spent 2-3 hours programming it and testing it. The EA was back tested on the EURUSD from January 1st 2009 - January 1st 2013.
It’s pretty raw right now and here are a few things it’s still missing
It doesn’t open short positions
The SL and TP are hard coded, I want the SL and TP levels to adjust dynamically to help winners run longer and losers get cut shorter.
I don’t plan on laying out all of the rules and code here but I am brand new to using MT4 other than writing MQL4 code, and doing any sort of demo testing. I would like to finish up the code so that it is working as good as possible and then run it on a demo and post the results on myfxbook. Right now it does about 3.25 trades per month, 50% win rate and each trade is a hard set 1:2 RR. I think finishing up the above 3 items will probable double the amount of trades it can take, and boost the RR and win rate. I figure if this is what I can come up with in 2 hours, some serious amount of time spent on it could really boost it’s success. The trades it takes are held for up to a couple days, so it doesn’t suffer the same issues as EA scalpers where and spread and slippage shouldn’t hugely affect the real results from the back test.
This could be traded by hand and probably with better results if done by an experienced trader, but I am very pleased with the results of it as an automated trader.
Back then during my Dark Age, I also wrote my own EA, although with somewhat embarassing result. My main reference is this book:
[B]Expert Advisor Programming: Creating Automated Trading Systems in MQL for MetaTrader 4[/B]
And that is also available in Amazon. That book is really good ‘for dummies’.
I use the MQL online documentation when I need to find a specific function in the MQL4 library. I am going to quickly add in code to dynamically set TP,SL and move SL to BE and see how that affects the program. I am going to step through it visually and see if I can’t find a pattern in my losing trades and try to program in some filters also.
Is it possible to disable the compounding/increasing of lot sizes and run the same test?
It would help make it easier to see the early part of the test and to get a better estimate on potential drawdown.
Otherwise that looks like a really good test. Does it do well with other pairs?
I am still trying to figure out how to get more historical data, but the only other pair that gave me a sizeable amount of trades was the EURAUD, and it come up with results very close to the EURUSD with the same EURUSD settings. Although I don’t trust any data that has less than 100 samples so I am stick to the testing on the EURUSD.
I found a few bugs in the EA today and I believe fixed the problem that was keeping it from shorting. I just left my house, but before I left I started a new round of optimization. It was only 10% of the way through and it had already come up with setting that were giving twice the profit factor(3.0) and drawdowns were about half(10-15%) before I made the bug fixes. The bugs were definitely contributing to more losses and hurting my profit factor and draw down. I am looking forward to the results.
I had deleted everything a long time ago because I was embarrassed with the result back then. If I’m not mistaken, I only used Simple MA for indicators, and its variation.
Yes this only does 1 trade at a time. When I took this screenshot it had a fixed TP and SL but I have since made some changes. The TP is still fixed, but the SL is dynamic. I am still working on making the TP dynamic also.
Have you ever thought of adding something to make it lock in profits at X amount?
For example you could set it so 100 pips would be TP, 75 pips would trigger a lock in which moves the SL to +50 pips… It would be good if you wanted to mess around with really large TP levels but still have some security.
I was trying FX few years back and tried one EA on (small) live account.
EA was based on some break out manually method that (FF? can’t remember) forum members were successfully trade.
This nice guy made an EA and it did work OK. You could enter comment for each EA on each pair. So I entered settings into comment to help me validate trades later.
Well, there was this bug then (MT4?) and if comment was longer than certain amount of characters, EA went crazy. Over night. LOL! On my small live account. If I remember correct FXDD did froze trades at some point but there were few hundred executed already. I lost over 50% on spread lol. That was it for me for Forex trading. But few days ago I stumble upon PA (Jhonathon thread) and got interested in price action and now I’m back
Anyway, sorry for rumbling, maybe you want to check if you enter longer comment in your AE if it still works correctly. That programmer told me that was at that time some MT4 limitations he didn’t know off.
It dynamically takes profit now based on various market dynamics, I am running tests to see if it improves over the fixed TP code. I ran some tests on it with the new shorting code, and it is still looking good. It plateaus for an amount of time and then resumes profits. I am going to go into the historical data file and look at the plateau data to see if anything stands out about it(volatility/volume), and then have the EA adjust for the various market conditions.
I downloaded the m1 data and uploaded it to mt4. My indicator runs on the 4 hour charts, so will this 1 minute data help me out any? My 4 hour candles still only go back to 2009, but my m1 candles now go back to 2001. It looks like I may have to manually convert that 1 minute data into 4 hour data and upload that to my H4 history. Am I thinking of this right or am I missing something?
This is weird and no it shouldn’t be that way. You shouldn’t need to manually convert data. When I was few years ago playing with back-testing, we too had servers available with many years more accurate data that once downloaded I could use right away. Something is wrong here.