Search This Blog

Tuesday

Forex indicator, based on neural network learning


Author:

gpwr

Description:

Two Forex - using indicator neuron direct distribution network (feedforward neaural network), which is learning by back propagation of errors (backpropagation). The network is loaded through a DLL file, C + + source code which is attached.

Neuron network is nothing more than a nonlinear model outputs as a function of inputs. At the entrances served user data, such as the sample time series. The meaning of the output is also set by the user, for example, signals 1 = buy / 0 = sell. The structure of the network, again set by the user. The network consists of a direct distribution

- The input layer (input layer), whose elements are inputs,

Hidden layers (hidden layers), consisting of computational nodes called neurons and

The output layer (output layer), which consists of one or more neurons, yields are yields across the network.

All nodes of neighboring layers are linked. These connections are called synapses. Each synapse has a weight (weight w [i, j, k]), which are multiplied by the data transmitted by synapses. Data moves from left to right is inputs from the network to its outputs. Hence the name "direct distribution network." The total sample of this network is depicted in the picture below

The data are processed neurons in two steps:

1. 1. All of the inputs multiplied by the appropriate weight, you are added

2. 2. Then, the resulting amount handled activation function neuron (activation or firing function) and (activation or firing function) and sent to the only exit.

The meaning of the activation function нейрон neuron as is the modeling work neuron and the brain: neuron is triggered only after the information has reached a certain threshold. In the mathematical aspects, it just gives the nonlinearity network. Without it, neuron net loss would be a linear autoregressive model (linear prediction model). The most common activation function neuron is a sigmoid function

f(x)=1/(1+exp(-x)) f (x) = 1 / (1 + exp (-x))

Forex Indicators

The threshold of activation of this function is 0. This threshold can be shifted on the horizontal axis at the expense of an additional entrance neuron (bias input), and called the input bias (bias input), which is assigned a certain weight in the same way as other inputs neuron.

Thus, the number of inputs, layers, neurons in each layer and the weights of inputs neurons entire neuron network, ie nonlinear model, which it creates. To use this model, you need to know the weight. The weights are calculated by training the network on past data, ie with any previous input data were known values of the output signal. The weights of the network are optimized to match its output with the test solution. Typically, inputs to the network filed several sets of input and corresponding output data and calculated mean error deviation of output from the network testing. The training network is to reduce this problem by optimizing the weights. There are several optimization methods, among which the main way back propagation of errors (ALO) and the method of genetic improvement.

Attached files:

BPNN.dll - Library file

BPNN.zip - archive all the files needed to create a DLL file

BPNN Predictor.mq4 - predictive indicator of future value prices

Buy-Sell Classificator.mq4 - predictive indicator buy / sell signals.

Train() и Test(). Library BPNN.cpp file contains two functions: Train () and Test (). Train () is designed to train the network to provide input and output data. Test () is for calculating output data based on the weights obtained after running Train ().

ВInput (green color) and output (blue) parameters of the function Train () are:

double inpTrain [] - input (older first)
double outTarget [] - Imprint (oldest first)
double outTrain [] - exits the network after training
int ntr - the number of training sets of input-output
int UEW - Managing key external values to initialize the weights (1 = use extInitWt [], 0 = use random numbers)
extInitWt [] - original values of weights
double trainedWt [] - the values of weights after training
int numLayers - number of layers in the network including input, hidden and output
int lSz [] - array size numLayers, which kept the number of neurons in each layer. lSz[0] задаёт количество входов сети lSz [0] specifies the number of network inputs
int OAF - a key feature in the activation of output neurons (1 = function enabled, 0 = no)
double LR - speed training
double MF - the moment of learning rate
int nep - the maximum number of training steps (epochs). Epoch consists of checking all the training sets.
double maxMSE - mean error, in which the learning stops.

Input (green) and output (blue) parameters of the function Test () are:

double inpTest [] - input data (older first)
double outTest [] - Imprint
int ntt - sets of input and output data
double extInitWt [] - original values of weights
numLayers - number of layers in the network including input, hidden and output
int lSz [] - array size numLayers, which kept the number of / neurons in each layer. l/ lSz [0] specifies the number of network inputs int OAF - a key feature in the activation of output neurons (1 = function enabled, 0 = no)

Using the activation of output neurons depends on the nature of the output. If the output signals of the network are binomial (0 / 1), then you must use the activation function (OAF = 1). If the output is a prediction of price, the activation function in output layer is not required (OAF = 0).

Examples of indicators used neuron Network:

BPNN Predictor.mq4 - predicting future prices. Network input parameters are the relative increments in prices:

x [i] = Open [test_bar] / Open [test_bar + delay [i]] -1.0

where delay [i] taken from the Fibonacci series. Network output is predicted a relative increase of future prices. Activation function in output layer is deactivated.

Input parameters are an indicator

extern int lastBar - number of the last bar
extern int futBars - the number of future predicted bars
extern int numLayers - number of layers in the network including input, hidden and output
extern int numInputs - the number of network inputs
extern int numNeurons1 - the number of neurons in a layer number 1
extern int numNeurons2 - the number of neurons in the layer number 2
extern int numNeurons3
extern int numNeurons4
extern int numNeurons5
extern int ntr - the number of training sets of input-output
extern double LR - the speed of learning network
extern double MF - coefficient of the time learning network
extern int nep - the maximum number of training steps (epochs)

extern int maxMSEpwr - exponent used to calculate the maximum allowable mean-square error learning maxMSE = 10 ^ maxMSEpwr


Buy-Sell Classificator.mq4 - индикатор предсказывающий buy/sell сигналы. Buy-Sell Classificator.mq4 - predictive indicator buy / sell signals. As in the previous example, the input network served

x[i]=Open[test_bar]/Open[test_bar+delay[i]]-1.0 x [i] = Open [test_bar] / Open [test_bar + delay [i]] -1.0

for bars, which in the past received signal to buy or sell. These last signals are ideal as input signals to obtain a given profit. Network output signal is 1 or 0 = buy = sell. The output layer activation function.

extern int lastBar - number of the last bar
extern int minProfit - the minimum profit in order to find the ideal entry point in the past
extern double threshold - the threshold for recognizing the output signals as 0 or 1
extern int numLayers - number of layers in the network including input, hidden and output
extern int numInput - the number of network inputs

extern int numNeurons1 - the number of neurons in a layer number 1
extern int numNeurons2 - the number of neurons in the layer number 2
extern int numNeurons3 extern int numNeurons3
extern int numNeurons4 extern int numNeurons4
extern int numNeurons5
extern int ntr - the number of training sets of input-output (depends on the number of buy / sell signals in the past, 0 selects all valid signals)
extern double LR - the speed of learning network
extern double MF - coefficient of the time learning network
extern int nep - the maximum number of training steps (epochs)
extern int maxMSEpwr - exponent used to calculate the maximum allowable mean-square error learning maxMSE = 10 ^ maxMSEpwr

Arrow to the right of the vertical green lines indicate buy / sell signals generated by the network for testing "the future" bars. The arrows on the left shows the optimal entry point in the past.

Installation of files:

Copy attached DLL file in the C: \ Program Files \ MetaTrader 4 \ experts \ libraries

Enables the use of DLL in metatrader: Tools - Options - Expert Advisors - Allow DLL imports

If the DLL file does not work, compile yourself. All necessary files are contained in BPNN.zip.

2 comments:

njel said...

nice nn indicator you can find on NNEA project. www.NNEA.net

Unknown said...

I have not come across a better brokerage platform than the one offered by FXB Trading. Its website and its quality customer support service team have earned confidence as well as respect of many traders. This brokerage service is well known for its legitimate dealings and its secure fund segregation. Trading is made simple at this place and there is plenty of flexibility on offer in the opening of positions.