Get the number of decimal places of any numbers (not just quotes) bypassing Digits() in MQL4 and MQL5 - page 16

 

Here's another interesting task: to make an array sorting function faster than the built-in ArraySort.

 
Ilya Malev:
sizeof(S)/sizeof(T)

Is the size of all structures guaranteed to be divided by the size of all variables?

struct SZ{
   char x1;
   char x2;
   char x3;   
};

Print(sizeof(SZ)/sizeof(int)); // 0
 
fxsaber:

Can I brainstorm on a quick implementation of translating an array of structures (length multiple of sizeof(int)) to and from an int[] array?

///

Simply after describing a structure, write a few more lines with a union that includes this structure and an array.

struct SS{
   int a;
   double b;
};

union UX{
   SS s;
   char a[sizeof(S)];
};


It is even possible not to write after each structure, but to template it - whatever is convenient for you.

 
Dmitry Fedoseev:

Is the size of all structures guaranteed divided by the size of all variables?

Forum on Trading, Automated Trading Systems and Strategy Tests

Getting the number of decimal places of any numbers (not just quotes) bypassing Digits() in MQL4 and MQL5

fxsaber, 2018.12.07 15:12

Can I brainstorm on a quick implementation of translating an array of structures (length multiple of sizeof(int)) to and from int[] array?

In general the solution lies at the same link, but because of the versatility there is a brake there. So multiplicity is an understandable additional condition.

This also appeared.

Forum on trading, automated trading systems and strategy testing

New version of MetaTrader 5 build 1930: Floating Chart Window and .Net Library in MQL5

MetaQuotes Software Corp., 2018.10.25 17:18

  1. MQL5: The pack( integer_value ) property has been added for structures. It allows you to set the alignment of the fields within the structure, it may be necessary when working with DLL. For integer_value may have values 1, 2, 4, 8 and 16.
    If the property is not defined, the default alignment is 1 byte - pack(1).

    Example usage:
    //+------------------------------------------------------------------+
    //| Default packing                                                  |
    //+------------------------------------------------------------------+
    struct A
      {
       char              a;
       int               b;
      };
    //+------------------------------------------------------------------+
    //| Specified packing                                                |
    //+------------------------------------------------------------------+
    struct B pack(4)
      {
       char              a;
       int               b;
      };
    //+------------------------------------------------------------------+
    //| Script program start function                                    |
    //+------------------------------------------------------------------+
    void OnStart()
      {
       Print("sizeof(A)=",sizeof(A));
       Print("sizeof(B)=",sizeof(B));
      }
    //+------------------------------------------------------------------+
    Output:
    sizeof(A)=5
    sizeof(B)=8
    More information about alignment in structures is available on MSDN.
 
Dmitry Fedoseev:

Simply, after describing the structure, write a few more lines with a union that includes this structure and the array.

You can even not write after each structure, but template it - whatever is more convenient.

I don't get it. If you want to participate, please write your variant.

 
fxsaber:

Can I brainstorm on a quick implementation of translating an array of structures (length multiple of sizeof(int)) to and from int[] array?

why to int? and not to char?

(and it will be longer - it will be copied faster)

 
Ilya Malev:

Apparently yours is already faster :)

// Перевод массива тиков в массив int[].
int TicksToIntArray_fxsaber3( const MqlTick &Ticks[], int &Array[] )
{
  INTEGER<MqlTick> TickInteger;

  const int Size = ArraySize(Ticks);
  ArrayResize(Array, Size * sizeof(MqlTick) / sizeof(int));
  
  int j = 0;

  for (int i = 0; i < Size; i++)
  {
    TickInteger.Data = Ticks[i];

//    j += ArrayCopy(Array, TickInteger.Integer, j);
    for (int k = 0; k < sizeof(MqlTick) / sizeof(int); k++)
      Array[j++] = TickInteger.Integer[k];
  }

  return(j);
}

// Перевод массива int[] в массив тиков.
int IntArrayToTicks_fxsaber3( const int &Array[], MqlTick &Ticks[] )
{
  INTEGER<MqlTick> TickInteger = {0};

  const int Size = ArraySize(Array);
  ArrayResize(Ticks, Size * sizeof(int) / sizeof(MqlTick));
  
  int j = 0;

  for (int i = 0; i < Size; j++)
  {
//    i += ArrayCopy(TickInteger.Integer, Array, 0, i, sizeof(MqlTick) / sizeof(int));
    for (int k = 0; k < sizeof(MqlTick) / sizeof(int); k++)
      TickInteger.Integer[k] = Array[i++];

    Ticks[j] = TickInteger.Data;
  }

  return(j);
}


I'll try to speed it up considerably.

 
fxsaber:

I don't get it. If you would like to participate, please write your option.

I did.

 
fxsaber:

In the general case the solution is in the same link, but because of the universality there are brakes. Therefore the multiplicity is an understandable additional condition.

This also appears.

Who will control this multiplicity?

Reason: