Terminal
MQL5
bool vector<TDst>::Assign(const vector<TSrc> &assign); bool matrix<TDst>::Assign(const matrix<TSrc> &assign);Example:
//--- copying matrices matrix b={}; matrix a=b; a.Assign(b); //--- copying an array to a matrix double arr[5][5]={{1,2},{3,4},{5,6}}; Print("array arr"); ArrayPrint(arr); b.Assign(arr); Print("matrix b \n",b); /* array arr [,0] [,1] [,2] [,3] [,4] [0,] 1.00000 2.00000 0.00000 0.00000 0.00000 [1,] 3.00000 4.00000 0.00000 0.00000 0.00000 [2,] 5.00000 6.00000 0.00000 0.00000 0.00000 [3,] 0.00000 0.00000 0.00000 0.00000 0.00000 [4,] 0.00000 0.00000 0.00000 0.00000 0.00000 matrix b [[1,2,0,0,0] [3,4,0,0,0] [5,6,0,0,0] [0,0,0,0,0] [0,0,0,0,0]] */
bool matrix::CopyRates(string symbol,ENUM_TIMEFRAMES period,ulong rates_mask,ulong from,ulong count); bool vector::CopyRates(string symbol,ENUM_TIMEFRAMES period,ulong rates_mask,ulong from,ulong count);The copied data type is specified in the rates_mask parameter using the ENUM_COPY_RATES enumeration. The following values are available:
Fixed error when changing a constant parameter which has been passed to a function as an object pointer reference.
The const specifier declares a variable as a constant to prevent it from being changed during program execution. It only allows one-time variable initialization during declaration. An example of constant variables in the OnCalculate function:
int OnCalculate (const int rates_total, // price[] array size const int prev_calculated, // bars processed on previous call const int begin, // meaningful data starts at const double& price[] // array for calculation );
The below example contains a compiler error which allowed an implicit pointer casting for reference parameters:
class A {}; const A *a = new A; void foo( const A*& b ) { b = a; } void OnStart() { A *b; foo(b); // not allowed Print( a,":",b ); }The compiler will detect such illegal operations and will return the relevant error.
MetaEditor
New MetaTrader 5 Web Terminal
We
have released a revised MetaTrader 5 Web Terminal which features an
updated interface and a redesigned core. The new interface is similar to
the terminal version for iPad:
It also features a plethora of new functions:
Try the new web terminal at www.mql5.com right now. It will soon become available for your brokers.
Terminal
MQL5
//--- matrix a= {{1, 4}, {9, 16}}; Print("matrix a=\n",a); a=MathSqrt(a); Print("MatrSqrt(a)=\n",a); /* matrix a= [[1,4] [9,16]] MatrSqrt(a)= [[1,2] [3,4]] */For MathMod and MathPow, the second element can be either a scalar or a matrix/vector of the appropriate size.
//+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- Use the initializing function to populate the vector vector r(10, ArrayRandom); // Array of random numbers from 0 to 1 //--- Calculate the average value double avr=r.Mean(); // Array mean value vector d=r-avr; // Calculate an array of deviations from the mean Print("avr(r)=", avr); Print("r=", r); Print("d=", d); vector s2=MathPow(d, 2); // Array of squared deviations double sum=s2.Sum(); // Sum of squared deviations //--- Calculate standard deviation in two ways double std=MathSqrt(sum/r.Size()); Print(" std(r)=", std); Print("r.Std()=", r.Std()); } /* avr(r)=0.5300302133243813 r=[0.8346201971495713,0.8031556138798182,0.6696676534318063,0.05386516922513505,0.5491195410016175,0.8224433118686484,... d=[0.30458998382519,0.2731254005554369,0.1396374401074251,-0.4761650440992462,0.01908932767723626,0.2924130985442671, ... std(r)=0.2838269732183663 r.Std()=0.2838269732183663 */ //+------------------------------------------------------------------+ //| Fills the vector with random values | //+------------------------------------------------------------------+ void ArrayRandom(vector& v) { for(ulong i=0; i<v.Size(); i++) v[i]=double(MathRand())/32767.; }
Improved mathematical functions for operations with the float
type. The newly implemented possibility to apply mathematical functions
to 'float' matrix and vectors has enabled an improvement in
mathematical functions applied to 'float' scalars. Previously, these
function parameters were unconditionally cast to the 'double' type, then
the corresponding implementation of the mathematical function was
called, and the result was cast back to the 'float' type. Now the
operations are implemented without extra type casting.
The following example shows the difference in the mathematical sine calculations:
//+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- Array of random numbers from 0 to 1 vector d(10, ArrayRandom); for(ulong i=0; i<d.Size(); i++) { double delta=MathSin(d[i])-MathSin((float)d[i]); Print(i,". delta=",delta); } } /* 0. delta=5.198186103783087e-09 1. delta=8.927621308885136e-09 2. delta=2.131878673594656e-09 3. delta=1.0228555918923021e-09 4. delta=2.0585739779477308e-09 5. delta=-4.199390279957527e-09 6. delta=-1.3221741035351897e-08 7. delta=-1.742922250969059e-09 8. delta=-8.770715820283215e-10 9. delta=-1.2543186267421902e-08 */ //+------------------------------------------------------------------+ //| Fills the vector with random values | //+------------------------------------------------------------------+ void ArrayRandom(vector& v) { for(ulong i=0; i<v.Size(); i++) v[i]=double(MathRand())/32767.; }
The neural network activation function determines how the weighted input signal sum is converted into a node output signal at the network level. The selection of the activation function has a big impact on the neural network performance. Different parts of the model can use different activation functions. In addition to all known functions, MQL5 also offers derivatives. Derivative functions enable fast calculation of adjustments based on the error received in learning.
AF_ELU Exponential Linear Unit AF_EXP Exponential AF_GELU Gaussian Error Linear Unit AF_HARD_SIGMOID Hard Sigmoid AF_LINEAR Linear AF_LRELU Leaky REctified Linear Unit AF_RELU REctified Linear Unit AF_SELU Scaled Exponential Linear Unit AF_SIGMOID Sigmoid AF_SOFTMAX Softmax AF_SOFTPLUS Softplus AF_SOFTSIGN Softsign AF_SWISH Swish AF_TANH Hyperbolic Tangent AF_TRELU Thresholded REctified Linear Unit
The loss function evaluates the quality of model predictions. The model construction targets the minimization of the function value at each stage. The approach depends on the specific dataset. Also, the loss function can depend on weight and offset. The loss function is one-dimensional and is not a vector since it provides a general evaluation of the neural network.
LOSS_MSE Mean Squared Error LOSS_MAE Mean Absolute Error LOSS_CCE Categorical Crossentropy LOSS_BCE Binary Crossentropy LOSS_MAPE Mean Absolute Percentage Error LOSS_MSLE Mean Squared Logarithmic Error LOSS_KLD Kullback-Leibler Divergence LOSS_COSINE Cosine similarity/proximity LOSS_POISSON Poisson LOSS_HINGE Hinge LOSS_SQ_HINGE Squared Hinge LOSS_CAT_HINGE Categorical Hinge LOSS_LOG_COSH Logarithm of the Hyperbolic Cosine LOSS_HUBER Huber
int cl_ctx; //--- Initializing the OpenCL context if((cl_ctx=CLContextCreate(CL_USE_GPU_DOUBLE_ONLY))==INVALID_HANDLE) { Print("OpenCL not found"); return; }
CalendarValueLast(change, result, "", "EUR")
MetaEditor
'levels.bmp' as 'uint levels[18990]'
Terminal
MQL5
MetaTester
MetaEditor
Fixed errors reported in crash logs.
Terminal
MQL5
double vector.RegressionError(const enum lr_error); double matrix.RegressionError(const enum lr_error); vector matrix.RegressionError(const enum lr_error,const int axis);The following variables can be used as metrics:
enum REGRESSION_ERROR { REGRESSION_MAE, // Mean absolute error REGRESSION_MSE, // Mean square error REGRESSION_RMSE, // Root mean square error REGRESSION_R2, // R squared REGRESSION_MAPE, // Mean absolute percentage error REGRESSION_MSPE, // Mean square percentage error REGRESSION_RMSLE // Root mean square logarithmic error };
MetaEditor
Tester
Fixed errors reported in crash logs.
Terminal
Terminal
Terminal
MQL5
void OnStart() { int arr[4][5]= { {22, 34, 11, 20, 1}, {10, 36, 2, 12, 5}, {33, 37, 25, 13, 4}, {14, 9, 26, 21, 59} }; ulong indexes[4][5]; //--- Sort the array arr.ArgSort(indexes,-1,0); Print("indexes"); ArrayPrint(indexes); } // Result log: // indexes // [,0][,1][,2][,3][,4] // [0,] 4 2 3 0 1 // [1,] 2 4 0 3 1 // [2,] 4 3 2 0 1 // [3,] 1 0 3 2 4
void OnStart() { string test="some string"; PrintFormat("String length is %d",test.Length()); } // Result log: // String length is 11
MQL5
double matrix::Flat(ulong index) const; // getter void matrix::Flat(ulong index,double value); // setter
Pseudocode for calculating the address of a matrix element:
ulong row=index / mat.Cols(); ulong col=index % mat.Cols(); mat[row,col]
For example, for 'matrix mat(3,3)', access to elements can be written as follows:
Tester
Terminal
Terminal
MQL5
VPS
MetaEditor
Tester
>
struct POINT { int x,y; }; int GetYFunc(y) { return(y * y); } void SomeFunction(int x1,int x2,int y) { POINT pt={ x1+x2, GetYFunc(y) }; ProcessPoint(pt); };
struct complex { double real; // Real part double imag; // Imaginary part };The "complex" type can be passed by value as a parameter for MQL5 functions (in contrast to ordinary structures, which are only passed by reference). For functions imported from DLLs, the "complex" type must be passed only by reference.
complex square(complex c) { return(c*c); } void OnStart() { Print(square(1+2i)); // A constant is passed as a parameter } // "(-3,4)" will be output, which is a string representation of the complex numberOnly simple operations are currently available for complex numbers: =, +, -, *, /, +=, -=, *=, /=, ==,!=.
select count(*) as book_count, cast(avg(parent) as integer) as mean, cast(median(parent) as integer) as median, mode(parent) as mode, percentile_90(parent) as p90, percentile_95(parent) as p95, percentile_99(parent) as p99 from moz_bookmarks;
Documentation has been updated.
void func(int &arr[ ][ ][ ][ ]) { }
struct MyStruct { string Array[]; }; void OnStart() { MyStruct a1,a2; ArrayResize(a1.Array,3); ArrayResize(a2.Array,1); a1=a2; }Earlier, the "a1" array size was equal to 3 after the function call. Now, the size will be 1.