The Perceptron is the simplest neural network, here is the code for the single layer version.
To put it simply, here I use a RSI 14 periods smoothed over 5 periods for example, but one could transmit any kind of data to it. By summing the value of the indicator at the instants y1, y2, y3 and y4 and weighted by a different factor for each of these iterations, we obtain an overall weight of the value which must then be interpreted naturally (see attached illustration).
In this version I left the value “raw”, in general one tries to obtain a boolean value by activating the true or false of this value with respect to levels of activation to be defined. In the case of this example on the RSI, this could be “on purchase if perceptron> 70 and on sale if perceptron <30 ..).
The values of the parameters x1 to x4 and y1 to y4 are to be modified at convenience and why not to optimize in Walk Forward mode in the ProBacktest strategy tester.
This code is an example of how the Perceptron is functioning and should be adapted with data arrays of any kind (indicators, prices, …). This leaves a wide area of exploration for those who want to try neural network. Good luck!
//PRC_Perceptron | indicator
//25.09.2017
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
// --- settings ---
//weight in % for each neuron
//x1=5
//x2=10
//x3=25
//x4=50
//indicator previous period
//y1=0
//y2=7
//y3=14
//y4=21
// --- end of settings ---
//indicator to be used by the neural network
indi = average[5](rsi[14])
w1=x1-100
w2=x2-100
w3=x3-100
w4=x4-100
a1=indi[y1]
a2=indi[y2]
a3=indi[y3]
a4=indi[y4]
return(w1*a1+w2*a2+w3*a3+w4*a4)