Build Neural Network Indicator in MT4 using Neuroshell

arryex

Established member
Messages
593
Likes
6
Develop a Neural Network based indicator has some advantages:
- Indicator may consist of a predicted values, as a leading indicator.
- This leading indicator will be useful prior placing any trade
- Neural network training can be performed using available softwares (freeware and commercial are available).
- the trained NN can be implemented as indicator in Metatrader either written neural configuration (weight) or calling the dll.

As a sample of NN implementation, I found the following link as the starting point: http://forums.babypips.com/57970-post1.html
Here I attached all file discussed on above link, basic idea to create the neural net is explained on the file (description.doc).

Using the same idea, I use Neuroshell to train the neural network and implement it in MT4 to create the indicator.

The following steps to build the NN:
1. Prepare the training data,i.e. consist of inputs and outputs for NN. Using MT 4 script to collect the data. Input can be indicators available in MT4 such as EMA, RSI, CCI, WPR etc. The output can be predicted EMA, Close, etc which useful for our trading depend on the NN strategy (back propagation, kohonen, PNN, GRNN, or GMDH).
2. Train the network using neuroshell:
- Create new problem
- Advanced NN: loading the data, define input/ouput, extract data (training and testing), design NN to choose NN strategy, create the dll using run time facilities.
3. Copy the created dll into MT4 folder.
4. Create MT4 indicator which consist of: dll file link definition, NN initiation OpenNet (in MT4 init function), calculate the indicator using FireNet and CloseNet (in MT4 deinit function). FireNet is used to firing the neural network using inputs as defined while preparing the data to get the NN output (predicted data).
5. Improving indicator, in my attachment I use moving average and comparison between the output net to generate trading signal and classifier indicator.
6. Converting MT4 indicator to expert advisor (I need some one to help me to create the EA based on created indicators).

The original MT4 files should been modified due to the format data required on
Neuroshell is different.

Attachment explanations:
- Description.doc (brief description from the originator)
- Data collection script.zip (sample code to collect data)
- Indicator, met file, template including instruction (in zip)
- aa Neurotred.jpg (indicator produced based on Neuroshell dll)
- Neuro Trend Classifier 4H.jpg (improved indicator)

Any advice is highly appreciated.
Cheers,
Arryex
 

Attachments

  • Description.doc
    428.5 KB · Views: 8,060
  • Data collector script.zip
    43 KB · Views: 4,025
  • aa Neurotrend.jpg
    aa Neurotrend.jpg
    86.7 KB · Views: 7,841
  • Neuro Trend  Classifier 4H.jpg
    Neuro Trend Classifier 4H.jpg
    114.7 KB · Views: 14,313
  • Indicators & instruction.zip
    21.1 KB · Views: 4,564
Last edited:
Dear Sir Arry,

Could you explain how to use data sets training creator as you attached above? and how it works.

Thank you
 
Hi,
I just uploaded the indicator file, net file and instruction to use them.

To use a script file, you should copy NeuralTrainingsetCreator.mq4 (and ex4) into folder
..\experts\script\, to use it expand the +script from navigator MT4 terminal, double click the file. You need to close and reopen MT4 if you can't see it.

The format data file is suitable for SNNS or JNNS (http://www.ra.cs.uni-tuebingen.de/SNNS/) which free downloaded. It is cheapest solution if you do not have
any commercial software to train your NN.

Other freeware is BMP that you can download from dit.ipg.pt/MBP/. All software and tutorial can be downloaded as well.

Sorry I could not tell more about SNNS or BMP since I am not use it extensively rather than Neuroshell, but I am sure it will help you much to learn neural network.

Good luck
 
The 2nd Indicator

I wish to predict 5 bar of High and Low in advance. The preparation done as the following:
1. Network Design
- input NN:
High(t), High(t+1), High(t+2), High(t+3), High(t+4), High(t+5),
Low(t), Low(t+1), Low(t+2), Low(t+3), Low(t+4), Low(t+5),
Close(t), Close(t+1), Close(t+2), Close(t+3), Close(t+4), Close(t+5)

- Output NN:
High(t-1), High(t-2), High(t-3), High(t-4), High(t-5) for Network 1
Low(t-1), Low(t-2), Low(t-3), Low(t-4), Low(t-5) for Network 21

- Network architecture:
3 hidden slabs, with 38 neurons, input slab with 15 neurons and output slab with 5 neurons.
Learning rate, momentum, and initial weight using default values
Pattern selection: rotation, Weight updates: Turboprop, Save training: best test set, event since min. avg. error=1,000,000.

2. Data preparation (using MT4 script, in csv format) to collect all required inputs and outputs.

3. Training performed, transfer created dll into MT4 folder.
4. Use the indicator.

Any other ideas are appreciated.

Cheers
 

Attachments

  • aaNeural Predict High & Low.jpg
    aaNeural Predict High & Low.jpg
    56.3 KB · Views: 6,011
Please excuse my ignorance but are you saying your NN will predict (rightly/wrongly) 5 bars in advance ?
 
Yes, regardless the quality of prediction (right or wrong), the intention is to next 5 bar high and low price (the next price range).

I have been inspired by the following article
http://www.tradetrek.com/Education/webclassroom/nn5forecast.asp

I think the quality of neural network prediction will be based on inputs, outputs and the neural network it self. Any other influence such as fundamental news announcement is not part of this NN input, hence we can not expect that the price range will be valid when the fundamental news announced.

Cheers
 
Which NNs do you find are best forecasters ?

I have found general regression and combined adaptive time ones are best.
Although the former are a bit wilder and the latter a bit slower.
 
Yes, regardless the quality of prediction (right or wrong), the intention is to next 5 bar high and low price (the next price range).

I have been inspired by the following article
http://www.tradetrek.com/Education/webclassroom/nn5forecast.asp

I think the quality of neural network prediction will be based on inputs, outputs and the neural network it self. Any other influence such as fundamental news announcement is not part of this NN input, hence we can not expect that the price range will be valid when the fundamental news announced.

Cheers

Had a look at tradetrek.
Seems that they are closing the equity side to concentrate on Forex.
NNs imho aren't quite up to speed yet. But this will change as markets become more and more predictable with better technology. Ultimately ceasing to exist.
 
You may notice in the TradeTrek article quoted above that they retrain their net at the end of each day. This allows the net to adapt to nonstationarities in the FX series. The problem with using a DLL from NS is that the net is fixed in time, and unless you go through the same process (collect features, transfer to NS, train net to get DLL, use it in MT4) each and every bar (equivalent to each day at trendtech) you may be hurt by the changes in the patterns. Is there any way to simplify the training process? Is it possible to train an adaptive net, or perhaps one that used an adaptive input?
 
My experience to train the network is quite faster, as you know, neuroshell was built since 2003 where only slow processor available at that time.
Now using 2000 bar data, 20% data for testing, using turboprop and event after minimum average 1,000,000 event it can be done only within 15 minutes. I am using AMD quad processor for my PC..hence the training time is not the case for me now, I can train the network any time if necessary but I will keep the net if the result still valid.

Please advice if you have any adaptive indicator available in MT4, so I can use it to train the network.
 
My experience to train the network is quite faster, as you know, neuroshell was built since 2003 where only slow processor available at that time.
Now using 2000 bar data, 20% data for testing, using turboprop and event after minimum average 1,000,000 event it can be done only within 15 minutes. I am using AMD quad processor for my PC..hence the training time is not the case for me now, I can train the network any time if necessary but I will keep the net if the result still valid.

Please advice if you have any adaptive indicator available in MT4, so I can use it to train the network.

I wasn't talking about training. I meant slower to adapt to new trends as in CAT nns or more erratic as in Gr nns.
 
My experience to train the network is quite faster, as you know, neuroshell was built since 2003 where only slow processor available at that time.
Now using 2000 bar data, 20% data for testing, using turboprop and event after minimum average 1,000,000 event it can be done only within 15 minutes. I am using AMD quad processor for my PC..hence the training time is not the case for me now, I can train the network any time if necessary but I will keep the net if the result still valid.

Please advice if you have any adaptive indicator available in MT4, so I can use it to train the network.
Sorry, the only MT4 NN indicators I have seen are primative, and do not do the job. They are in forums on NNs in the MT4 website and ForexFactory.

My comment was more a set of questions.
How often do you need to retrain your nets?
Have you considered using the adaptive neural Indicators in NS as preprocessors to your final net?
If you used these, would your net last longer between retraining?

A final question: Do you use ChaosHunter?
Regards
Fralo
 
I should explain that I am using Neuroshell2 instead of Neuroshell Trader, it is one of ward product (www.wardsystems.com).

With Neuroshell2 I can build my own prediction or classification and knowing neural net architecture (back propapagation, recurrent network, Kohonen, probabilistic neural network, GRRN, GMDH, etc). While in Neuroshell Trader you can make any prediction or classification using indicators add-on. Using runtime facilities in Neuroshell2 I can make my own add-on indicator for Neuroshell Trader or other software such as MT4. Even this is an oldest product, I can still get some benefits. There are other products that they called as AI Trilogy which consist Neuroshell predictor, classifier, genehunter and runtime facilities but I do not have them.

I think Chaoshunter is more advantage of GMDH neural network, I use it to get relation (formula) between variables, it can be used in many application and not limited for financial matters. I am still learning to use it, may be I can post about it after I get something useful.

You may compare Neuroshell2 and Neuroshell trader with neurosolution and Tradingsolution from neurodimension (www.nd.com) or Alyuda forecaster with Tradedecion. You can choose freely to train your network using a free software (SNNS, MBP, rapidminer etc).
 
As an advice from Chris (val2004), I tried to implement the same method as described on the following ebook by Mr Kutsurelis. http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.26.8408, here attached.

The objective is to predict 10 bars in future EURUSD (daily bar), all inputs are modified as described in attached pictures. All data are taken from MT4 chart, some inputs are not included due unavailability data. The chart is only displayed on Neuroshell trader Chart.

I am still develop the indicator on MT4, since the inputs are coming from other charts, such as EUJPY, USDJPY, #DJC.XDJ, etc.

Cheers,
Arryex
 

Attachments

  • Predicted Close.png
    Predicted Close.png
    67 KB · Views: 5,105
  • training display.PNG
    training display.PNG
    305.6 KB · Views: 2,515
  • Indicator inputs.PNG
    Indicator inputs.PNG
    25.8 KB · Views: 2,117
  • NeuralMarketsThesis.pdf
    415.1 KB · Views: 3,379
Anybody know about VantagePoint's Intermarket Anaylisis?

As explained in the book "Trend Forecasting with Technical Analysis" by Louis Mendelsohn, intermarket analysis provide more precise trading strategies.

Based on given inputs, there 5 Neural Networks are produced: 1. predicted 1 bar high (PHigh), 2. predicted 1 bar low (Plow), 3. predicted short term 2 bar SMA5 (PTS), 4. predicted medium term 4 bars SMA10 (PTM), 5. Neural Index (based on difference between predicted 1bar and actual SMA3).

Additional indicators PTS Diff (PTS-actual SMA5) and PTM Diff (PTM-actual SMA10), PHigh Diff (PHigh - High) and PLow Diff(PLow-Low). Unfortunately, I could not found how to get "Strength Index".

Neural Network Inputs: for EURUSD chart daily.
Open,High,Low,Close,Volume,AUDJPY, AUDUSD, EURCAD,GBPJPY, GBPUSD,,^DJI, ^DJT, ^DJU, Nasdaq-100, FTSE 100. I could not include Oil, USD Index, T-Notes as mentioned in the book, due to unavailability data from MT4.

Neural Network outputs:
Lead(High,1), Lead(Low,1), Lead(Avg(Close,5),2), Lead(Avg(Close,10),4) Lead(Avg(Close,3),1)

NN design using back propagation.
The book explain how to use these indicators, such as:
- Buy when PTS Diff or PTM Diff turns positive and sell when PTS DIff or PTM Diff turns negative.
- Buy when PTS cross above TrendS or PTM cross above TrendM and sell when reverse
- Buy when PTS cross above PTM and sell when reverse
- Buy when Neural index 1 and sell when 0.

Higher probability to be used for trading, i.e. when all indicators are in confluence.
 

Attachments

  • High probability for Sell.png
    High probability for Sell.png
    80.1 KB · Views: 2,475
  • High probability for Buy.png
    High probability for Buy.png
    81.7 KB · Views: 2,720
  • Inputs.png
    Inputs.png
    4.3 KB · Views: 1,547
  • intermarket_analysis_of_forex_markets.pdf
    518.9 KB · Views: 4,635
Anybody know about VantagePoint's Intermarket Anaylisis?

As explained in the book "Trend Forecasting with Technical Analysis" by Louis Mendelsohn, intermarket analysis provide more precise trading strategies.

Thanks for all the info Arryex. (y)I read the book a few years back, tried to use Neuro Solutions to reproduce Mendlsohn's results, and finally gave up. I didn't have all the data, and Neuro Solutions took a looong time training nets.

Did you use NS2 or NST for training? Have you tried using NST to develop trading rules and to backtest the rules? Any results you would care to post?
Regards
Fralo
 
Basic information that I used to train the network is mentioned on the following link as well http://www.tradertech.com/journal_trading.asp

Input layer:
euro FX plus the daily open, high, low, close, volume and open interest data(Not available in MT4) for nine related markets:
· Australian dollar/U.S. dollar (AUD/USD)
· Australian dollar/Japanese yen (AUD/JPY)
· British pound -> (Not available in MT4, may be GBP Index?)
· Euro/Canadian dollar (EUR/CAD)
· Gold
· Nasdaq 100 Index
· British pound/Japanese yen (GBP/JPY)
· British pound/U.S. dollar (GBP/USD)
· Japanese yen -> (Not available in MT4, may be USD/JPY?)

NN configuration:
Five different neural network (see attached picture)
Output Layer:
- The first network forecasts tomorrow’s high to help set stops for entry and exit points.
- The second network forecasts tomorrow’s low to help set stops for entry and exit points.
- The third network forecasts a 5-day moving average of closes two days into the future to indicate the expected short-term trend direction within the next two days.
- The fourth network forecasts a 10-day moving average of closes four days into the future to indicate the expected medium-term trend direction within the next four days.
- The fifth network indicates whether the market is expected to change trend direction within the next two days, by making a top or a bottom.
The first four networks at the primary level of the network hierarchy make independent market forecasts of the high, low, short-term trend and medium-term trend. These predictions are then used as inputs into the fifth network, along with other intermarket data inputs, at the secondary level of the network hierarchy, to predict market turning points.

Fralo, for the training I use NS2, I do not try to make prediction using NST neither make trading strategy with it.. at least implementing the idea first, but I will post it after.

Just for your information, the Neural trend indicator and Neural Classifier posted previously has a good result on H4 or daily time frame. Imagine if put an order at blue or red dot..for me is quite fun..:D I need some body to help me to convert the indicator to an EA...

Regards,
Arryex
 

Attachments

  • Figure2 Map of NN.gif
    Figure2 Map of NN.gif
    33.7 KB · Views: 3,333
  • Posting trading idea 1.png
    Posting trading idea 1.png
    17.6 KB · Views: 5,823
Fralo, for the training I use NS2, I do not try to make prediction using NST neither make trading strategy with it.. at least implementing the idea first, but I will post it after.

Just for your information, the Neural trend indicator and Neural Classifier posted previously has a good result on H4 or daily time frame. Imagine if put an order at blue or red dot..for me is quite fun..:D I need some body to help me to convert the indicator to an EA...

Regards,
Arryex
1. Is it that NS2 is better and more flexible than NST?
2. The red and blue dots are indeed a lot of fun..:clap:
3. I might be able to help with an EA, depending on what you want. I am not professional at this, but have programmed several that work quite well for backtesting with MT4. One I have used live, but it has drawdowns that are too large and is dependent too much on the spread. There are members of other forums that would probably jump at the chance to help since this is interesting and looks promising.

The problem I see is that several of the inputs to your NNs cannot be obtained using MT4. What is the form of your indicator? Is it a DLL fed by external data? Is it an MT4 indicator (I guess not)?

You probably know that there are ways to connect NST to MT4 so that NST will accept MT4 data in real time, and (I think) generate orders that MT4 can implement. I have never had need to do this so I'm not sure if it works well. PM me if you are interested in this, I have some files.
Fralo.
 
Hi Fralo,
Comparing NST with NS2
1. NS2 is not dedicated only for trading/financial prediction, it can be used for any other area. While NST is dedicated for trading only.
2. NST is newer product while NS2 is the oldest (classic one).
3. Neural Network prediction used in NST seems only back propagation, I am not sure if inside there are some choice to select the NN architecture inside NST, while with NS2 I can select which architecture NN available such as Kohonen, PNN for classification.

Thank you for your availability to create an EA, basically I need an EA code to generate trade signals (Buy, Sell, Stop) when cross over occurred (blue, red and magenta dots) which are based on cross over MA. The different is I am using predicted MA which called by MT4 using dll.

For your information, all my inputs are taken from MT4 chart using data collector, after trained in NS2 then I recall it using runtime facilities. All data and indicators are built in MT4.
See attachments..sorry I could not send the code yet, but almost same as the 1st post.

Arryex
 

Attachments

  • Neural Indicators.png
    Neural Indicators.png
    81.1 KB · Views: 2,259
  • aaNeuro Trend Properties.png
    aaNeuro Trend Properties.png
    16.2 KB · Views: 1,454
  • aaNeuro Classifier Properties.png
    aaNeuro Classifier Properties.png
    16.6 KB · Views: 1,726
  • aaNeuro Trend mq4.png
    aaNeuro Trend mq4.png
    77.4 KB · Views: 1,820
Hi Fralo,

3. Neural Network prediction used in NST seems only back propagation, I am not sure if inside there are some choice to select the NN architecture inside NST, while with NS2 I can select which architecture NN available such as Kohonen, PNN for classification.
I am still learning NST, but I am reasonably sure that it allows control of network architecture, provided that the architecture is simple. e.g. NST allows use of Kohonen and PNN's, but it will not support Laguerre recurrent nets. It will allow you to specify things like number of hidden layers and nodes per layer. I seem to recall that NST also has some form of recurrent net. I am not sure about control of the error prop algorithm. It has something called turbo prop which is proprietary.


Thank you for your availability to create an EA, basically I need an EA code to generate trade signals (Buy, Sell, Stop) when cross over occurred (blue, red and magenta dots) which are based on cross over MA. The different is I am using predicted MA which called by MT4 using dll.
Arryex
A basic crossover EA is supplied with MT4. It is OK to use for testing your logic, but too simple to go live. All you need do is make an MT4 indicator that calls your DLL, then replace the MA function in the EA with an iCustom function calling the MT4 indicator. It is important that your DLL be callable from MT4. (You might be able to simply call your DLL from the EA).

You might notice in the attached image that I have circled an area where most MA crossover systems fail, and made a couple of x's at the likely trading price. One cannot trade until the bar after the crossover has occurred. Then you must trade at the market or use some form of pending order. Although the crossovers may show profit if one could trade at the cross, the actual trades may cause whiplash. Because your sample shows long trends that are caught, for your sample the return would be very nice. But what about the long run? Only backtesting can tell. That might actually be easier in NST. (If I just knew how to use it).:confused:

Whiplash.jpg
 
Top