What can or can't an EA do?

Total newbie question -
Just wondering can an EA be written, not only to open and close a trade, but can it be written to manage the trade? how powerful is this EA thing.
Can do whatever I imagine I want it to do.
Pretty limited - your better off being at the screen.

Ok example - as that probably works best - Can an EA be written, to do the following?

Open trade on criteria based on a current price passing an ema line when Stochs are in a certain range (and rising or falling) only if the CCI index is below certain range(and rising or falling) and only if the “trend” is in our favor .
ALL of this and if only above/below the middle bolinger band.
And pretty much a similar type of criteria to close the trade.

AND - on top of all that - manage the trade - record price action and or something like this.
define feeling1; feeling2; feeling3; etc. . and if price and or the next few minutes shows what I want to see as far as where is ema ; where is b.b ; where is cci ; where is stochs ; fill in feeling 1 and let trade ride or if going against fill in feeling3 and close trade early (instead of waiting for S.L.)

Any of this make sense? Can an EA do it?

Short answer: Absolutely it can do that.

Long answer:

(Since this depends heavily on the software, I’ll use MetaTrader’s MetaQuote 4 Language as my reference. Others might be less powerful.)

An EA can do everything you can do sitting in front of the software, plus it can do it faster, all day long. Assuming you have the technical wherewithal to program the EA, it can do most any technical analysis trading scheme you have cooked up (obviously it won’t help you with fundamental analysis).

The “open trade” analysis in the example you provided would probably be 50-100 lines of code max, and another 50-100 max for the “close trade” analysis. Not that big at all; once you are experienced with the platform you could probably write it up in an afternoon.

The difficulty in using EAs (this is just my opinion here) is tuning it. Ok, you sat down for 4 hours and traded the M5 and gee, you made a profit using your strategy. Let’s be optimistic and say you turned off your human brain and followed it exactly - per pip. If everything shouted BUY but the price was one pip away from whatever value your strategy defined, you didn’t buy. Even if 5 times in a row buying in that situation would have profited. So let’s say you do that for 4 hours and it looks good.

Now you write up an EA, put in your parameters, and back-test it over the past 4 months… and even though there’s a little blip at hours 1-4, the rest is a big loss. Now what? You have to tune your parameters… and that is much harder said than done. Going through 4 months of charts and writing down stuff like “increase EMA crossover threshold by one pip?” and then changing it, re-running, seeing another loss, and trying to analyze it… THAT is what’s hard.

But absolutely, the EA can do what you proposed in your example, no problem!

Hope that helps :slight_smile:

Hi Intx,

what you said sounds interesting. I’m keen on trying out EA’s, do you have any brokers to recommend that can enable me to have the ability to do the coding? I have no idea how to code but there are a couple of things I’d like to try out.

Thanks mate!

Well I’m pretty new to forex so I don’t know too much about your options for brokers. Personally I’m demoing with IBFX. They use MetaTrader 4 as their software, which seems (in my humble opinion) really powerful. There are lots others… anybody that is reputable and uses MT4 would probably be fine… but you could give IBFX a shot if you want.

Note that I’m only demoing, I haven’t given them any money.

Ditto here I’ve actually got a couple of demo accounts - and currently I am using IBFX exclusively - and I am trying the EA there -oh my goodness - spent 4 hours last night what a blast.

I need to find someplace that defines how the ‘classes’ are used, I think they’re called ‘classes’, for example in the template the use a code something like:


I see via a little popup window what each parameter is for for this ‘class’ -
Not to big of a deal to identify what is where, but how to use?

I’ve got a couple of quarters of C++ study under my belt, but - that was 4 yrs ago.

So I want to learn about the bollinger band '‘class’ iband(parm1 . . ) and how to use it.

I need to extract the value of the ‘topline’ ‘middleline’ and ‘bottomline’

Ok, not asking for help here, just trying to explain what I am going to try to do next. (although if someone provides help, I will certainly take it)

Yeah I realize the thread kinda got off track, but here’s some quick info for you, PerchTird.

I use a particular site that has lots of MQ4 documentation and some examples… I’d post a link here but it’ll just get removed as I’m <50 posts. Google for “mq4 documentation” and click the sub-link for the first hit.

As for what you’re calling “classes”, they’re actually functions. But the same idea. That site I mentioned describes each of the arguments that each function takes and what they mean.

For your particular question, here’s how you get the Bollinger values for the most recently completed period (the middle line is just an SMA at the given period, that doesn’t come with iBands):

int bb_period = 20;
int bb_deviation = 2;
double price_upper, price_lower, price_middle;

price_upper = iBands(Symbol(), 0, bb_period, bb_deviation, 0, PRICE_CLOSE, MODE_UPPER, 1);

price_lower = iBands(Symbol(), 0, bb_period, bb_deviation, 0, PRICE_CLOSE, MODE_LOWER, 1);

price_middle = iMA(Symbol(), 0, bb_period, 0, MODE_SMA, PRICE_CLOSE, 1);

Incidentally, I’m thinking of writing a tutorial on MQ4 to post to the forum. We’ll see how motivated I feel :slight_smile:

Hope that helps!

Wow thanks for that post - I don’t have time now to look look at it, but I will tonight.

I will also be googling - mq4 documentation - again thanks.

A tutorial - now that would be nice - lemme know if/how I can help - I am pretty interested in programming and learning code ESPECIALLY since it will have meaning for ME :slight_smile: - - (ie I liked taking classes, but never really had motivation to create anything) now that I think I’d like to trade on forex - AND I can write a ‘program’ to do it for me - just seems fun and if I can make some money - well that would be even better.

ok -I couldn’t wait until tonight - I did a search as noted - and bingo - that’s exactly what I am looking for - now , now only if I had the time - it’ll take weeks or even months to study all of that. :slight_smile: oh well it’s for a good cause.

A little off topic and a little on.
I agree totally with the statement an EA can do almost anything.
The one thing it cannot do is think.
It can only do what it is programmed to do.
EA’s [any software actually] are only as “intelligent” as the person/s who wrote it.
EA’s, as with almost any software can become “confused” as well.
I’ve been reading and trying to learn Forex for over a month now and have also looked at the EA’s like Fap.
They’re a neat idea to an extent, I just don’t trust them.
If you’re going to go to the trouble to write an EA for your own personal use and willing to go to the trouble to learn how, let me ask you this, why not use Linux as your OS and run the EA there?
C [+] [++], Python, Perl, java and BASH are all used and compatible in Linux.
MT4 can run in Linux.
I’m running MT4-FXOpen as I’m writing this and I’m running Arch Linux.
Linux seldom if ever needs rebooting, seldom if ever crashes, and unless you run in root [admin], never gets hacked or viruses.
I don’t run a firewall beyond my router and have zero need for an anti-virus.
To my way of thinking, hacks and viruses are a big concern, especially if you’re sound asleep and have an EA running.

MT4 runs under Linux (with Wine), but not terribly well. The fonts are funky, there’s some graphics blips, and some features don’t work (“use date” in the back-tester), and you gotta rip that one DLL from somewhere. But it does work.

I’m not sure Linux offers anything over Windows when it comes to running an EA (beyond the usual benefits of Linux over Windows, that is). I guess there’s less of a threat of viruses, but to be honest, keeping a stable, virus-clean XP machine that does nothing but run MT4 isn’t hard. It’s probably easier for most people than getting MT4 to run under Wine :slight_smile:

As for your other comment, about an EA not being able to think… that’s a really interesting point. In one sense you don’t want the EA to think. That’s the idea, it just coldly applies logic and never gets scared by emotions and makes an off-strategy decision. But then on the other hand, human brains are really powerful at estimation, and some of the mechanisms that our brains use to analyze lots of data at one time (such as a price curve) are really difficult to implement in a computer… so in that sense your EA doesn’t “think” quite the same as you do.

Personally, I’ll take the EA over a human any day (at least mathematically!) :slight_smile:

As for MT4 under wine, it’s no more difficult than dropping the .dll, or in my case, all 4 that windows had, into the sys32 folder in wine.
The EA’s I’ve read about require dropping files in folders also.
As for lack of functions or funky fonts, it may depend on how up to date wine is and what fonts one has installed.
I havn’t tried all the functions on mine but the ones I do use work fine, Bollinger bands, volume, Elliot wave, candlesticks, Fibonacci.
I use MT4-FXOpen btw, it does better than MT4 itself.
There is also the risk of viruses not known about for Windows, and there are more than a few of those out and about.
Script kiddies never sleep it seems like.
As for an EA thinking fast, I agree, nothing can add and subtract like a well written piece of software.
I also agree a program does only as it’s programmed to do,usually.
I’ve read a few stories of some of these EA’s getting confused when the market is in overdrive and costing a lot of money when they were left in auto.
We’ve all seen software gilfritz, usually when we needed it most.
This happens in windows more often than Linux and I am speaking from experience here on that topic.
I’ve been totally Linux for a few years now.
That applies to my comment on thinking also.
The auto does not “think” it’s doing anything wrong when it’s going spastic buying/selling or just hung up and not doing anything beyond monopolizing the cpu.
I also mentioned Linux due to it’s seldom if ever needing rebooting.
My idea of a neat EA would be one that would watch for a decent market set up to enter or close per a persons strategy, then sound an alarm, that’s all as far as making a trade goes.
It could have the proper whatever criteria marked in some fashion so the person can at a glance agree or disagree and take the appropriate action.
If a person is in a position such as mine [disabled] they’re at home an awful lot, sooo, they can leave their pc on 24-7 and be able to pay attention to more than 1-2 charts if they so desire.
What I’m seeing concerning EA’s though is too many want to take the easy way out and hand full control over to an EA made by someone else and remove any work whatsoever by themselves beyond installing the thing, to include the much needed learning process.
Human nature I know, but the easy way out seldom is the proper answer.
But, to each their own. :slight_smile:

Agreed… it’s useful to think of an EA as a complex indicator. Letting it actively trade during press-release or other high volatility times can be dangerous if you haven’t accounted for that in your code. I’m not sure I’d have the nerves to let an EA trade 24/7/365 with real money without at least checking in on it every few hours to make sure it’s not shoveling my money into a pit!

I googled mq4 documentation, and for some reason the links that appear first are those stupid links that take you to some other sites with advertisements. I don’t know if anyone else has noticed this, but google just isn’t what it used to be. It used to be that you do a search and the most relevant links appear, now it’s just those stupid third party links that contain keywords included in your search and then when you click on them you get bombarded by totally different and unrelated material.

Anyway, i’ve started a thread and i’ve got a question for you intx13 in that thread (since you said you’d rather have us post questions on MT4 somewhere other than your comprehensive thread about it).

EA can be made to follow any mechical trading strategy. However i doubt it could used to analyze fundamental events and trade based on analysis.