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

 
Botan626 #:

If you move lines 22 and 23 here

the script will start to terminate with an error

Not reproducible. Which build are you using ?
 
Alain Verleyen #:
Does not play. What build are you using?

Maybe you need to have several different indicators on the chart to reproduce the situation.

5833 build

 
Alain Verleyen #:
Does not play. What assembly are you using?

For example, if you add to the graph in this order, you will get this message.

2 leaked strings left
 
Botan626 #:

For example, if you add to the graph in this order, you will get this message.

Reproduced. Yes this is a MQL bug.
 
Botan626 #:

For example, if you add to the graph in this order, you will get this message.

Fixed from build 5867.
 
Based on this discussion, I did a quick calculation (performance is needed, as it is used in this project) of the position duration.
excluding weekends according to forex rules - Saturday/Sunday, Catholic Christmas/Good Friday and New Year.
#include <fxsaber\BestInterval\Holiday.mqh> // https://www.mql5.com/en/code/22710

datetime PositionOpenTime = OrderOpenTime();
datetime PositionCloseTime = OrderCloseTime();

int PositionLength = HOLIDAY::GetDealLength(PositionOpenTime, PositionCloseTime);
 
fxsaber #:
Based on this discussion, I did a quick calculation (performance is needed, as it is used in this project) of the position duration.
Optimized version using Prefix[] sum cache
/*
 Holiday2 (EURUSD,H1)   GetDealLength: 146056 microsec (sum = 5034828067200)
 Holiday2 (EURUSD,H1)   GetDealLength_Cached: 563 microsec (sum = 5035790304000)
*/
Files:
Holiday2.mq5  14 kb
 
amrali #:
Optimized version using Prefix[] sum cache

Some minor fixes.

Files:
Holiday3.mq5  16 kb
 
amrali #:

A few minor corrections.

Thank you, it doesn’t match yet.
void OnStart()
{
  const datetime OpenTime = D'2026.04.03 23:44:57';
  const datetime CloseTime = D'2026.04.06 01:07:17';    

  Print(HOLIDAY::GetDealLength(OpenTime, CloseTime)); // 4940
  Print(HOLIDAY::GetDealLength_Cached(OpenTime, CloseTime)); // -81460
}
 
fxsaber #:
Thank you, it doesn’t match yet.
Hello,
You cannot open a deal on Friday, 2026.04.03 because the market is closed (Good Friday before the Easter Sunday).