Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

TypeToBytes - MetaTrader 4 Library | MT4 EA Download - MetaTrader 4 Resources

author EAcpu | 4 reads | 0 comments |

This cross-platform library allows convenient byte operations using structures and standard data types.

 // MQL4&5 code

#propertystrict

#include #define print(A):: print ( #a + ”=" + ( string ) a); blank on startup ( blank )
{ 
MQTick tick;
  :: Symbol information check (:: symbol (), check);

MQTick clone tick = tick; // Struct operations if (_R(Tick) == CloneTick) // Structures can now be compared :: print ( "equal" ); // Get the desired type of result via shift print(_R(Tick)[( datetime ) 0 ]) // Check that the 'datetime' value in the MqlTick structure object is offset from zero - Tick.time

// Get the shift constant integer offset of the structure field = _OFFSET(Tick, bid); // Find the byte shift of the bid field in the MqlTick object. Print (Tick.bid) // Check the value of Tick.bid _W(check, offset, ( double ) 1.23456 ); // Write the (double) 1.23456 value at the found shift. PRINT(Tick.bid) // Make sure Tick.bid is now equal to 1.23456 PRINT(_R(Tick)[( DOUBLE ) OFFSET]) //Print the "double" value at the shift offset - which again is Tick.bid PRINT(_R(Tick).byte[ 8 ]) //Check the byte value of shift 8 in the MqlTick structure object PRINT(_R(Tick)[( Uchar ) 8 ]) // Same, but using different methods Print(CloneTick.bid) // Check the value of CloneTick.bid _W(clone flag, 0 , tick); // Write the value of the Tick structure object to CloneTick at zero offset Print(CloneTick.bid) // Make sure CloneTick.bid == Tick.bid

// Use standard types for operations color color = C'241,248,255' ;

  print (_R(color)[( uchar ) 1 ]) // Green component of color - 248 _W(color, 2 , ( uchar ) 230 ); // Write the (uchar) 230 value at shift 2.  Print (color) // Make sure the color is now C'241,248,230'

// Mixed types operate simultaneously if (_R(tick)!=color) // It is even possible to compare structures to standard types :: print ( "unequal" );

return ;
}


Attachment download

📎 TypeToBytes.mqh (11.92 KB)

📎 TypeToBytes_ExampleScript.mq4 (6.47 KB)

Source: MQL5 #16282

Verification code Refresh