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!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
//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) |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Hi Nicolas, this is very interesting. Do you mind maybe providing some more information on how to interpret it or even a use case or two?
Especially with regards to using the activation/de-activation and then moving on to a stronger neuron (or would this maybe require a new indicator?)
Hi Nicolas…I don’t know where to post my request…..sorry!!!!
Can you tell me in a generic code how can I indicate not 1 contract buy or sell….but less…I tried 0,1 or 0,01 contract at the market,
but the result it’s always the same….it considers always 1 contract….gimme a hand please=)
Hi, please post your question in the ProOrder section of the forum.