Friday, 18 March 2011

Stoploss or die !! and MT4 - MQL

I was trying some 'scalping' this week, this is where you try to make short term 5, 10 or 15 pip quick gains only grabbing small gains but frequently. It obviously requires you to be 'at your terminal' to do this.....all was going well until in a blink of an eye one of my trades crashed 100 points (on news...or indeed speculation by senior EU bods on the nature of the nuclear leaks in Japan). In a moment I was open to a $300 loss on a 3 point trade.....this thankfully came back mostly, but wiped out most of my small gains and added to my so far downtrending balance.

The lesson....even when scalping make sure you put in an emergency stop loss, even if its a good distance from your initial position.

In other news I managed to get my first expert advisor working, this is a programmed algorhythm where you automate your trades. I have got a few working where I actually make profit to....unfortunatly on too few trades to be practical.

Using the MT4 trading tool and the MQL language you create a small program that tests the market EVERY TICK (this is many times a minute). You can inspect standard metrics, like bollinger bands, moving adverages etc and even inspect previous bars on the chart. Then automatically place, modify and close orders.

Here's a clip of what the code looks like :-->

while (iLoop != 0)
{
dDelta = (Close[iLoop]-Close[iLoop+1]) * 10000;
   dDeltaAggregate += dDelta;
   if (dDelta > 0) iUpTrend++;
   if (dDelta < 0) iDownTrend++;
iLoop--;
}

This loop simply compares the closing value of one bar to another (the previous one) and counts the number of bars heading in either an up trend or a down trend. You can then test your advisor over months or years of previously recorded trade data. This generates you a report which you can use to see if your trades would be successful. A great resource for coding tips is here : http://docs.mql4.com/index (and also in my links).

Below is an example of the testing tools output, in this test result, my system made 20 trades over 3 months (on one currency pair over, so in theory this would be about 200 trades over 3 months). It retuned a small profit. This is enough to use a system (yet) and would also need an extended amount of forward testing, where I would run it for weeks or months on my demo account against live data.

Great fun doing this and also very edumacational, till next time, pip pip

                                                          Click on image to expand the report

No comments:

Post a Comment