Simultaneous calculations in MQL4 code. How to solve?

 
Hi,

I am developing an ATS that would require simultaneous calculations ( 1000-10000 simple to moderate mathematical operations per tick). I have no programmatic knowledge for now and i am worry this simultaneous issue might provide a source of instability in the code and delay the execution.

However, i am working with a professional MQL4 programmer but later i am going to migrate to higher language.

Any suggestions is highly appreciated.

Thanks

McGene
 

I don't know your algorithm, but I doubt that you need to do all that work for each tick. Usually (and I'm making presumptions here) it's just on bar higher highs (& vv) that you need to do calcs.

A) So, when computation is 'expensive' I sometimes try

bool doCalcs = false;
static double HBar;
if(IsANewBar())
{
  HBar = -1.0;
}
if(High[ix] > HBar)
{
  HBar = High[ix];
  doCalcs = true;
}
if(docalcs)
{
  // do heaps of stuff
}

(just typed, not compiled or checked .. and just High part done)

B) At first tick of bar, work out (by back-calculation) what High (& Low) is needed to exceed to trigger Order action, then just check for H (& L) exceeding that

 
brewmanz:
A) So, when computation is 'expensive' I sometimes try

//+------------------------------------------------------------------+
//| Skip useless ticks                                               |
//+------------------------------------------------------------------+
double  CA.below,   CA.above=0;         // Export to start
void    CallAgain(double when){
    if (when>=Bid && CA.above > when) CA.above = when;
    if (when<=Bid && CA.below < when) CA.below = when;
    return;
}
int     start(){
    static datetime Time0;                              #define INF 0x7FFFFFFF
    if (Time0 != Time[0] || Bid < CA.below || Bid > CA.above){  // Important
        CA.below = 0;   CA.above = INF;     Time0 = Time[0];
        ...

    double  delta = (Bid-pattern.trigger)*DIR;                  // Want to open
    if (delta <= 0                                              // Still below.
    ||  delta > 0.5*atr){                                       // Gapped above.
        oo.OP = pattern.trigger;                                // Show line
        CallAgain(oo.OP);   return; }
 
brewmanz:

I don't know your algorithm, but I doubt that you need to do all that work for each tick. Usually (and I'm making presumptions here) it's just on bar higher highs (& vv) that you need to do calcs.

A) So, when computation is 'expensive' I sometimes try

(just typed, not compiled or checked .. and just High part done)

B) At first tick of bar, work out (by back-calculation) what High (& Low) is needed to exceed to trigger Order action, then just check for H (& L) exceeding that


Thank you for your post and info. I will share your post with my programmer and i hope this will be helpful for him to do it.

Thanks very much. and i will update him about what he has thought.

McGene

 
McGene4xPro:
Hi,

I am developing an ATS that would require simultaneous calculations ( 1000-10000 simple to moderate mathematical operations per tick). I have no programmatic knowledge for now and i am worry this simultaneous issue might provide a source of instability in the code and delay the execution.

However, i am working with a professional MQL4 programmer but later i am going to migrate to higher language.

Any suggestions is highly appreciated.

Thanks

McGene
I have never performed any quantitative algorithm analysis on my code but Im pretty certain that Ive got at least 1000 operation going each tik.. backtesting is a bit slower than simpler EA but by no means impractical. As brewmanz said, most of the time theres no need to perform operations at each & every tik, but dont hesitate to enact the algorithm you want just to save your CPU some work. If you can optimize your code all the better but its a better paradigm to go in with little to no regard for code optimization, then perhaps go back and optimize if you feel the need to improve performance.
 

I have no programming knowledge as i am an EA developer and trader. However, i worry that if i have thousands of math and quantitative operations are running on every tick, this might slow down the algo or disturb the execution system. This is my primary worry for now.. However, i know mql4 is not that strong language and i might migrate on time to higher " java or C++
", also, i am going on time to migrate to higher tech hardware using GPU. It might be the best solution for me on time.. I am still stick with mql4 till now and ready/open for suggestions.. Thanks all

 

A GPU will only affect graphics speed - not hard-core mathematical algorithm speed. And if your CPU utilisation does not even get close to 100% (well, 100% of one core), don't worry about code optimising.

I'm an old-timer from way back (writing IBM Mainframe Assembler in the 70's) and we would work out CPU cycles for each function. Nowadays, getting a faster computer is usually cheaper than people spending time improving code.

Having said that, some of my code has been CPU-intensive & some simple tricks (as stated above) can reduce CPU usage by a factor of 10 or more with little effort.

Another technique for, say, non-linear continuous algorithms is to calc the INITIAL value on new bar, then use SLOPE APPROXIMATION to calc values for each tick.

 

"Premature optimization is the root of all evil" -- Donald Knuth

In other words: Don't think about optimization now. Program your algorithm and make it work. Make it fulfill all specs and pass all tests. This has to have the highest priority until its working correctly as desired. THEN (after it is complete and working) you can start thinking about optimizing/rewriting individual parts of it (the parts that impact performance most) if needed at all.


Your programmer should know what he is doing. Just let him do his job. Don't complicate it unnecessarily and don't frustrate your programmer by trying to tell him how to write a program. He is called "programmer" because he should know all this already.

 

Thank you for all here

Really appreciate your posts and information