Why I am not a big fan of MQL4 or trading platform scripting

I spent most of 2008 trading futures and developing automated systems on Tradestation. The futures trading didn't turn out so well as I lost 40% of my account and had to call it quit. My quant development work on the other hand, was coming along slow but steadily. However, since I couldn't bear the monstrous maintenance fee anymore at Tradestation, I had to abandon that work. Then last year when I wanted to pick up where I left off on Matlab, I found that I couldn't just continue my work. For one, I've lost most of my files. I think I left them in my other computer in Hong Kong. Which is probably in a landfill by now. Secondly, I didn't keep a thorough journal back then in 2008 like I'm doing now. Lastly, from the important files that I've kept, I didn't bother to convert the codes because I might as well write new ones from scratch than figure out what I did. The reason why I am reminiscing at the moment is because I am finding myself in the same cycle again. As regular readers may be aware, recent events have accelerated my quant projects schedule. I am experimenting with using Metatrader 4 for my foreign exchange trading and scripting in MQL4 for automated trading. Like Tradestation, Metatrader 4 is a trading platform with scripting capabilities. Its programming language, MQL4, is a proprietary language based on C. I took a few hours this weekend to learn it (as I'm familiar with C already). So that I can start coding this week. However, after giving it more thought, I've decided to scale down on my projects with MQL4. I don't want to rely on a proprietary system for short-term convenience. As trading programmers know, the language used is merely a choice. Experience tells me that the bulk of development time is not spent on the actual programming itself. Rather, much of the time is spent on formulating, analyzing, and optimizing your algorithm. So I might as well bite the bullet to build from scratch my automated trading systems and quant analytics on one platform (i.e. on Python). That has been my long term plan all along. Everything under one roof. But I digressed. Then there's the issue of re-useability. Metatrader 4 is forex-only and only works with brokers that support it. As such, I would have to use something else for stock trading. Even for a forex-only system, it would help if I can do intermarket analysis quantitatively. That's not possible as far as I know with MQL4. Which is another major downside for me. To summarize other reasons on how I came about this decision, here are the advantages and disadvantages of using MQL4 versus using a general programming language, such as Python or C++. The advantages of using MQL4 are:

  1. Saves A LOT of development time as it's already built for trading
  2. Charting, manual and automated trading on one platform
  3. Based on the popular C programming language
  4. Many forex traders use it
  5. Large repertoire of forex-specific programs

Disadvantages of using MQL4.

  1. Not for real quant analysis or data mining
  2. Limited to MT4-supported brokers
  3. Forex trading only
  4. Proprietary programming language
  5. Must run on Metatrader 4 client terminal
  6. MQL5 coming soon

This is certainly a tough choice. Judging by the huge user base, it's evident that many people are satisfied with MQL4. Yet, as I've discussed here, there are downsides to using it (besides technical matters). My current plan remains the same as what I said in my last month's trading review. That is, I will use MQL4 to plug holes in my trading system for now before migrating to build my own system. In fact, I am already brewing my first expert advisor starting today. Perhaps I might even have something to post by the end of this week.

Departed TradeStation and going the Ninja Trader path

I have worked with TradeStation for a few months earlier this year. During that time, I worked for a few hours every single day on developing automated strategies and day trading on it. I thought TS was very good for use as a day trading platform. Particularly now that I'm using ThinkOrSwim, I feel the TOS system is grossly inadequate when compared to TS. However, I personally didn't like using TS as an automated strategy development platform. EasyLanguage (TS's development language) is definitely easy to learn and use. I would imagine EL would meet the needs of many people and they'd be satisfied with it. On the other hand, if you want to develop more complex strategies, the coding can get complicated to the point of confusing, if it's even possible at all. Like I never figured out how to build a simple neural net on it. Besides the language, another limitation of TS is its inadequate API. For example, and if I remember correctly, I had a hard time in the programming trying to tie my portfolio value to the strategy. To accomplish something simple like automatic portfolio balancing. Often times, I wanted to do something but then found that I needed some 'work-arounds' instead. In essence, EasyLanguage is easy to get started, but it certainly doesn't provide the depth which I wanted. Granted, it was a great starting point for me in automated strategies development. I learned a lot from it. Don't get me wrong though, a good strategy does not mean a complicated strategy. One could have a profitable strategy with just a few lines of code (moving averages, anyone?). What I want is something that can serve as my creative sandbox. I wanted something that can satisfy my wildest ideas. Actually, I just don't have sufficient risk capital to let loose a strategy, so I have the luxury of not tasked to yield results and is free to play with what I want. Including my POMDP discussion in my previous post, and my other idea of using modern control theory (my study focus back in the days) to identify market inefficiencies. I couldn't have done those with EL without over-complicating matters (DLL's, add-ons, etc.). The biggest factor though, was the monthly subscription cost. I stopped my TS subscription eventually because I just can't afford it. So what next? After some digging, I came across Ninja Trader. They support C# programming in their strategies. What's more, it's free for development use! I will be using it with opentick for a free datafeed. Free platform, free data! What more could I ask for? Update: It seems that opentick is overloaded and haven't been taking on new users for a few months now. I'll just use the simulated data within NT for now. Update 2009: Opentick is now closed until further notice according to them. I have began going through the NT tutorials and trying to refresh my distant memories on some technical topics. After a few months of vacation, I am back to the drawing board again. We'll see how it goes. I will document my progress here under the automated trading category.

2MA w/ ADX and disappointing realization

Another day, another strategy. For the past couple of days, I've been working on the 2MA cross with ADX confirmation strategy for ER2H08 1200 sh/bar. Basically, an HMA(Low, 8) crossing over EMA(Low, 24) as the trigger. Condition2 is that the current high is highest of past 3 bars. Condition3 is current ADX is also highest of the past 3 bars. Condition4 is that it is during day time so fewer slippage.

Exit is simply HMA(Low, 23) crossing under EMA(Low, 33) or it is nearing the close of the day session. Stop is \$350; Floor is \$500 and 63% retracement.

Upon loose optimization on Oct 1, 2007 to Nov 30, 2007 data, the Long strategy achieved 3.37 profit factor, 57% profitable, and a steadily rising performance graph. Very good indeed. I was estatic yesterday.

I continued to work on the strategy for the whole day today and developed a Short version using the same concept. The result were very good too (PF > 3, etc).

From the back-testing data, the Long and Short together has PF over 2 and steady rising performance too. From the calculation, I would make over \$7000 for the 2 months on 1 contract alone.

Feeling pretty confident, I felt the system was somewhat complete, so I tested it using the lastest 30 days of data. Unfortunately, it failed miserably. PF was way under 1.0 and the gross profit were a mere couple of thousand dollars. The net profit were estimated to be just a few hundred dollars.

So I tested the system on another set of data. August 2007. The result was even worse!

Long story short, I found out that ADX isn't that reliable to confirm with major swings.

Using new MA algorithm to rewrite old indicators

Seeing that many indicators use a MA for calculation. It may be possible to use new MA algorithm to improve on their calculation.

For example, the RS in RSI is something like RS = EMA(up days) / EMA(down days). We could change it to RS = HMA(up days) / HMA(down days). Since HMA is much faster, the resulting H-RSI may be faster too. This can be useful in day trading strategies.

More work needs to be done to test this idea.

continue   →