C# expert advisors, don't waste your time

 

I've spent a lot of time looking around at different options for writing expert advisors in C# and I can tell you with certainty that all of the available solutions are terrible. Wasting your time attempting to write expert advisors in any language besides MQL is a terrible idea. I know, you want to use a modern programming language that lets you do routine things without rewriting common algorithms that were pretty well thought out over a decade ago, well too bad. You're stuck using this domain specific language, with all it's limitations and bugs, and the only solutions out there are basically wrappers that pass information back to MQL functions anyway. Skip the whole mess of debugging the language you choose, the wrapper layer, and then the MQL layer, just to get Linq, third party libraries that work, garbage collection, expert systems, etc. oh... and Try {} Catch {}, you don't need any of that.

Basically, there are two flavors of wrapper out there in any sort of useful state:

1. Create a server wrapping every MQL function in an expert advisor, script, or indicator, then have the C# expert advisor post messages that the MQL code reads and executes in a loop.

2. Create an unmanaged dll exporting every MQL function, call those unmanaged functions in managed code and deal with marshaling, disposing, and basically managing the unmanaged code... but hey, you're still going to need an expert advisor, script, or indicator that loads the unmanaged dll and initiates the whole process so... basically messages and loops that end up in MQL again.

You just can't escape the DSL here, so stop trying. There is no client API, no UI plugin system, no UI extension system. You can just create unmanaged C++ dll and consume them in your MQL expert advisors. Don't cry, that's just how it is, and the deeper you look the more you can see that it is completely intentional. You will write code, and you will be locked into this platform, end of story.

If you want a trading platform that allows you to code in C# and trade with reputable brokers, just google it. If you love Metatrader, learn it's language.

 
Beside using existing libraries "that were pretty well thought out over a decade ago", which of course would be very useful, may I ask what you will have more with C# than with mql ? I am interested by actual useful information and not at all by an "opinion war" about the "best" coding language.


Thanks sharing your experience.

 
Alain Verleyen:
Beside using existing libraries "that were pretty well thought out over a decade ago", which of course would be very useful, may I ask what you will have more with C# than with mql ? I am interested by actual useful information and not at all by an "opinion war" about the "best" coding language.


Thanks sharing your experience.

I believe it is speed and the direct communication with the server.

<off-topic message removed>.

 
GBWT094114:

I believe it is speed and the direct communication with the server.

Forum on trading, automated trading systems and testing trading strategies

C# expert advisors, don't waste your time

Alain Verleyen, 2016.11.27 15:10

Beside using existing libraries "that were pretty well thought out over a decade ago", which of course would be very useful, may I ask what you will have more with C# than with mql ? I am interested by actual useful information and not at all by an "opinion war" about the "best" coding language.


Thanks sharing your experience.

Do you have useful information ? If not please stay away.
 
Garbage collection,  error handling,  memory management, synchronous or async programming,  events,  delegates,  lambdas,  specialized libraries for math,  charting,  and anything else you might want in order to view data in any way you want,  and... integrating with other systems without hacks and wrapper code. Basically,  you could focus on the strategy and how best to implement it,  instead of reinventing boilerplate code like "map reduce" or doing error handling by checking a global variable for an error code.  handling errors that way means you can't reliably do any kind of async  code because who knows which thread changed the global "last error"  you know?

Imagine being able to fill all 8  indicator buffers in parallel for your custom indicator, with a tested threading model that seems to be  stable enough for enterprise grade software.

I mean,  even nodejs  can do things fast enough. I'm just lost trying to figure out why  metatrader doesn't just expose a standard client api  that we could consume in whatever programming language we wanted. Instead,  they're reinventing object oriented programming on top of the functional language they made up,  which is the same thing PHP did.  Nobody likes PHP,  they just deal with it because it's everywhere, which is again similar to what I hear about mql.
 
Matthew Colter:
Garbage collection,  error handling,  memory management, synchronous or async programming,  events,  delegates,  lambdas,  specialized libraries for math,  charting,  and anything else you might want in order to view data in any way you want,  and... integrating with other systems without hacks and wrapper code. Basically,  you could focus on the strategy and how best to implement it,  instead of reinventing boilerplate code like "map reduce" or doing error handling by checking a global variable for an error code.  handling errors that way means you can't reliably do any kind of async  code because who knows which thread changed the global "last error"  you know?

Imagine being able to fill all 8  indicator buffers in parallel for your custom indicator, with a tested threading model that seems to be  stable enough for enterprise grade software.

I mean,  even nodejs  can do things fast enough. I'm just lost trying to figure out why  metatrader doesn't just expose a standard client api  that we could consume in whatever programming language we wanted. Instead,  they're reinventing object oriented programming on top of the functional language they made up,  which is the same thing PHP did.  Nobody likes PHP,  they just deal with it because it's everywhere, which is again similar to what I hear about mql.
And all this is related to Real Time System Instruction cycle response.
 
Matthew Colter:
Garbage collection,  error handling,  memory management, synchronous or async programming,  events,  delegates,  lambdas,  specialized libraries for math,  charting,  and anything else you might want in order to view data in any way you want,  and... integrating with other systems without hacks and wrapper code. Basically,  you could focus on the strategy and how best to implement it,  instead of reinventing boilerplate code like "map reduce" or doing error handling by checking a global variable for an error code.  handling errors that way means you can't reliably do any kind of async  code because who knows which thread changed the global "last error"  you know?

Imagine being able to fill all 8  indicator buffers in parallel for your custom indicator, with a tested threading model that seems to be  stable enough for enterprise grade software.

I mean,  even nodejs  can do things fast enough. I'm just lost trying to figure out why  metatrader doesn't just expose a standard client api  that we could consume in whatever programming language we wanted. Instead,  they're reinventing object oriented programming on top of the functional language they made up,  which is the same thing PHP did.  Nobody likes PHP,  they just deal with it because it's everywhere, which is again similar to what I hear about mql.

Of course there could be improvements to mql (see above). But all what you say is existing in CTrader right, why you are trying to use MT4/MT5 and "waste your time using C# with them " ? Why are most brokers using MT4/MT5 and not CTrader and it's C# ? There is a lot of things I don't understand or want to be improved in MT4/MT5 but it's Metaquotes software, it's their business and their decision, and as far as I can see they are still very successful. So it's always stunning me to see people asking "why I don't have this feature or this one with mql (or MTx)". Do you understand the implications for a company to develop a language supporting all these features, to embed it in their platform, to support it...? While most people already complaint about mql5 complexity in face of mql4 ?

  • Garbage collection is useless in a managed environment like MT platforms (the platform is the garbage collector).
  • Error handling : I do agree there could be at least more possibilities that the limited "GetLasterrror".
  • Memory Management : Not sure what you mean exactly ? But in all cases it seems to me a trading platform could only have minimum memory management as security is an issue.
  • Asynchronous : agree. But we can live without it. We already have asynchronous trading orders, and that's the main thig in a trading platform.
  • Events : already there. In MQ way of course.
  • Delegate, lambdas : really ?
  • Specialized libraries for math. There is already a lot.
  • Charting :  What do you mean exactly ?

Why would Metatrader expose a standard client API ? What would be their advantage ? They are monopolizing te market, why would they open their platform ? If you have convincing arguments, just contact Metaquotes, they will certainly be grateful to implement something which can profit their business.

If I learned something from live it's how it's useless to complain about things you don't have any control on.

 
Alain Verleyen:

Why would Metatrader expose a standard client API ? What would be their advantage ? They are monopolizing te market, why would they open their platform ? If you have convincing arguments, just contact Metaquotes, they will certainly be grateful to implement something which can profit their business.

If I learned something from live it's how it's useless to complain about things you don't have any control on.

Very simple, They can always charge brokers 0.05% on the orders, and problem solved. If it is a financial matter in face of scientific progress, any creative person can come up with million of ideas to make money with open systems like Google. In addition to increase the popularity of the system with professional institutions and developers. Not only home made Algo Trading geeks.
 
Alain Verleyen:

Of course there could be improvements to mql (see above). But all what you say is existing in CTrader right, why you are trying to use MT4/MT5 and "waste your time using C# with them " ? Why are most brokers using MT4/MT5 and not CTrader and it's C# ? There is a lot of things I don't understand or want to be improved in MT4/MT5 but it's Metaquotes software, it's their business and their decision, and as far as I can see they are still very successful. So it's always stunning me to see people asking "why I don't have this feature or this one with mql (or MTx)". Do you understand the implications for a company to develop a language supporting all these features, to embed it in their platform, to support it...? While most people already complaint about mql5 complexity in face of mql4 ?

  • Garbage collection is useless in a managed environment like MT platforms (the platform is the garbage collector).
  • Error handling : I do agree there could be at least more possibilities that the limited "GetLasterrror".
  • Memory Management : Not sure what you mean exactly ? But in all cases it seems to me a trading platform could only have minimum memory management as security is an issue.
  • Asynchronous : agree. But we can live without it. We already have asynchronous trading orders, and that's the main thig in a trading platform.
  • Events : already there. In MQ way of course.
  • Delegate, lambdas : really ?
  • Specialized libraries for math. There is already a lot.
  • Charting :  What do you mean exactly ?

Why would Metatrader expose a standard client API ? What would be their advantage ? They are monopolizing te market, why would they open their platform ? If you have convincing arguments, just contact Metaquotes, they will certainly be grateful to implement something which can profit their business.

If I learned something from live it's how it's useless to complain about things you don't have any control on.

Lol, I know. That's why the title of the thread advises people to stop trying to use bridges and just code in mql. I already found an open source project that's gaining traction,  let's me code in C#,  let's me backtest  with multiple time frames and currencies simultaneously,  let's me store my projects in their cloud or run them privately, and let's me trade fx and equities through three well known and reputable brokers. Metaquotes can do what  they want to do, I like a lot of things they've done,  but I'm going to try writing software for this other platform because I believe it will be easier for me to create reliable programs that give the results I want.  I'll still use metatrader,  and probably still make scripts (macros)  for doing simple things,  just won't be trying to do technical analysis on it.
 
Matthew Colter:
Lol, I know. That's why the title of the thread advises people to stop trying to use bridges and just code in mql. I already found an open source project that's gaining traction,  let's me code in C#,  let's me backtest  with multiple time frames and currencies simultaneously,  let's me store my projects in their cloud or run them privately, and let's me trade fx and equities through three well known and reputable brokers. Metaquotes can do what  they want to do, I like a lot of things they've done,  but I'm going to try writing software for this other platform because I believe it will be easier for me to create reliable programs that give the results I want.  I'll still use metatrader,  and probably still make scripts (macros)  for doing simple things,  just won't be trying to do technical analysis on it.

Sure, do what is best for you.

But I can't agree if your conclusion is something about technical analysis cannot be done with mql. Maybe I am lacking of imagination.

 
Alain Verleyen:

Sure, do what is best for you.

But I can't agree if your conclusion is something about technical analysis cannot be done with mql. Maybe I am lacking of imagination.

I didn't say technical analysis can't be done from mql. People can create automated strategies using the given technical indicators, I've made quite a few myself. After  working with MQL for about two years I know exactly what I don't like about it,  and I've been actively monitoring what else is out there.  It just happens that a whole new platform emerged  that allows me to do the same technical analysis using C# and manage a whole portfolio from one "EA", all of this before MQL could  evolve and update to a point where I could just focus on  writing a strategy for a single currency pair without getting sidetracked with missing language features and unwanted side effects.

I just want to think about trading algos, I do enough DevOps and software QA at my day job. The strategy and analysis should be the difficult part,  not the platform I'm writing them on.