Friday, January 1, 2010

Zulutrade - Last Post

Welcome back Zulu-traders and Forex fans.

Happy New Year and best wishes for a healthy and prosperous New Year.

Well its been said that the very definition of insanity is when you keep doing the same things over and over expecting a different outcome. In my case, that means Zulutrade which has done nothing but loose me money. So as of January 1, 2010, I'm done with Zulutrade.

When I first saw Zulutrade, I thought - what could be easier? Experienced Forex traders all around the globe competing to rise to the top of the Zulu-food chain. All I had to do is pick a few signal providers, throw them a few dollars and the cash would start rolling in. And its all free. What could be easier?

Well of course it didn't turn out that way and this blog is a chronicle of my money-loosing experience with Zulutrade.

We all know the flaws of the Zulutrade platform, but since I'm winding down, let's go through them here:

1) Signal providers don't have to trade their own real money - its all funny money to them

2) Signal providers have unlimited capital and can keep adding to loosing trades indefinitely. This has made many an equity curve go from the lower left to the upper right - when in reality the actual customer experience is another story

3) Signal providers are compensated by transaction and not by the profitability of their signals.

Zulutrade management is well aware of these flaws and they could easily correct them. But they don't correct them and why? Because the real records of the signal providers would be exposed and they wouldn't look so good. And once the the real records were exposed, they would stop suckering in new money - just like I got suckered in.

Anyway, I don't regret the experience because I've learned some valuable lessons and made some great relationships.

You can follow my further experiences with Forex trading on my new blog over at:

http://fx-mon.blogspot.com/.

I'm also continuing to blog my equity trading at:

http://tcxsystems.blocks.com/

And you can follow my tweets at:

http://twitter.com/tcxmon.

All the best to you and your family for a healthy and prosperous new year!

Wednesday, December 30, 2009

MetaTrader - MQL4 programming - Part 3

Welcome back Forex fans.

Here's my 3rd installment on programming MetaTrader. In case you missed my prior posts, you can find them here MetaTrader programming part 1 and MetaTrader programming part 2.

In this post, we'll take a look at the MarketInfo() function. This function pulls some necessary information from the broker's about the symbol in question. Go ahead and create a new EA file called MarketInfo. Paste the following code above the init() function:

string sSymbol;

Now paste this code into the init() function:

int init()
{
// Grab current symbol
Print("Marketinfo Startup");

// Grab current symbol
sSymbol = Symbol();

// Print it out and finish up
Print("Symbol: ", sSymbol);

return(0);
}

Now setup your Start() function as follows:

int start()
{
double dRetval;

dRetval = MarketInfo(sSymbol,MODE_LOW);
Print("Days high: ", dRetval);

dRetval = MarketInfo(sSymbol,MODE_HIGH);
Print("Day low : ", dRetval);

/* Skip Bid, Ask, Point, Digits, they pre-defined variables */

dRetval = MarketInfo(sSymbol,MODE_SPREAD);
Print("Spread: ", dRetval);

dRetval = MarketInfo(sSymbol,MODE_STOPLEVEL);
Print("Stop Level: ", dRetval);

dRetval = MarketInfo(sSymbol,MODE_LOTSIZE);
Print("Lot Size: ", dRetval);

return(0);
}

/* Skip these
MODE_LOTSIZE 15 Lot size in the base currency.
MODE_TICKVALUE 16 Minimal tick value in the deposit currency.
MODE_TICKSIZE 17 Minimal tick size in the quote currency.
MODE_SWAPLONG 18 Swap of a long position.
MODE_SWAPSHORT 19 Swap of a short position.
MODE_STARTING 20 Trade starting date (usually used for futures).
MODE_EXPIRATION 21 Trade expiration date (usually used for futures).
MODE_TRADEALLOWED 22 Trade is allowed for the symbol.
MODE_MINLOT 23 Minimal permitted lot size.
MODE_LOTSTEP 24 Step for changing lots.
MODE_MAXLOT 25 Maximal permitted lot size.
MODE_SWAPTYPE 26 Swap calculation method. 0 - in points; 1 - in the symbol base currency; 2 - by interest; 3 - in the margin currency.
MODE_PROFITCALCMODE 27 Profit calculation mode. 0 - Forex; 1 - CFD; 2 - Futures.
MODE_MARGINCALCMODE 28 Margin calculation mode. 0 - Forex; 1 - CFD; 2 - Futures; 3 - CFD for indexes.
MODE_MARGININIT 29 Initial margin requirements for 1 lot.
MODE_MARGINMAINTENANCE 30 Margin to maintain open positions calculated for 1 lot.
MODE_MARGINHEDGED 31 Hedged margin calculated for 1 lot.
MODE_MARGINREQUIRED 32 Free margin required to open 1 lot for buying.
MODE_FREEZELEVEL 33 Order freeze level in points. If the execution price lies within the range defined by the freeze level, the order cannot be modified, canceled or closed.
*/

As we can see from the code, the MarketInfo() function allows us to pull the day's high and low when using the MODE_HIGH and MODE_LOW parameters. This could be useful when coding an Expert Advisor. The daily high/low counters reset when the daily interest rate roll occurs which is at 5PM EST.

Calling MarketInfo() with the MODE_SPREAD parameter pulls the current spread for the pair which you can get just as easily by subtracting the Bid from the Ask and dividing by Point.

The MODE_STOPLEVEL parameter returns the number of pips away from the current price at which you are allowed to place the a stop order or take profit order. In the above example, the Stop level value is 4 so if we went long the market at an Ask price of 1.4340, the closest that we could place a take-profit order would be 1.4344. If the current Bid price were 1.4338, the closest we could place a stop-loss order would be 1.4334.

When I first found out about this, I thought was kind of unfair. I suppose it prevents the market maker from constantly getting scalped and ensures that on trades that go against the customer, they make at least the spread plus the stop level. Of course, there's nothing preventing you from entering market orders to close a position within the StopLevel.

The MODE_FREEZELEVEL parameter returns the number of pips away from the current price at which limit orders are "frozen" and cannot be changed. For example, if the FREEZELEVEL were 5 and the current Bid/Ask was 1.4356 x 1.4358 and you had a limit sell order at 1.4360, you would not be allowed to modify or cancel your limit order since it was within 5 pips of the Bid price.

On my terminal FREEZELEVEL came back at zero, so i'm not sure its enforced with FXDD on their Metatrader platform.

Now save and compile the EA and drag it onto a chart of EUR/USD. Now drag it onto a few other charts such as GBP/USD and GBP/JPY to get a feel for the different Spread and Stoplevel values.

That's it, come back later for more MT4 programming.

Tuesday, December 29, 2009

MetaTrader - MQL4 programming - Part 2

Welcome back, fans of Zulutrade and automated forex trading.

Let's continue our look at programming Expert Advisors in the MetaTrader platform. At this point, you should know the basics of MetaTrader and how create an apply an Expert Advisor. If you need a refresher, see my prior post MQL Programming Part 1.

Now open up MetaTrader and create a new EA called welcome.mq4 and save it in the Experts folder under your MetaTrader install folder. Then exit MT4, and restart it and you should see your new Expert Advisor called Welcome on the left side under the Expert Advisors folder.

Now open up the Welcome.mq4 folder and add these 2 new variables in the header section before the init() function:

// Total bars on the chart
int nTotalBars;

// Number of bars to look back
int nLookBack = 5;

Now complete the Init() function as follows:

int init() {
datetime dNow;
string sDate;

string sTime;
dNow = TimeCurrent();
sDate = TimeToStr(dNow, TIME_DATE);
sTime = TimeToStr(dNow, TIME_MINUTES);

Print("Initializing Welcome EA");
Print("Server time: ", sDate, " ", sTime);

// Grab total bars
nTotalBars = Bars;
Print("Point: ", Point);
Print("Digits: ", Digits);

return(0);
}


In the Init() function, we grab the server time using the TimeCurrent() function and use TimeToStr() to convert it to its date and time components and print them out. The print output appears on the "Experts" tab and are a convenient way to interact with the user.

We also grab the values of the Bars pre-defined variable which return the total number of bars on the current chart. We also print out the value of Point variable which shows the point size of the current pair. With FXDD and the EUR/USD pair, the Point equals 0.0001. and Digits equals 4.

With that behind us, we know all the real action takes place in the start() function which gets called each time a new tick arrives at the terminal. Let's take a look at now to access price data from inside the Start() function.

Pre-defined variables Bid and Ask return the current market prices for the pair.

Pre-defined variables Time High, Low, Close and Volume return the values of the bars on the chart. Each variable is really an array, and the 0th array value (High[0] for example) shows the High for the current price bar currently being formed. High[1] refers next oldest bar. Close[10] would return the closing bar value 10-bars back from the current bar.

With that, let's code a Start function that prints a message to the Experts tab each time the pair makes a new n-bar high. For the purposes of this example, let's use 5 for the bars to look back.

Now let's code the start() function as follows:

int start()
{
// Use to index into price array
int i = 0;
bool bNewHiLo = false;

// Zero's bar is the bar current in the making
double dAvgPrice0 = (High[0] + Low[0]) / 2.0;

Print("Avg/High[0]/Low[0]", dAvgPrice0, ",", High[0], ",", Low[0]);

double dAvgPriceN;
double dAvgPriceHi = 0.0;
double dAvgPriceLo = 999999999.0;

// Calculate N bar high and low for this bar
for (i=nLookBack; i>0; i--)
{
// Calculate average price for this bar
dAvgPriceN = (High[i] + Low[i]) / 2.0;

// Save new high and lo
if (dAvgPriceN < dAvgPriceLo) dAvgPriceLo = dAvgPriceN;
if (dAvgPriceN > dAvgPriceHi) dAvgPriceHi = dAvgPriceN;

}

if (dAvgPrice0 > dAvgPriceHi) {
Print("New ", nLookBack, " bar high at: ", dAvgPrice0);
bNewHiLo = true;
}

if (dAvgPrice0 < dAvgPriceLo) {
Print("New ", nLookBack, " bar low at: ", dAvgPrice0);
bNewHiLo = true;
}

if (bNewHiLo == false) {
Print("No signal ", nLookBack, "-Bar Hi/Lo/Current: ", dAvgPriceHi, ",",dAvgPriceLo, ",",dAvgPrice0);
}

return(0);
}


There's a lot going on here, so let's go through it one line at a time.

At the top of the start() function, we calculate the average price for the 0th bar - the bar currently in the making. I decided to go with average price for the bar so I don't give any additional credit to the opening or closing price for the bar.

Next, I declare variables dAvgPriceHi and dAvgPriceLo to hold the high and low prices for a given lookback. I initialize dAvgPriceHi to 0.0 and dAvgPriceLo to a high value so that first real price that comes along will get saved as the high or the low.

After that, the for loop is used to step through the price bars starting with 5 bars back and stepping forward until we reach bar 1. I calculate the average price for each bar and compare it with the previously saved high or low. When that loop finishes, dAvgPriceHi has the highest average price for that 5 bars and dAvgPriceLo as the lowest average price for that 5 bars.

Finally, I see if the average price for the currently forming bar (bar 0) is higher than the highest high (or lower than the lowest low) across the lookback period. If so, I print an alert out to the Results tab.

You can probably see where I'm going here. I'm working toward an expert that buys on breakouts of a n-bar high or sells on breakdowns from the n-bar low. I can make the value of N a variable and use the back-testing and optimization feature of Meta-trader to find good values of N for a given tradeable and bar pair.

Now compile the EA and fix any syntax issues. Now drag the EA onto a 1 minute chart of EUR/USD and watch it go to work.

That will form the basis of my first EA which is based on Donchian channels.

Finally, I realize there are limits to including the code itself in the blog. I'll figure out a place where I can publicly post the EA code as its developed and just highlight the interesting parts in the blog.

Monday, December 28, 2009

Zulutrade - Top Providers by Live Trade 12/24/2009

Welcome back Zulutraders and Forex fans.

To your left, please find the top 20 providers by live trade for trades closed from 12/20/2009 through 12/24/2009.

Overall trade volume was about half the levels of the prior week indicating many traders are taking a break from trading for the rest of the year.

Our favorite Cheetah moved up to the #4 spot from #5 last week. The other 4 traders just swapped positions with Surfing and LowestDD getting bumped out of the top positions and being replaced by sharp forex and smart forex.

Former favorite Bigwin had a big week, raking in a bunch of pips and moving from position #26 the prior week up to #17 last week.

That's all for now, check back later for more updates on automated forex trading.

Saturday, December 26, 2009

Zulutrade - Accounts Update 12/24/2009

Welcome back Zulu-fans. Here's a recap of the week's action.

Things were quiet in the live account. Cheetah picked up 3 pips and that was fine with me. My live account now has just about 380 pips left, so we'll see if Cheetah can pull it back from the brink. On the demo accounts side...

Blinov was looking sharp and picked up 105 pips with 6 straight winners with only a 64-pip draw down. Blinov has now picked up 330 pips on 17-straight winners since adding him on a demo account back less than 2 weeks ago. He has about -394 pips in open losses, so we may have just been lucky not getting stopped out.

Next up is Missforex who picked up 48 pips on 4 straight winners. He is up 392 pips since the beginning of the demo period only 2 weeks back with 10 straight winners. Unlike Blinov, Missforex has no open positions.

Ferrari was down 14 pips on the week in quiet action.

Hayate had exactly one trade and hit my 180 pip stop. Ouch.
kingtrade didn't trade last week and has only traded 4 times in the month of December. Zulutrade shows he has in the neighborhood of 70 live followers, just waiting for him to spring a trade.

280pips.com is down -44 pips on the week, but I can't blame the provider since I had him reversed.

Student picked up 12 pips, but now has 6 open EUR/USD positions in the red. This is uncharacteristic of him, since he usually takes his losses. At this point is is painting the tape to keep his performance graph on an upward trajectory.

That's all for check back for more updates on Zulutrade, Metatrader, and automated Forex trading.

Friday, December 25, 2009

MetaTrader - MQL4 programming - Part 1

Welcome back Zulu-traders and fans of the Forex.

Here's wishing you a Merry Christmas and all the best for a healthy and prosperous New Year!

Let's take a look at programming in MQL4 - the language of MetaTrader 4. Even if you don't plan to write your own Expert Advisers, its good to understand how they work. So how do you go about learning MQL4? You read the book, of course, which is found here.

I got through about half of the book and the author spends a lot of time on programming basics. If you've ever done any programming, the language looks pretty familiar and is probably closest to the C language. I'm not going to attempt to teach you programming here, so I'll just extract the most important concepts to get you started.

Anyway, there are 3 basic things you can program and execute inside the MetaTrader platform. To execute one of these items, simply drag it from the navigator on the left and drop it onto a price chart. Here are the 3 things you can program:

1) Expert Advisor (EA) - An MQL4 program used for automated execution of trading strategies. The EA is called automatically by the MQL platform at every "tick" or change in price from the quote server.

Only one EA can be attached to a given chart, but you can apply multiple EA's to a given currency pair by opening multiple windows for that pair and dragging a different EA onto each window. It's typically advisable to run only one EA on a given account at a time, otherwise it becomes too much to keep track of.

Most MT4 users address this issue by installing MetaTrader into different folders (you get prompted for the folder at install time) and running multiple instances of MT4 on your computer. This would allow you to run 3 different EA's against 3 different demo accounts all at the same time.

Expert files get placed into the Experts folder under the folder where you installed MetaTrader.

2) Script - An MQL4 program to automate a series of operations involving price or trading. Scripts are allowed to call trading functions. A good use for a script would be to close all open trades. Scripts are executed only once on the chart at the time it script is dragged onto the chart.
Script files get places into the Scripts folder under the folder where you installed MetaTrader

3) Custom indicator - An MQL4 program to calculate technical indicators on the current price chart. Custom indicators calculate values to be drawn on the price chart (such as a moving average) or in a separate windows such as an oscillator. Indicator scripts are called automatically by the MT4 platform at each tick. Trading functions cannot be called from inside indicators. Multiple indicators can be applied to a chart at a given time which distinguishes them from EA's and Scripts.

Script files get placed into the Scripts folder under the folder where you installed MetaTrader

Each of the above types of program contain 3 pre-defined functions:

init() - called only once when the Indicator, Script or EA first starts. This is a good place to do any first time operations in your programs.

deinit() - called only once when the Indicator, Script or EA ends. This is a good place for clean up operations.

start() - called each time a new tick arrives at the platform for both EA's and Indicators. This is where most of the action is. I believe start() is called only once for scripts.

Now that we have that behind us, let's write our first program in MQL4.

  • From inside the platform, click on 'Custom Indicators' on the left side and press the Insert key.
  • At the wizard which appears, select 'Custom Indicator' and click Next.
  • For the name, call it first.
  • Complete the rest of the screen with your name, copyright and blog if you have one and click Next.
  • Leave the following screen unchanged and click next.
Once the program appears on the screen, setup the init function as follows:

int init()
{
Alert("Hello MetaTrader");
return(0);
}

Alert() is a simple function that pops up a message on the screen.

Once you are done coding, click the Compile icon at the top and fix any syntax errors which appear. Once the compile is clean, select File, Exit and notice that the file will be saved in your indicators folder.

Now exit the MetaEditor window and return the MT4 platform window. Now select File, Exit to exit Metatrader.

Now start MetaTrader again and your new indicator (called first) should appear under the Indicators folder now. Now simply drag the new indicator onto a price chart and you should see the alert.

Congratulations, you just wrote your first MetaTrader program!

That's enough for now, check back later for Part 2.

Wednesday, December 23, 2009

MetaTrader - Intro to back testing

Welcome back Zulu-traders and forex fans.

Let's take a look at backtesting with the MetaTrader 4 platform.

Backtesting is the first step in evaluating an Expert Advisor. After all, if the robot doesn't make any money in backtesting over a one year period (for example), why consider it any further? More important, backtesting allows you to get a realistic idea of the amount of drawdown to expect.

To learn the basics, check out this 3-part video series YouTube Backtesting Videos.

Disregard the part about downloading data from the Alpari Website. You can pull down updated data inside the MT4 platform by going to Tools, History Center, double-click your pair, select your timeframe and click download.

The Expert Advisor evaluated here is called Framework and can be downloaded for free by clicking on the link. This EA uses crossovers in the Commodity Channel Index (CCI) which is an oscillator whose values typically range between -100 and +100. This system uses 3 separate CCI values with parameters of 5, 25 and 125 representing short, medium and long term values of the CCI indicator.

The trading logic is relatively simple. Take a long positon when the medium CCI is below the zero line and when the short and long term CCI's are both above zero. Take a short position when the medium CCI is above the zero line and when the short and long term CCI's are both below zero. The system uses a take proft of 255 pips and uses no stop loss.

While there is no stop loss, the system will close out all open positions and start to trade in the other direction once it gets a signal opposite any open trades. The system also pyramids (adds to) positions in the current direction as long as trades are open once a certain number of bars have elapsed.

The results from testing were pretty impressive across multiple pairs when tested on a daily timeframe from 1/1/2009 through today. Here are ending, high and low values on a $10,000 account over the test period:

Pair, High, Low, Ending
USD/JPY - $14,962, $8324, $10,606 (big drawdown from the high)
EUR/USD - $12,252, $10,244, $12,252 (all winners)
GBP/USD - $10,705, $8947, $8947 (ended at the low)
GBP/JPY - $14039, $8888, $11865 (stomach churning)

Overall drawdowns from the entry were contained to under 20% from the initial deposit. But there were some roller-coaster changes in account equity for example with USD/JPY going as high as almost $15,000, then drawing down to under $9,000 to end up at $10,606.

In summary, this robot isn't for me but is an interesting learning experience. The drawdowns can be large and (unlike Zulutrade History), all open positions are closed out at the end of the test period, sometimes ending in a sudden closing loss such as the GBP/USD example above. This trades might eventually work out, but I would rather know the closing equity than leave open trades off the grid - like Zulutrade does in their test results.

Also, there are issues with the quality of the test results as shown by the modelling quality metric on the results tab. There are many issues to consider when testing robots, and i've learned alot from this exercise. I've also started to work through Daniel Hernandez's e-book from http://fxreviews.blogspot.com/.

Long story short (and confirmed from Daniel's e-book) if you think MetaTrader expert advisors are an easy path to riches, think again! Enjoy some time off and check back later.