Features of the mql5 language, subtleties and tricks - page 56

 
Andrey Khatimlianskii:

Have you measured the performance? I'm curious how much it will slow down the performance. Especially with custom indicators.

I have not measured it, but it should not be slower than in MT4.

Measurement
#define  AMOUNT 1 e7
void OnStart()
{  
  int handle = iMA(NULL, PERIOD_CURRENT, 1, 0, MODE_SMA, PRICE_CLOSE);
  const ulong StartTime = GetMicrosecondCount();
  
  for (int i = 0; i < AMOUNT; i++)
    handle = iMA(NULL, PERIOD_CURRENT, 1, 0, MODE_SMA, PRICE_CLOSE);

  Print((string)((GetMicrosecondCount() - StartTime) / AMOUNT) + " mcs per iMA");
  Print(handle);    
}


The result is

0.3383469 mcs per iMA


One third of a microsecond to verify. It means that a single run for every 10 million ticks will slow down by three seconds.

 
fxsaber:

Measurement

Strange that you didn't compare creating the handle + getting the value in the loop with your original version, that's the difference that's interesting.

 
Andrey Khatimlianskii:

It's strange that you didn't compare creating a handle + getting a value in a loop with your original version, that's the difference that's interesting.

Because the values are taken from the same handle. iMA with the same parameters always returns the same handle.

 
fxsaber:
In MQL5 it is quite acceptable to write it like this

I.e. "create" a handle on every tick. New indicator entities will not be created, the time will be wasted only on the comparison of the iMA input parameters with those indicators that were running on the previous ticks. In other words, it's the same as in MT4.

This is an interesting design.

Please check the speed of handle creation in OnInit with this approach.

 
Vitaly Muzichenko:

Please check the speed with Handle creation in OnInit, with this approach.

Forum on trading, automated trading systems and strategy testing

Peculiarities of mql5 language, subtleties and tricks

fxsaber, 2017.10.05 09:09

A single run for every 10 million ticks will slow down by three seconds.

This is compared to your option.

 

How can I replace standard OrderCalcProfit() and OrderCalcMargin() so that the functions are cross-platform? It seems, that it already was somewhere, but I can't find it here - maybe I was sleepy... But I must have woken up within an hour of searching :)

 
Artyom Trishkin:

How can I replace standard OrderCalcProfit() and OrderCalcMargin() functions so that they would be crossplatform? It seems, that it already was somewhere, but I can't find it here - maybe I was awake... But I must be awake after an hour of searching :)

https://www.mql5.com/ru/search#!keyword=myordercalcmargin&module=mql5_module_forum

MQL5.Community
MQL5.Community
  • www.mql5.com
Поиск выполняется с учетом морфологии и без учета регистра. Все буквы, независимо от того, как они введены, будут рассматриваться как строчные. По умолчанию наш поиск показывает страницы...
 
fxsaber:

https://www.mql5.com/ru/search#!keyword=myordercalcmargin&module=mql5_module_forum

:)

SymbolInfoMarginRate() is not in 4. The question was formulated as follows:

Forum on trading, automated trading systems and trading strategies testing

Peculiarities of mql5, tips and tricks

Artyom Trishkin, 2017.10.06 06:36

How can I replace standard OrderCalcProfit() and OrderCalcMargin() so that functions are cross-platform? It seems, that it already was somewhere, but I cannot find it here - can not sleep... But after an hour of searching I should have woke up :)

And there is nothing about OrderCalcProfit()
 

It's a gift, not a language opportunity.

struct MQLTICK : public MqlTick
{
  bool operator >( const MqlTick &Tick )
  {
    return(this.bid > Tick.bid);
  }

  bool operator <( const MqlTick &Tick )
  {
    return(this.ask < Tick.ask);
  }
};

void OnStart()
{  
  MQLTICK Ticks[];
  
  Print(CopyTicks(_Symbol, Ticks));
  
  Print(Ticks[0] < Ticks[1]);
}
 
fxsaber:

A gift, not a language opportunity

A gift in the form of an elusive runtime error

struct MqlTick1 : MqlTick {        };
struct MqlTick2 : MqlTick { int i; };
void Copyticks( MqlTick& []) {}
void OnStart()
{
        MqlTick1 ticks1[];
        MqlTick2 ticks2[];
        int i1 = ::CopyTicks( _Symbol, ticks1 ); //нормально ??????????????
                   Copyticks(          ticks1 ); //error: 'ticks1' - parameter conversion not allowed
        int i2 = ::CopyTicks( _Symbol, ticks2 ); //нормально ??????????????
        Print( "i2=", i2, ":", GetLastError()); //Результат: -1:4006
}

How is ::CopyTicks better than Copyticks ?

And why is the result always -1. Such errors (4006) should be reported at compile time