Education

How do you know you aren’t fooling yourself? Are you curve fitting your EA?

Are you curve-fitting your EA?

Creating input parameters for an Expert Advisor is easy. It’s easy in MQL and it’s easy in VTS.

In MQL you just use the keyword extern. It looks like this:

extern int StopLoss=200;

There are a couple of ways to do it in VTS. When you create a Variable Element you can set the scope as extern. Or you can use the Input Manager. You can read more about the Input Manager here: VTS->Help->Input Manager

Input parameters appear on the input tab when you attach an EA to a price chart.

They are very powerful. Input parameters allow you to change the behavior of your EA without rebuilding it.

They are especially useful for testing. You can change the values and see how your EA performs. The MetaTrader Strategy Tester even allows you to run a back-test that automatically optimizes your input parameters.

That’s powerful, but it’s not the most powerful way to use input parameters.

The most powerful use of an input parameter is to find out if you’re fooling yourself.

How so?

I’ve written about curve fitting before. (On page 29 of Automatic Alpha I write about curve-fitting and the technique I’m about to describe here.)

Basically, to curve-fit means to create an EA that works for a specific time period.

It’s not that hard to do. As matter of fact you can do it to yourself without even realizing it!

Luckily, there’s a way to find out.

Robustness is a term used when designing a control-system .

(An example of a simple control system is the thermostat in your house: when the temperature drops, the heat is turned on. When the temperature rises, the heat is turned off).

Anyway, robustness defines the stability of a control system. Think of it this way: A stable system acts like a marble inside a bowl. If you gently shake the bowl, the marble will move for a little while, but it will eventually stop and settle at the bottom of the bowl.

An unstable system acts like a marble on the top of an upside down bowl. If you gently move the bowl the marble will fall off and roll away!

Why am I talking about this? Because an EA that has been curve-fit behaves like an unstable system.

Shaking the bowl is like changing the input. How do you shake an EA?

You change its input parameters.

So, to test your EA for robustness you vary its input parameters.

Suppose you have an EA that uses a 12 period moving average to open trades. You change the period from 12 to 24 and record your EA’s performance.

If your EA performs significantly different when you change the period of the moving average, then the EA is not robust. It’s sensitive to changes.

Does this mean it is a bad EA? Not necessarily. It means that it’s sensitive to changes in its input. So, you should not be terrible surprised if the EA’s performance changes in the future, because, well, things in the future change.

The bottom line: if the EA is super-sensitive to changes it is probably curve-fit. It’s likely that it will not perform in the future the way that it has in the past. (If you are buying a black-box EA, all I can say is “caveat emptor”.)

When you build an EA with VTS, use the Input Manager to create input parameters for some of your indicator parameters.

This way you can test and find out: Are you fooling yourself?

 

What is the heart of an Expert Advisor?

What is the heart of an Expert Advisor?

Opening and closing trades is not the heart of an Expert Advisor.

Neither is the number of lots traded. And it’s not the value of the stoploss or the takeprofit.

Those parts are important for sure, but they’re mechanical and usually pretty straightforward.

No, the important part of an EA, the very heart of an EA is its logic.

The logic used to open a trade. The logic used to close a trade. Even the logic used to calculate the lot size and the stoploss and the takeprofit.

In VTS, we use Logic Elements to construct the heart of an EA.

I’ve really gone out of my way to make defining the logic easy. For instance, to test for a “cross over”, I created two special operators that you’ll only find in VTS: CROSS_UP and CROSS_DOWN.

To recognize that two lines, say line A and line B, have crossed requires 4 points of information. The values of line A and B now, and the values of line A and B from earlier (maybe from the last  candle).

If the value of A used to be less than B, but now it’s greater, then the lines have crossed.

I write about this in MQL For Traders.  Here is a picture from page 116 that might help. See how the value of the blue line used to be less than the green line (in Period2), but now it is greater (in Period 1.)

 

Cross Over

Cross Over

You wouldn’t realize this unless you really thought about it, huh?

You don’t need to know things like this to use VTS. I suppose it might help, but it’s not mandatory knowledge.

You definitely don’t need to know how to write the MQL code for a cross over. (Honestly, I don’t even like writing that code – it’s confusing and very easy to make a mistake).

You can read more about VTS Logic Elements here:

VTS-Help-Logic

You can easily view the MQL code that’s generated from the CROSS_UP and CROSS_DOWN operators. Just click the Editor button inside of VTS. You can learn more about the Editor here: VTS-Help-editor.