A little surprised :) Thought I'd share and ask a NOT rhetorical question. - page 23

 
Urain:

Are you going to divide one (not necessarily a multiple of 2) by another (not necessarily a multiple of 2) by a bit shift?

Ok, I'll throw in what I've got, and then you can decide for yourself whether you need it or not.

Joseph Stein (1961):

gcd(n,0) = gcd(0, n) = n

gcd(n,n) = n

gcd(2n,2m) = 2gcd(n, m)

gcd(2n,2m + 1) = gcd(n, 2m + 1)

gcd(2n + 1, 2m) = gcd(2n + 1, m)

gcd(2n + 1, 2(n + k) + 1) = gcd(2(n + k) + 1, 2n + 1) = gcd(2n + 1, k)

--

Two lectures by STL creator Alexander Stepanov on Yandex

// On the subject of calculating NOD - second lecture. But I suggest to see/listen to both of them. Cool lectures, clever man, just nice. Yes, and useful.
Files:
gcd_ru.zip  365 kb
 
MetaDriver:
If with bit shifts, go for it. If with modulo division, don't.

Dividing by successive offsets

interesting figures at the end of the article:

This algorithm will execute in the worst case in (n-1)! iterations, where n is the bit depth of the divisible. In summary, in comparison with the sequential addition algorithm, this algorithm produces a gain of up to 9 times for 8-bit numbers, and up to 546 times for 16-bit numbers.

 

So here's what I got:

long gcd(long m, long n) 
{
  if (m<0) m=-m; 
  if (n<0) n=-n;
  if (m==0) return n; 
  if (n==0) return m;
  int d = 0;
  while ((m & 1)==0 && (n & 1)==0) { m >>= 1; n >>= 1; ++d; }
  while ((m & 1)==0) m >>= 1;
  while ((n & 1)==0) n >>= 1;
  while (m!=n)   //  while (true)  // старый вариант 
    if (m < n) 
    {
      n -= m;
      do  n >>= 1;  while ((n & 1)==0);
    } 
    else       // if (n < m) это теперь без надобности
    {
      m -= n;
      do  m >>= 1;  while ((m & 1)==0);
    } 
//    else break;  // старый вариант
    return (m <<= d);
}

it seems to be working fine. please test all the holes.

// tweaked it, it's nicer this way.
Files:
gcd.zip  1 kb
 

That's weird, it's not very fast.

2011.04.03 22:56:59 gcdSpeedTest (EURUSD,M20) Common time GreatestCommonDivisor(random(),random()) = 7656ms; // 10000000 calls
2011.04.03 22:56:51 gcdSpeedTest (EURUSD,M20) Common time gcd(random(),random()) = 5234ms; // 10000000 calls

Files:
gcd.zip  2 kb
 
MetaDriver:

That's weird, it's not that much faster.

2011.04.03 22:56:59 gcdSpeedTest (EURUSD,M20) Common time GreatestCommonDivisor(random(),random()) = 7656ms; // 10000000 calls
2011.04.03 22:56:51 gcdSpeedTest (EURUSD,M20) Common time gcd(random(),random()) = 5234ms; // 10000000 calls

I have a bigger difference. Yours is 3-4 times faster, but don't forget that in C++ the difference is reduced by a factor of 2-2.5, so you are honestly 1.5 times faster.

void OnStart()
  {
//---
   int total=1000000;
   long x=2*3*5*7*9*11*13*17*19*21*23*29;
   long m=55*x,n=34*x;
   uint start=GetTickCount();
   for(int i=0;i<total;i++)x=gcd(m,n);      
   Print("MetaDriver gcd time=",GetTickCount()-start," x=",x);
   start=GetTickCount();
   for(int i=0;i<total;i++)x=GreatestCommonDivisor(m,n); 
   Print("Urain       GCD time=",GetTickCount()-start," x=",x);
  }
2011.04.03 22:35:41     Черновик 30 (EURUSD,M1) Urain       GCD time=1313 x=1222772020470
2011.04.03 22:35:40     Черновик 30 (EURUSD,M1) MetaDriver  gcd time= 312 x=1222772020470
 
Urain:

I have a bigger difference. Yours is 3-4 times faster,

but don't forget that in C++ the difference is reduced by 2-2.5 times, so you're honestly ahead by 1.5 times.


And we'll see.

So far we have a preliminary version in mql5. Friendly testing, looking for bugs.

I have made it as a structure.

struct Rational
  {
   long              n;
   long              m;
   void ErrDZ() { Print("Rational error: zero-denominator!"); }
   void Neg() { n=-n; }
   void Norm() { long d=gcd(n,m); n/=d; m/=d; if (m<0) { n=-n; m=-m; } }
   void Assign(long a,long b) { if (b==0) { n=0; m=1; ErrDZ(); } if (b<0) { n=-a; m=-b; } else { n=a; m=b; } }
   void nAssign(long a,long b) { Assign(a,b); Norm(); }
   void Assign(long a) { Assign(a,1); }  // {n=a;m=1;}
   void Add(Rational &a) { if(m==a.m) n+=a.n; else { n*=a.m; n+=m*a.n; m*=a.m; } }
   void nAdd(Rational &a) { Add(a); Norm(); }
   void Add(long a) { n+=a*m; }
   void nAdd(long a) { Add(a); Norm(); }
   void Sub(Rational &a) { if(m==a.m) n-=a.n; else { n*=a.m; n-=m*a.n; m*=a.m; } }
   void nSub(Rational &a) { Sub(a); Norm(); }
   void Sub(long a) { n-=a*m; }
   void nSub(long a) { Sub(a); Norm(); }
   void Mul(Rational &a) { n*=a.n; m*=a.m; }
   void nMul(Rational &a) { Mul(a); Norm(); }
   void Mul(long a) { n*=a; }
   void nMul(long a) { Mul(a); Norm(); }
   void Div(Rational &a) { n*=a.m; m*=a.n; }
   void nDiv(Rational &a) { Div(a); Norm(); }
   void Div(long a) { m*=a; }
   void nDiv(long a) { Div(a); Norm(); }
   string ToString() {return "("+IntegerToString(n)+"/"+IntegerToString(m)+")";}
  };

I have made all operations in two forms - with and without normalization. I have obtained a flexible structure.

If you suspect the possibility of overflow - you use a version with normalization, without fear - you save time (normalization can be done later, when the foam has accumulated).

There is a simple test in archive, but it is desirable to test harder.

Files:
 
IgorM:

thanks at least admit it - you cut emoticons, but who removes whole posts?

About that, Academic, I think it's great that you have a so-called "calculator", but i would like to clarify if you can automatically optimise it in the course of trading?

Yes, it's just a programme, if you run it, it will work and give you the optimum parameters.
 
A check on the EMA would be a good idea.
 

Especially for this thread I published the latest MT5 tester results (anyone will be able to repeat the tests after the next update).

This is what the MetaTrader 5 tester can do, and even more so with a full infrastructure layout (reports, charts, results, visualisation).

 
Renat:

Especially for this thread I published the latest results of MT5 tester (anyone will be able to repeat the tests after the next update).

That's what the MetaTrader 5 tester can do, and even with a full layout (reports, charts, results, visualization).

7 symbols, all ticks, since 2000, two parameters ( variants 200 * 200 )- 40000 passes, with a hundred orders per day for each symbol.

How long does it take?

take 10 years - 356 * 10 * 100 * 7 = 25 000 000 deals

we take approximately 10 ticks per minute

and 10 years - 365 * 10 * 1440 * 10 = 52 000 000 ticks on one symbol. And if we're being honest, they are ticking on every symbol. So, we should honestly multiply by 7. And it is not 10 ticks per minute. And sometimes it's 300.


How long does it take?