10 March 2023
10 March 2023
Terminal
MQL5
Compile the project and run it on EURUSD H1 to see the result.
In
addition to the model and the MQL5 code which runs it, the project also
includes the PricePredictionTraining.py Python script. It shows how you
can create an ONNX model yourself. To run the script, install Python on
your computer and the required modules from the prompt line:
#import "mmlib.dll" bool sgemm(uint flags,matrix<float> &C,const matrix<float> &A,const matrix<float> &B,ulong M,ulong N,ulong K,float alpha,float beta); #importC++
extern "C" __declspec(dllexport) bool sgemm(UINT flags,float *C,const float *A,const float *B,UINT64 M,UINT64 N,UINT64 K,float alpha,float beta)In addition to buffers, you should pass matrix and vector sizes for correct processing.
Added new CopySeries function for copying synchronized timeseries from MqlRates into separate arrays.
The CopySeries function allows obtaining only the necessary timeseries into different specified arrays during one call, while all of timeseries data will be synchronized. This means that all values in the resulting arrays at a certain index N will belong to the same bar on the specified Symbol/Timeframe pair. Therefore, there is no need for the programmer to additionally synchronize the received timeseries by the bar opening time.
Unlike CopyRates, which returns the full set of timeseries as an MqlRates array, the CopySeries function allows obtaining specific required timeseries into separate arrays. This can be done by specifying a combination of flags to select the type of timeseries. The order of the arrays passed to the function must match the order of the fields in the MqlRates structure:
struct MqlRates { datetime time; // period beginning time double open; // open price double high; // high price for the period double low; // low price for the period double close; // close price long tick_volume; // tick volume int spread; // spread long real_volume; // exchange volume }
Thus, if you need to get the values of the 'time', 'close' and 'real_volume' timeseries for the last 100 bars of the current Symbol/Timeframe, you should use the following call:
datetime time[]; double close[]; long volume[]; CopySeries(NULL,0,0,100,COPY_RATES_TIME|COPY_RATES_CLOSE|COPY_RATES_VOLUME_REAL,time,close,volume);
The order of the arrays "time, close, volume" must match the order of the fields in the MqlRates structure. The order of values in the rates_mask is ignored. The mask could be as follows:
COPY_RATES_VOLUME_REAL|COPY_RATES_TIME|COPY_RATES_CLOSE
Example
//--- input parameters input datetime InpDateFrom=D'2022.01.01 00:00:00'; input datetime InpDateTo =D'2023.01.01 00:00:00'; input uint InpCount =20; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart(void) { //--- arrays to get timeseries from the Rates structure double open[]; double close[]; float closef[]; datetime time1[], time2[]; //---request close prices to a double array ResetLastError(); int res1=CopySeries(NULL, PERIOD_CURRENT, 0, InpCount, COPY_RATES_TIME|COPY_RATES_CLOSE, time1, close); PrintFormat("1. CopySeries returns %d values. Error code=%d", res1, GetLastError()); ArrayPrint(close); //--- now also request open prices; use float array for close prices ResetLastError(); int res2=CopySeries(NULL, PERIOD_CURRENT, 0, InpCount, COPY_RATES_TIME|COPY_RATES_CLOSE|COPY_RATES_OPEN, time2, open, closef); PrintFormat("2. CopySeries returns %d values. Error code=%d", res2, GetLastError()); ArrayPrint(closef); //--- compare the received data if((res1==res2) && (time1[0]==time2[0])) { Print(" | Time | Open | Close double | Close float |"); for(int i=0; i<10; i++) { PrintFormat("%d | %s | %.5f | %.5f | %.5f |", i, TimeToString(time1[i]), open[i], close[i], closef[i]); } } /* Result 1. CopySeries returns 0 values. Error code=0 [ 0] 1.06722 1.06733 1.06653 1.06520 1.06573 1.06649 1.06694 1.06675 1.06684 1.06604 [10] 1.06514 1.06557 1.06456 1.06481 1.06414 1.06394 1.06364 1.06386 1.06239 1.06247 2. CopySeries returns 0 values. Error code=0 [ 0] 1.06722 1.06733 1.06653 1.06520 1.06573 1.06649 1.06694 1.06675 1.06684 1.06604 [10] 1.06514 1.06557 1.06456 1.06481 1.06414 1.06394 1.06364 1.06386 1.06239 1.06247 | Time | Open | Close double | Close float | 0 | 2023.03.01 17:00 | 1.06660 | 1.06722 | 1.06722 | 1 | 2023.03.01 18:00 | 1.06722 | 1.06733 | 1.06733 | 2 | 2023.03.01 19:00 | 1.06734 | 1.06653 | 1.06653 | 3 | 2023.03.01 20:00 | 1.06654 | 1.06520 | 1.06520 | 4 | 2023.03.01 21:00 | 1.06520 | 1.06573 | 1.06573 | 5 | 2023.03.01 22:00 | 1.06572 | 1.06649 | 1.06649 | 6 | 2023.03.01 23:00 | 1.06649 | 1.06694 | 1.06694 | 7 | 2023.03.02 00:00 | 1.06683 | 1.06675 | 1.06675 | 8 | 2023.03.02 01:00 | 1.06675 | 1.06684 | 1.06684 | 9 | 2023.03.02 02:00 | 1.06687 | 1.06604 | 1.06604 | */ }
MetaEditor
Tester
Trade Master 9 Web Terminal build 3620