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

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
How to do calculations in #define, so that this #define can then be used as a constant?
lots of errors
That's a strange code. Have you compared performance with this solution?
Forum on trading, automated trading systems and testing trading strategies
Features of the mql5 language, subtleties and tricks
fxsaber, 2024.04.16 14:08
I wrote a custom TimeToSruct, it is not faster than the original.Ok good we have multiple options to decode timestamps.
How do you do calculations in #define so that this #define can then be used as a constant?
lots of errors
The task is to first perform the calculations (which are now inside #define), and only after the calculations write the value to the constant via #define. Is this possible?
Ok good we have multiple options to decode timestamps.
Where can we find <mql5_lib\base.mqh> ?
help me to read these tables from csv.
2017-03-06,-5.1,-0.68
WRONG PARAMETR DATATATIME error like this
struct prices
{
datetime opentime; // date
double Bid; // bid price
double Ask; // ask price
};
prices arrs[];
void OnTick()
{
int h=FileOpen(name,FILE_READ|FILE_ANSI|FILE_COMMON);
if(h!=INVALID_HANDLE)
{
//--- read all data from the file into the array
FileReadArray(file_handle,arrs);
//--- get the array size
int size=ArraySize(arrs);
//--- print the data from the array
for(int i=0;i<size;i++)
Print("Date = ",arrs[i].opentime," Bid = ",arrs[i].Bid," Ask = ",arrs[i].Ask );
Print("Total data = ",size);
//--- close file
FileClose(file_handle);
}
else
Print("File open failed, error ",GetLastError());
can anyone tell me where the error is
Modified just now by rahuA faster TimeToStruct() function to decode time-of-day variables to get all date and time components.
Some parts of the code can be reused to retrieve components of interest individually.
Benchmark:
Results:
I thought that the variant you suggested was the fastest, but it turned out to be even faster:
I piled together different methods that have already appeared here.
It should be additionally reminded that it works correctly until 28 February 2100, because it does not take into account the Gregorian calendar, in which 2100 will not be a leap year.An additional advantage is that the function remembers in static variables the basic calculations and applies them if the day coincides with the day from the previous call to the function. In reality, such calls will be more than 90%. That's why the gain will be even greater than in this random test. But the test shows that this function is about three times faster than the standard one.
I've pieced together various methods that have appeared here before.
Added this one. x64.
It should be additionally reminded that it works correctly until 28 February 2100, because it does not take into account the Gregorian calendar, in which 2100 will not be a leap year.
You can remove this limitation by adding epochs.