Neural Network EMA system (NeuroTrend)

Dont wanna get in trouble with the admins here… just do a search at forex-tsd.com for neural network :slight_smile:

I’ve been testing this the past week and it is amazing how predictive it can be. I suppose the trick is to keep the neural network ‘trained’ as you call it … can anyone learn to do this or does it require some advanced programming knowledge. (I have some basic programming skills … not advanced!)

The lines redraw the past. So not too fancy like you said.

Just play with it for couple of hours.

I only had time to run a single signal but it was a money maker. There was a nice short that came up between 3pm-4pm Central Time (-6 UTC i think or -7 with DST) that I didn’t ride out but it was a money maker.

It was funny because I had just installed the signals and chart template when it went off and I just did what it said. I had to actually go back and look to actually understand what it was doing. I was in demo so it wasn’t any big deal.

Hello Everyone,

I was away from my computer for a couple of days and was not able to do the updates as planned previously but finally I made it to program the modifications I wanted to do.

[B]Important update is that the network is trained with June and July history data.[/B]

Best Wishes,
Arun

To train a network, programming skills are not necessary (unless and untill you want to do in metatrader) as it is possible to use any of the free neural network simulator softwares on the net to train the network. The only requirement is to export necessary data from Metatrader to that software.

[I][B]Note: Read the installation instructions that is included in the zip file. Feel free to ask me if you were not able to install it properly.[/B][/I]

I’m amazed and impressed by this thread! I’ve done some light reading on neural network systems over the years but never seen one actually built and implemented.

I’d love to see some more screenshots of the signals you guys are generating.

Cheers!

Automated Trading Championship 2008 if you see the top two eas are neural network based so it getting some steam.
click on 2007

That motivates me to work more and improve my system but frankly speaking I am finding a bit difficult to find time to test various indicators.

How is your system working??? Do you have some results by now.

Arun,

I have worked with NN during my master’s thesis and I have good experience with them. I just don’t have the time right now to do my own tests on Forex market.

I think that you could use Jurik’s non lag (and smooth too) indicator tools for the NN inputs. I think of JMA 5 with phase around 0 and JRSX to replace you EMA and RSI. (If you need the Jurik indicators, look at the Metaquotes web site and look for NK_library). Of course you can add Demarker and ADX and I think you should have a longer set of past inputs. I would try from 5 to 10 past values. Just my 2 cents on this one…

Also, the output of the NN could be the following:

Use a JMA (5 to 15 period, to be tested) angle indicator (JMA5(n)-JMA5(n-1) for example) that is normalized between -1 and 1 so it will fall into the activation function range (I believe you are using sigmoid or tanh). Now shift this indicator 2 to 3 bars to the past. Use the shifted values as your training set (desired output). You could also set 3 trig points in the angle to define sell, no trade and buy signal. If you have a sigmoid activation function that goes from -1 to +1, the output values from -0.3 to -1 gives you a sell situation, from -0.3 to 0.3, gives you a “no trade” situation and from 0.3 to 1 you have a buy situation.

This is just food for thought as you go along. I think that predicting buy and sell signals is simpler to trade and to automate eventually.

it is very rule based it works. i made around 378 pip back testing! i really didnt like win ratio and i am try to simplify my rules. i have exams now i probably post my result for 17 - 23 and see if things got better. Just let you know it was ran against three pair, eur/usd, usd/jpy, and gbp/usd. win ratio was 51%

Thanks for your thoughts and suggestions. Infact, my first version was based on JMA. Neural Networks normally generalize the model that is to be trained and mixing lagging indicators with JMA really did not work in my case. From your experience, can you suggest me any other indicators and the amount of data I should take in to consideration for training. I mean how many months of data you think necessary to train a network.

Arun,

Sorry in advance for the lenghty post !!

Training is certainly a very critical part in the network developpement. As you probably already know, you don’t want to overtrain it as it will memorize the data instead of predicting it. I still think that you should add more past values of your EMA derivative. I would also include the second derivative of EMA (i.e. [EMA(n)-EMA(n-1)]-[EMA(n-1)-EMA(n-2)]). Let’s say that the EMA is the position of a car on the road, the EMA derivative gives you it’s speed and the second derivative gives you the acceleration. This is a good characterization of what the car is doing.

Also, I think that adding a volatility indicator could improve the result. You could use the upper Bollinger band minus the lower Bollinger band value. Another one could be the ATR but I must say that I prefer the JATR since it reacts quicker and it’s smoother. I added the indicator if you want to try it. I also think that including the derivative of the RSI or stochastic could lead to interesting results as they show quickly when price action is changing direction.

The network should be trained using different periods. For example, you could use three periods for training, The first one could be a period where the currency was mostly trending up, the second when it was mostly trending down and the last one when it was going sideways. This way you would be less likely to have a network that performs well only in certain market type.

I would look at the residual error value and as soon as it starts to show convergence (mean error stops going further down), I would stop training. It could be hard to achieve if the software you use cannot give you the mean error of the training.

You could also train the network using one period and then try it in a different period (aka testing period) to see if it is still giving a good signal. This is what you are doing already but I think that a plot of the error in the testing period could reveal if your network is optimally trained.

I also think that probabilistic NN (PNN) should be taken in consideration. They train quite fast so cycle of trial and error are shorter. I believe that the forex market has some cahotic behavior that is more suitable for probabilistic solutions. They also have less tendencies to hang in local minima and tend to go to global minima.

The nuber of neurons on the hidden layer can also have a dramatic impact. It must not be overlooked. I just can’t give you a numer. Usually you have about twice the number of your inputs on the hidden layer.

Finally, as I have mentioned before, these are only suggestions and I can’t promise that they will improve anything. I just don’t have the time to get deep into it. Which software do you use (FANN, Cortex, Matlab, NeroShell…) ?? If I get into this later, I think of using Matlab since it has all the power and I know this beast quite well…

Thanks for your work…

very good idea. Im going to follow this.

Hi,

First of all thankyou for your excellent ideas. You seem to have a good foundation from your thesis work ;-). I am slowly seeing light in this thread with in-depth discussions on the topic. I am using the Uni Stuttgart SNNS or to say its successor JNNS to train my network. Do you have experience with this tool by chance??. I choose it as it is free, easy to learn and has various implementations of the algorithms. I have some experience with Matlab but not in training neural networks. Right now I am really satisfied with SNNS as it has all the required tools and plots. There is an error plot view which I really like and use to stop my training when the training and validation data have a global minimum. I stop the training a bit before the plot flattens which indicates that the network is starting to memorize. My long term plan is actually program the training algorithm also in mql. Right now I have implementation of a network creation and forward propagation which is included in NeuroTrend.

This is really sparkling. I liked the way you explained taking speed and acceleration as example. I should implement this as soon as possible. Also using a volatility indicator might be helpful as you said. One of my experience and also as I read in some publications, It is not much helpful to add more past data. My tests showed that it is enough if the inputs are that of t, t-1, t-2, t-3. As you might have noticed during training, outputs are of t, t-1, t-2 and inputs are of t-3, t-4, t-5. Do you think forecasting t+1, t+2, t+3 is a right model? I am planning to reduce and extend it to t, t+1 but for two EMA’s ie EMA5 & EMA 10. I am not sure but I think it might help to forecast a EMA cross over (mean two EMA’s) rather than forecasting 3 future outputs of one EMA. What is your opinion on this.

Concerning the number of hidden layers. According to some publications, it is enough to have a single hidden layer for most of the applications. Right now I use only one hidden layer but the number of neurons (units) depends on my number of inputs and outputs. I start with H = (I+O)/2 ie… number of hidden neurons is half the sum of number of inputs and outputs. In SNNS one can also prune the network, but I haven’t tried this as I am not sure of the good pruning algorithms and also in SNNS pruning does not work for all the training algorithms.

I would really appreciate if you can join me and keep giving your suggestions and opinions. Are you a full time trader??? I think if we collaborate on this we can surely come out with a good NN based indicators and bring some light on others to join hands. I try to spend at least 10hrs per week on my interests (programming and developing a NN based indicator) apart from my regular job. If more people join we can test different combinations of indicators and analyze whats good and whats not for NN based forecasting.

Thanks for your input,
Arun

Could you refer me to some literature about probabilistic neural networks?? Does it require changes in the implementation of the network or is it more dependent on training algorithm???

Arun,

Again, this is a lenghty post… sorry but due to the complexity of the task, it is needed !!

I don’t know the SNNS software but I think that any good NN software can do the job. It’s only a matter of preference. Some software may be faster than others which can be an advantage since training can sometimes be quite long. My work in my thesis was using millions of data points so I sometime had to wait several hours for simulation to complete. I like Matlab since it has very powerful matrix manipulation and NN calculation can be made using matrix math. Anyway in this case I believe your training time is quite fast as there are not many data points to process. Using NN software offloads you from the inside calculations and mistakes!!

I have attached a PNN document that shows you the basic math. I think that PNN have great potential for classification but I would set it aside for now. The PNN use a probability density function (pdf) that is quite different from sigmoid or tanh. The pdf is a gaussian like curve (the bell curve) and the inputs have to be processed to fit in. For those reason, I would stick to the standard backpropagation NN you (I believe) actually use. Keep it for later…

The forecast future EMA values is (IMHO) not the approach I would take. I did describe in my first post what I would do but let me explain it again.

The inputs would be what you have or a combination of the following (the little d before the indicator means the derivative of what follows so dEMA means the derivative of the EMA and ddEMA means the second derivative of the EMA. BB means the upper band minus the lower band of Bollinger Bands indicator. Also note that the Bands period should be played with to find optimal period and also the value has to be scaled so that it fits in the activation function range):

dEMA(n)
dEMA(n-1)
dEMA(n-2)…

ddEMA(n)
ddEMA(n-1)
ddEMA(n-2)…

RSI(n)
RSI(n-1)
RSI(n-2)…

dRSI(n)
dRSI(n-1)
dRSI(n-2)…

BB(n)
BB(n-1)
BB(n-2)…

dBB(n)
dBB(n-1)
dBB(n-2)…

JATR(n)
JATR(n-1)
JATR(n-2)…

dJATR(n)
dJATR(n-1)
dJATR(n-2)…

Now for the output, here is my idea:

You take the dJMA10(t+2) or dEMA5(t+1) and scale it to the range of your activation function. Of course by scaling it you will crop the highest values but the idea is to scale it to give you good resolution for normal market movements. The big moves will saturate at +1 but it is fine as it means that it is going up. I don’t care if the price is up strong or superstrong, as long as it is going up is all that matters. Another idea is to convert the values to angle values which have +90 and -90 degrees max values. You then normalize them to +1,-1. Now you create trigger points such as 0.3 and -0.3 (assuming an activation function that goes from -1 to +1). When you pass those 0.3 values, you are in up or down situation. When the value comes back within 0.2 or -0.2 then you are sideways. The little hysteresis (0.3 to get out but 0.2 to come back in) is to avoid oscillation of your prediction on boundary conditions. The values given here are arbitrarily chosen and should be back tested to fine tune them. Now you create a signal indicator based on those trig points to have only buy, sell, or sideways signal i.e. (+1,-1, 0) values to predict and this is what you apply to your learning theoretical values. The output of your NN will only be signals to buy, sell or hold and not future EMA values. This is much simpler to trade, if the signal is accurate!!

Another idea is to manually create your ideal values of buy, sell and no trade signal by looking at the testing period bar by bar and set the values manually. This could take quite some time but it could be interesting…

Another approach to use NN in trading is to do the work backwards. First you take a bunch of indicator you like and then do some backtests with the future values of those indicators. You can also use a NN that use the different indicators as inputs and train it so it will choose the correct balance between the different indicators. For example, I personally like the dEMA as it gives you the velocity of the price movement. If you back test a trading system using the dEMA(n+2) value, combined with some volatility indicators, then you see if it is profitable. Once you have tweeked the values, you then try to predict those indicators using NN and use them in your trading system. So first you see which future values are handy and then you predict them. This kind of system is quite demanding as you can end up with 4 or 5 different NN.

Also, I think that it could be interesting to try NN on longer time frames. You see, short time frames have some patterns but the news release are messing things around. Those are random in nature and no system can predict them. We have an idea with the economists prediction but still nothing is garanteed. Longer time frames like 1h, 4h and daily help to reduce those effects. Remember that doing live trading is way different from demo and backtest. You don’t always get filled or have requotes or slippage and short time frame may suffer from this. Just a thing to remember.

For the hidden layer, you only need 1, that is true. What I was saying is the number of neurons on this layer should be about twice as the number of inputs you have. This value can be changed, it is just a starting point.

Finally, I am full time worker and have very little time to put in developing trading systems. My job is quite demanding and I have little spare time. I have only been looking at forex for the past year. I am still learning but I have a good idea of what beast the forex is… A beast that is hard to control I must say !!

I will try to help you as much as I can with ideas but I cannot commit to program anything right now… You just happen to be the first one to exhibit about the same idea I have in my head so I chose to give you what I have thought !

Thanks again for your suggestions Pegasus200. It was a bit hard for me to understand the outputs you mentioned, but I think I got it. In this reply I am going to make a table which would be like a foundation for new trials based on our discussions.

Concerning output of the network I would prefer not going with the idea 2 & 3 as you mentioned…

  1. Another idea is to convert the values to angle values which have +90 and -90 degrees max values. You then normalize them to +1,-1. Now you create trigger points such as 0.3 and -0.3 (assuming an activation function that goes from -1 to +1).

  2. Another idea is to manually create your ideal values of buy, sell and no trade signal by looking at the testing period bar by bar and set the values manually. This could take quite some time but it could be interesting…

I liked the second idea, but as you said we have to play around with the threshold values to find the best once. Also i see it as an extension to the idea 1) by applying threshold at the level after the forecast of the EMA(t+1). Which in this case would map 1 or BUY to forecasted EMA(t+1) >= EMA(t)+0.3

Idea 3) is a tedious process which I have already experienced as it required a lot of patience and time to create training signals by looking at each Bar signals and might be influenced by the error of human decision.

Another approach to use NN in trading is to do the work backwards. First you take a bunch of indicator you like and then do some backtests with the future values of those indicators.

Your final idea was not clear to me. I think you meant to forecast indicators of a well known trading system that is based on some well studied indicators.

Lets make a foundation for our discussions and for our objective of designing a reliable NN system. This is not a final draft. Once we are satisfied with some initial inputs and outputs. I will create a new NN indicator out of it and lest see how we can optimize.Due to lack of table tools I had to create this in word and publish the screenshot. Word doc is also attached


Points for discussion

See text in red in the table

Do we need dBB as it only says about trend ???

Suggestions for initial parameters for BB???

I would also take EMA5 for 60min bar chart to feed whats going on in long run???

Do you think it is enough to feed difference of StochMain and Signal rather than including both?? From my experience with NeuroTrend Stoch has influence on forecasting better than MACD or ADX.

Any other suggestions??? Comments???

I was compiling this reply and nabil114 sent a reply next to this reply. I would agree in some way with this thoughts. For higher time periods I agree that noise is suppressed significantly and it is easy to work with but one needs also greater stoploss levels which will work only on standard accounts. I would say lets start with 15min chart and test also 30min and 1hr later. Anything less than 15min may be not a good start for a NN design with not much experience.

Finally, Thanks a lot to all for your thoughts, suggestions especially Pegasus200 for his time and support. I am hoping to come up with a well designed NN by end of this week.

Best Wishes,
Arun

i have been try to make a system. it works but problems are below. now if you can filter the bad trades then you have good ones that is it.
i am trying to make a system in 5 mins that problem with the system entry in dead trend and entry to late by the time indicators align. I wont be handle pairs that are choppy example gdbp/usd and usd/jpy

i am young so i dont need a million dollar over night with my system just more about consistently bring a 100 pips a week and in 7 year i will be able a millionaire.

about trades at news time spread go higher. you can make ea not trade in those times, rather wait after 5 min candle bar is done. usually most brokers will have normal spreads after that time. and sometimes you can create head fakes saying it is going up but really going down. example this week with the euro dollar.

the problem going in higher time frames is that sometimes is hard to predict is a trend is forming because it takes time for it to form or it wont go in you way in the beginning and go in your direction later on. You have to deal with sideways, choppy moves and dead markets. and if you trade over multiple pair knowing which pair is going to make the next trend.

where as short time frame you dont have worry about those problems rather if you entering if the trend is dead, or late for non choppy currency pairs.