Enclosed files:
BPNN.dll - library file
BPNN.zip - archive of all files needed to compile BPNN.dll in C++
BPNN Predictor.mq4 - indicator predicting future open prices
BPNN Predictor with Smoothing.mq4 - indicator predicting smoothed open prices
File BPNN.cpp has two functions: Train() и Test(). Train() is used to train the network based on supplied past input and expected output values. Test() is used to compute the network outputs using optimized weights, found by Train().
Here is the list of input (green) и output (blue) parameters of Train():
double inpTrain[] - Input training data (1D array carrying 2D data, old first)
double outTarget[] - Output target data for training (2D data as 1D array, oldest 1st)
double outTrain[] - Output 1D array to hold net outputs from training
int ntr - # of training sets
int UEW - Use Ext. Weights for initialization (1=use extInitWt, 0=use rnd)
double extInitWt[] - Input 1D array to hold 3D array of external initial weights
double trainedWt[] - Output 1D array to hold 3D array of trained weights
int numLayers - # of layers including input, hidden and output
int lSz[] - # of neurons in layers. lSz[0] is # of net inputs
int AFT - Type of neuron activation function (0:sigm, 1:tanh, 2:x/(1+x))
int OAF - 1 enables activation function for output layer; 0 disables
int nep - Max # of training epochs
double maxMSE - Max MSE; training stops once maxMSE is reached.
Here is the list of input (green) и output (blue) parameters of Test():
double inpTest[] - Input test data (2D data as 1D array, oldest first)
double outTest[] - Output 1D array to hold net outputs from training (oldest first)
int ntt - # of test sets
double extInitWt[] - Input 1D array to hold 3D array of external initial weights
int numLayers - # of layers including input, hidden and output
int lSz[] - # of neurons in layers. lSz[0] is # of net inputs
int AFT - Type of neuron activation function (0:sigm, 1:tanh, 2:x/(1+x))
int OAF - 1 enables activation function for output layer; 0 disables
Whether to use the activation function in the output layer or not (OAF parameter value) depends on the nature of outputs. If outputs are binary, which is often the case in classification problems, then the activation function should be used in the output layer (OAF=1). Please, pay attention that the activation function #0 (sigmoid) has 0 and 1 saturated levels whereas the activation functions #1 and 2 have -1 and 1 levels. If the network outputs is a price prediction, then no activation function is needed in the output layer (OAF=0).
Examples of using the NN library:
BPNN Predictor.mq4 - predicts future open prices. The inputs of the network are relative price changes:
x=Open[test_bar]/Open[test_bar+delay]-1.0
where delay is computed as a Fibonacci number (1,2,3,5,8,13,21..). The output of the network is the predicted relative change of the next price. The activation function is turned off in the output layer (OAF=0).
Indicator inputs:
extern int lastBar - Last bar in the past data
extern int futBars - # of future bars to predict
extern int numLayers - # of layers including input, hidden & output (2..6)
extern int numInputs - # of inputs
extern int numNeurons1 - # of neurons in the first hidden or output layer
extern int numNeurons2 - # of neurons in the second hidden or output layer
extern int numNeurons3 - # of neurons in the third hidden or output layer
extern int numNeurons4 - # of neurons in the fourth hidden or output layer
extern int numNeurons5 - # of neurons in the fifth hidden or output layer
extern int ntr - # of training sets
extern int nep - Max # of epochs
extern int maxMSEpwr - sets maxMSE=10^maxMSEpwr; training stops < maxMSE
extern int AFT - Type of activ. function (0:sigm, 1:tanh, 2:x/(1+x))
The indicator plots three curves on the chart:
red color - predictions of future prices
black color - past training open prices, which were used as expected outputs for the network
blue color - network outputs for training inputs
Setting all up:
Copy enclosed BPNN.DLL to C:\Program Files\MetaTrader 4\experts\libraries
In metatrader: Tools - Options - Expert Advisors - Allow DLL imports
You can also compile your own DLL file using source codes in BPNN.zip.