Tips for EA programmers

 

I've been making EAs for a few years now, and although I may not be a master of MT4, I have picked up a number of tricks along the way. I've finally reached the point where I have two systems running on real money, doing well, and I thought I would make a quick thread with tips for those getting started or others starting to dive into more advanced functions.

Newbies! Create Your Own Include File

This is probably key to this entire article. You can create your own include file and simply pull it into all of the EAs you make. This will pull in all of the variables and functions you want without having to rewrite the same code repeatedly. I was constantly rewriting a lot of variables and other functions into my EAs and scripts before I realized what an idiot I was being.

Use the common functions include

MT4 should come with a standard include file called Common Functions. I don't use most of them, but if you're running your EA in visual mode, try out the "print()" function. Very helpful.

Save time! Skip non-trading days in your EA

If your EA only trades from to , tell it to skip all other bars. This has no effect on your system, but will vastly speed up backtesting. Simply do a TimeHour(Time[0])==whatever and if it's outside your range, "return(0);" Same goes for minutes, days, whatever.

Create a "Lotsize" function

Develop an equation for your desired maximum lotsize per the size of the account. Then, create a single function to return your desired lotsize, taking an input variable of risk. Make sure to work leverage into your function, as you may switch brokers or change account types. After that, you never need to work out lotsizes again. Simply throw in the desired risk relative to your maximum ideal trade size. (A risk of "1" is the maximum size trade you'd want to take.) I found this extremely helpful.

Create EAs that talk to each other

Your EA strategy may have pretty good win/loss ratios, but the wins tend to be pretty small. Why not allow the EA to run on multiple currencies and only enter on the currency that has the highest potential profit? This can be done through some simple file write/reads on tick() and opens up a variety of new strategies.

I found this ideal to running one EA that handles multiple currencies. If you go that route, then you need to change variables and re-initialize the EA every time you want to include or remove a currency. With this, you simply close a window. Be sure to throw some "Hey, we're not working on currency, anymore!" code into the deinit() function so that it doesn't throw off the other EAs.

Begin coding via scripts, not EAs

A script can very quickly run through the entire chart and tell you what percentage of win/loss scenarios you would have faced are. It's much easier to create a quick script and see whether or not that wonderful strategy you devised actually has a win rate of only 30% vs the 90% you see on the whole two months you were looking through data. This sounds like a lot of coding, but it actually is pretty simply and relies on the next principle:

DO NOT MAKE A STANDARD EA -- absolutely key!

This is my personal opinion, but... if you're EA strategy relies on more than one or two indicators (MAX) and has all sorts of crazy rules, you're going about it the wrong way. There are banks with millions of dollars of computer equipment that do nothing but crunch numbers and figure out what works. Your little EA will not beat them.

Example:

MA cross with MACD in negative territory and it's wednesday past 9 AM with amount of volume and I saw a pig flying out the window. Oh, and that totally-awesome custom indicator I made tells me it's time to sell, too!

Remember that the more indicators you're using, the more you're "fitting" your EA to the data.

Problems this causes:

1. Very difficult to backtest with any accuracy

--It IS possible to backtest with nearly 100% accuracy if you're testing properly. By properly, I mean testing the IDEA, not the exact numbers. I'll give an example below.

2. The numbers you DO get in backtesting will be pretty far off.

--Spread isn't really taken into account, slip isn't, etc. You really can't trust the numbers if you're trying to do things like scalp or your EA relies on a very slim margin of success.

What you SHOULD do:

Look at the chart from a distance and look for very broad, continuing patterns. Perhaps (and this is total BS, but let's go with it for example sake) that each day of gain has a 75% chance of being followed by another positive day. That's VERY easy to get statistics on via the script mentioned above. You DON'T need indicators at all or should use them minimally (between both my EAs, I use only one).

Then, look at things like the average profit day vs the average loss AFTER a profit day. If the numbers work out, make an EA and start looking at it further. If not, figure something else out. Maybe each day the numbers come out, the price moves 30% in the opposite direction of the previous day, or some crap like that.

If you follow these sort of very simple rules, you can backtest with nearly 100% accuracy, even if the exact profit / losses aren't known. I KNOW that the system will win (on average) more than it loses, because I have hard statistics to back it up. It also saves a TON of backtesting time and trying to optimize. Yes, backtesting will get you variable results each time, but the general theme of wins/losses and profit vs loss should be consistent and you can count on those numbers.

Real world example

Both of my EAs, combined, use one single indicator. In reality, I don't even need it.

The entry has a 66% chance of being right. If the entry was wrong, it has something around 75-90% of returning to profit within a certain timeframe. If it's not profitable by that point, it gets closed.

Running through testing, I can easily have streaks of 10 or 20 trades without a single loss. I know I can trust these numbers, because even though the profit returned isn't accurate, the OVERALL win/loss numbers and strategy are solid.

Remember, we're testing the idea, not the exact numbers. If your strategy says that every wednesday the price shoots up over 100 pips, you don't need to know whether it was 100, 105, 110, etc. You just need to know that it shoots up at least 100 pips (your takeprofit) more often than it hits your stoploss (say 20pips).

That's it, for now

I hope folks find this helpful. It's enabled me to get to a new level when it comes to developing systems and coming up with profitable ideas. I'll answer any questions posted or provide coding tips (although I may not be up to CodeGuru's level and such!)

Thanks!

-Jason

 

Hi, Jason, looks like your title should be "tips for people who's thinking of making EA".

I'm a programmer myself, I agree use include is a good way to save time copy and paste.

 

Tips For Trading Forex Profitably

Trading Forex can make you a lot of money if you know what you are doing. However, it can also lose you a lot of money if you are not careful. Here are 3 tips for becoming more profitable in Forex:

Be cautious when using software

There are plenty of Forex trading software programs out there, and most of them claim they can get you huge returns on your investments. However, you need to be cautious about which programs-if any-you use. There is a reason that 95% of human investors fail to make money with Forex trading-it is difficult. There is no program that will get you rich, and you are usually better served to invest yourself.

If you do plan on using software, make sure to research it thoroughly beforehand. There is nothing wrong with using a robot, and for some traders it is a necessity. After all, it can take a long time to analyze the market, and if you have a day job this might not be practical. However, not all software packages are created equal. Just be sure that you have read a number of reviews before committing to any program.

Have stop losses in place

Many investors believe that all their trades are going to make money, and they jump in with reckless abandon. However, even expert traders lose money on a huge percentage of their trades, and you will do the same. Make sure you always have a set point you will see the investment at no matter what, and stick with that at all costs. Just remember: the key to successful Forex trading is limiting your losses and riding your winners. This is true of any investment opportunity, and Forex trading is no different.

Use low leverage feature

Many times you will find brokers giving high leverages of up to 150:1, but these are very dangerous, particularly if you are new. If you are a beginner, do not go any higher than 10:1 to limit the risk. There is still significant profit potential with low leverage positions, but the loss potential is significantly less.

 
Trader5050-Deployed:
Begin coding via scripts, not EAs A script can very quickly run through the entire chart and tell you what percentage of win/loss scenarios you would have faced are. It's much easier to create a quick script and see whether or not that wonderful strategy you devised actually has a win rate of only 30% vs the 90% you see on the whole two months you were looking through data. This sounds like a lot of coding, but it actually is pretty simple

This is the first I've seen this mentioned anywhere. Every script I've seen has been a tool for the here & now - placing orders, moving stops and so on. Using them to backtest a strategy is something new to me & I didn't realise it was possible, let alone quicker to develop and run than an EA. Does anyone know where I could find a sample script of this kind with which to get started?

Reason: