CFDs are complex instruments and come with a high risk of losing money rapidly due to leverage. -- % of retail investor accounts lose money when trading CFDs with this provider. You should consider whether you understand how CFDs work and whether you can afford to take the high risk of losing your money.

Programming Languages for Algorithmic Trading Strategy R&D

Dear all,

A year ago, I started getting interested to automated forex trading because I realized that maybe this could be a way for me to avoid this psychological part of trading. After that, I learned how to make my own robots in MQL. Now I don’t know where to go from here. I have been reading some topics on this forum where some people say that MQL is not that good…and I can say that it has it’s own limits, but I don’t think it’s that bad.

In the following topic @integracore2 states that R is great and I can’t say it’s not because I never used it:

In the same topic @CavaliereVerde is saying that MQL is enough.

Both of these guys are great and I really respect them because I learned a lot from them, but I don’t know if I should continue with MQL only or start using some advanced stuff. So here are my questions:

  1. I am currently trading on higher time frames and I’m not sure if I need analysis on every tick, so I’m not sure if I need something more than MQL. Can someone please explain that part more in detail?
  2. If MQL is just the beginning, where should I go from here? Should I start using R or Python and why? Python is something which is widely used and I think it could be better for me to learn it, but please tell me if I’m wrong.
  3. If you are using R or Python, do you use it only for analysis or you build robots with them?
  4. If you use R or Python to build trading robots, how do you connect it to MT4?

In algo trading it is not the language or the platform that makes the difference.
The thing that makes the difference is the developing process.
An algo trader is more an optimizer than a coder.

  • management of the historical data
  • number and stability of the parameters
  • endurance of the trader

Having said that, after mql4-5 I would go with Python


And you are using Python or not? :slight_smile:

If YES, I assume you are using it for trading, not only the analysis?!

Actually I bought some really good courses on MT4 robot optimization, but I’m not sure if that’s enough.

BTW thanks for being here whenever I have some questions.


NO :smiley:

I am able to code strategies in mql4 , mql5 and Zorro’s C-lite .

Zorro could be the next step if metatrader isn’t enough for you.
Zorro has mt4 and mt5 bridge while with Python and R you have to program it.


I checked Zorro’s website and it looks interesting. Thanks!


For algorithmic trading, once you actually have the “brains” of the methodology - meaning the design of the systematic decision making process for your algorithm - I think you would find the question of which language to use to be a trivial one - for you will have needs and demands placed by your algorithm, and there will be a language best suited for your use.

Actually writing the code is the easy part once you have a profitable mechanical strategy. The question becomes - which environment is best for developing such mechanical strategies? Well… again, depends on your needs :slight_smile:

I personally use R/Python/C -> R for data analysis, Python for Data wrangling and other small data manipulation for which writing C code would be too cumbersome, and C for when I need to work with very large amounts of data - because sometimes waiting times for R/Python code to do something can be 100x slower than C -> So when I might need to wait a month+ for some code to finish running, I code it in C.

For you, I suggest R+MQL. Much of data analysis is so very pleasant and easy to do in R. When you suspect a certain method might prove profitable, you can quickly and crudely code it in MQL and check if it is viable.


If I have a 4500 line EA and I want to get serious with it, which direction should I go?

Z? Matlab? Python? R? C?


Hi @bendex :slightly_smiling_face:

Great question - 4500 lines in one script could indicate that you’d benefit from introducing more object-orientation into your code (which is supported by MQL).

The language you choose would really boil down to what kind of functionality your strategy uses and what specifically you mean by getting serious… :bulb:

If you could shed some more light on say e.g. the sort of things your EA does on each tick (without any detail about strategy specifics, that’s your IP that you should protect at all costs), I could speak more to this.

For example,

  1. does your EA rely heavily on indicators built-in to MQL?

  2. is it math heavy?

  3. does it consume a lot of data regularly (e.g. on each tick)?

…stuff like that, etc.

p.s. Think we should probably create another thread for this discussion, it’s excellent subject matter everyone could benefit from :slightly_smiling_face: I’ll do that shortly.


Could be a continuation of this… :wink:


Aha! Thanks for pointing that out @CavaliereVerde, forgot about that one :man_facepalming:

Merging now.


EDIT: oops looks like I didn’t reply to the right thing @integracore2

For sure! No excuses but I wrote most of it a long time ago before I was familiar enough to realize the potential.

Lots of non indicator related code, lots of arrays, multi signal including trend line or s/r detection, multi exit including mutli TSL methods, multi TF, multi market, multi order, OnTimer to offset some cpu usage but ontic as well to check spread, lots of logging including slippage tracking, messaging, error checking, displaying “heartbeat” of tics and timer on the chart, complex lot sizing when 5 orders of minlot are still too big (reduces the number of orders)… off the top of my head.

The Ontic function is very light, especially with “checkspread” turned off and the OnTimer fires only once every few minutes typically. I’d say it doesn’t really “consume” a lot (considering it’s multi everything) of but it does need to store a lot of things in arrays. It’s kind of math moderate, the trend-line detection is math heavy though.

not really.

I’ve pretty much read only Ernest P Chan’s take and was leaning towards MatLab. But I really appreciate any info!


Impressive answer! :slightly_smiling_face:

Great, let me work on a mindmap / class diagram that I think would prove useful to you and anyone else reading this too :+1:

Love contributions like this on the forum, thanks so much @bendex :clap:


I guess from a standpoint of mt4+TDS I’m imagining multi market testing, swap data, genetic optimizer that is very configurable or even script able, way more charts and graphs, built in detailed walk forwarding off the top of my head as things that would be nice.

1 Like