Help Please!!! to 'port' nested Class(s) from EA to CNeuralNet

 

deal Fellow:

While trying to learn about Neural Network and AI, I come across an article https://www.mql5.com/en/articles/12187.

I am trying to put most of the possible calculations within the CNeuralNet and remove them from EA_TradeNN.

I am using setup of CStategy --> CBaseExpert --> ExpertAdvisor.

I need guidance/help/support to move following codes from EA to CNeuralNet class "CNeuralNet *TrainNet(double &std)" and "CNeuralNet *LoadNet(const string filename, double &std, const int flags = FILE_COMMON)"

CNeuralNet *TrainNet(double &std) {

                double          aCoefs[];
                matrix          sys(Reserve, SymbolCount*Depth);                        // create matrix of (250,15) size       when Reserve 250, Symbol(3) * Depth(bars) 5
                vector          vModel(Reserve);
                vector          vCoefs;                                                                                                                         // to failitate transfer of aCoefs[] data into matrix.sys's rows
                datetime        startTime = 0;

                for(int j = Reserve-1; j >= 0; --j) {
                        // since we're using close price, make +1 in pBarShift for first completed bar
                        if(!getPriceDelta(j+1)) {                                                                                       // will also update 'sSC[].close' array
                                return NULL;                                                                                                                            // probably some other symbols may not have enough history
                        }

                        // remember where/when the training set begins
                        if(startTime == 0)                                                                                                              startTime = iTime(_Symbol,PERIOD_CURRENT,j);

                        ArrayResize(aCoefs, 0);

.... partial code due to limit on characters in the post
CNeuralNet *LoadNet(const string filename, double &std, const int flags = FILE_COMMON) {

                CBinFileNetStorage                      reader;                                         // custom (optional) data
                CNeuralNetStore                                 store;                                  // general data
                CNeuralNet                                                      *net;
                std = 1.0;
                Print("Loading ", filename);
                ResetLastError();
                net = store.load<CNeuralNet>(filename, &reader, flags);
                if(net == NULL) {
                        PrintFormat("Failed to load NeuralNet from [%s] file: Error[%i]",filename,_LastError);
                        return NULL;
                }

                CNeuralNet::Stats                       s[1];
                s[0] = reader.getStats();
                ArrayPrint(s);
                std = reader.getScale();
                Print(std);
                Print(reader.getDescription());
                return net;

} // End of class initiliazation

since the code has nested classes and no constructor seems to be called in EA, I am confused how to achieve my goal.

string                                                          Symbols;
int                                                             Reserve;                                                                                                                        // Training set size (vectors)
//+-----------------------------------------------------------------------------------------------------------------------------+
//| CLASS:                      CStrategyNN
//| STRATEGY:           
//+-----------------------------------------------------------------------------------------------------------------------------+
class CStrategyNN : protected CBaseStrategy {

public:
                // PARAMETRIC CONSTRUCTOR METHOD
                CStrategyNN(SSymbolParam &pSymbolParam,string &pTradedSymbols[]);
                // DEFAULT DESTRUCTOR
         ~CStrategyNN();

Currently I am getting following errors (StrategyNN.mqh), which seems because of in EA they are defined as global variable while in Class they are not. Even declaring them as public, did not help.

If I declare variables before class definition, at least I dont get "variable undeclared" error. However, I am not sure if this is correct practice? Also the code still remains in EA (or StrategyNN Class) instead of my goal to move it within NeuralNet Class.

'Reserve' - undeclared identifier StrategyNN.mqh 813 16

'SymbolCount' - undeclared identifier StrategyNN.mqh 813 25

'Depth' - undeclared identifier StrategyNN.mqh 813 37

'Reserve' - undeclared identifier StrategyNN.mqh 814 19

'Reserve' - undeclared identifier StrategyNN.mqh 818 15

'getPriceDelta' - undeclared identifier StrategyNN.mqh 820 8

'+' - some operator expected StrategyNN.mqh 820 23

'SymbolCount' - undeclared identifier StrategyNN.mqh 833 23

'getPriceVolatility' - undeclared identifier StrategyNN.mqh 836 21

'sSC' - undeclared identifier StrategyNN.mqh 836 40

'[' - array required StrategyNN.mqh 836 43

',' - unexpected token StrategyNN.mqh 836 52

'sSC' - some operator expected StrategyNN.mqh 836 40

'arrNPV' - semicolon expected StrategyNN.mqh 836 53

')' - unexpected token StrategyNN.mqh 836 59

expression has no effect StrategyNN.mqh 836 53

'HiddenLayerFactor' - undeclared identifier StrategyNN.mqh 864 34

'HiddenLayerFactor' - undeclared identifier StrategyNN.mqh 865 34

'HiddenLayerFactor' - undeclared identifier StrategyNN.mqh 866 112

'SpeedUp' - undeclared identifier StrategyNN.mqh 873 29

'SpeedDown' - undeclared identifier StrategyNN.mqh 873 37

'SpeedHigh' - undeclared identifier StrategyNN.mqh 873 47

'SpeedLow' - undeclared identifier StrategyNN.mqh 873 57

'DropOutPercentage' - undeclared identifier StrategyNN.mqh 875 21

'Epochs' - undeclared identifier StrategyNN.mqh 876 57

'Accuracy' - undeclared identifier StrategyNN.mqh 876 64

'Symbols' - undeclared identifier StrategyNN.mqh 888 75

implicit conversion from 'number' to 'string' StrategyNN.mqh 888 75

'Depth' - undeclared identifier StrategyNN.mqh 888 102

'Reserve' - undeclared identifier StrategyNN.mqh 889 25

'Epochs' - undeclared identifier StrategyNN.mqh 889 52

'Accuracy' - undeclared identifier StrategyNN.mqh 889 75

'HiddenLayerFactor' - undeclared identifier StrategyNN.mqh 890 25

'DropOutPercentage' - undeclared identifier StrategyNN.mqh 890 59

'TimeStamp' - undeclared identifier StrategyNN.mqh 903 34

'(datetime)' - some operator expected StrategyNN.mqh 903 44

implicit conversion from 'number' to 'string' StrategyNN.mqh 903 34

'+' - semicolon expected StrategyNN.mqh 903 97

'+' - illegal operation use StrategyNN.mqh 903 97

result of expression not used StrategyNN.mqh 904 40

'FrameFile' - undeclared identifier StrategyNN.mqh 920 6

'FrameLoss' - undeclared identifier StrategyNN.mqh 921 6

38 errors, 4 warnings 39 5

Hope I can get some guidelines or help to progress further.

Regards

Complete code is attached as Zip file. StrategyNN.mql will not compile as it is part of other classes.

However, EA_TradeNN.q5 can be complied and can be tested.

Backpropagation Neural Networks using MQL5 Matrices
Backpropagation Neural Networks using MQL5 Matrices
  • www.mql5.com
The article describes the theory and practice of applying the backpropagation algorithm in MQL5 using matrices. It provides ready-made classes along with script, indicator and Expert Advisor examples.
Files:
NeuralNetMQL.zip  146 kb