Build Neural Network Indicator in MT4 using Neuroshell

Hi,

1. I think, the best inputs for our NN are all inputs that influence our desired output. In some case, during training the NN, we can remove any inputs that small correlation with our predicted output. But sure, this is not an easy task to find which parameters are the best for our nets.

To make prediction using HA is possible. You can use a script/indicator/EA to collect your data. Example
input[0] = iCustom(NULL, 0, "Heiken Ashi",0,i+21);
input[1] = iCustom(NULL, 0, "Heiken Ashi",1, i+21);
input[2] = iCustom(NULL, 0, "Heiken Ashi",1, i+21);
input[3] = iCustom(NULL, 0, "Heiken Ashi",1,i+21);
input[4] = iCustom(NULL, 0, "Heiken Ashi",0,i+34);
input[5] = iCustom(NULL, 0, "Heiken Ashi",1, i+34);
input[6] = iCustom(NULL, 0, "Heiken Ashi",2,i+34);
input[7] = iCustom(NULL, 0, "Heiken Ashi",3, i+34);

and the ouput is
output[0] = iHigh(NULL,0,limit-1);

PS: I remove extern color color1/2/3/4 in original Heiken Ashi

Here attached the sample data, for your NN training purpose.

Which one is better HA price or normal price, I am not sure..we need to train the net and test it. I prefer to preprocess data (using normalization) to limit our inputs/ouputs within certain range (e.g, -1 to 1, or 0 to 1).

Precaution: during training NN will measure maximum/minimum value from the pattern data, hence NN may not work in other range of data. Example if you train the NN while the predicted value is between 0.950 to 1.345, the trained net may not work if the actual value is below 0.95 or higher than 1.345.

2. Which pattern we need to choose for our training? I think the range where all patterns are shown. If all your trained pattern is only during bullish market, then your NN may not work during consolidation or bearish. Hence you should train all your data with all possible patterns. 20,000 patterns may be better than 1000 patterns, but 20,000 may not sufficient if not reflecting all conditions and 1,000 patterns may sufficient if it reflecting all conditions.

Arry
 

Attachments

  • aaNeuro8iHAdata short.zip
    103.8 KB · Views: 460
Arry!

Still looking for a reasonable program to train the neural network but the problem is there are several parameters to set to train the network. So can you explain what parameters( input units, out put units, hidden layes, activation method, training algorithm, mse etc) with what values are the best to train forex data?

Thanks
Kashif
 
Kashif,

I am not a specialist but I may have few suggestion:
- All depends on what software intend to use, each software has some advantages than others.
- The inputs in NN is measured as a strength. Higher value considered more stronger than smaller value. Hence it is advised to use normalization technique for your inputs. It is better to use RSI, CCI, stochastic rather than O, H, L, C,V values itself and it related as well with the range. RSI, CCI and stochastic will move oscillatory within a range (-100 to 100 or 0 to 100) no matter the price movement.
- The output to be predicted advised within the range as well, it is better to predict %Change in High rather than predict High itself, since %Change allways move within 0-100% and afterward you may recalculate back to get predicted High.
- There are some formula to count how many neurons for hidden layers. what i found for network with one hidden layer, the number of hidden neurons = 1/2 (Inputs + Outputs) + square root of the number of patterns. Refer to previous question indicates that more patterns will require more hidden neurons.
- So far turboprop and rotation training methods in NS2 give a better result compare with others in most of my case.
- I am verifying that small impact to the prediction for selection of activation method (need more investigation).
- Error criterion is used to measure performance of our NN. Off course the best one is NN which can produce R-squared=1 , MSE and RMSE smallest, %same sign=100%. Those result resulted for all range (Training, Cross validation and Out of Sample Test/Production).

If I have a problem I will try to select all possible net configuration and choose the best one.

Arry
 
Arry,

Thanks for you reply.

My life is full of ups and downs. Programming and Math are my favorite subjects. Though I could not become a professional programmer or Mathematician. But I keep try programming my self like php and EAs. Before about 5 years, first time opened a demo trader account and starts trading. Since that time I have lost about $250 but I did no do trading regularly. Just keep looking whats going on!

But 10 months ago I left my temporary job and started sitting on net, some time with php and some time with trading. In trading, my aim was to develop an EA which can give me about 400 pips/month. I tried many strategies but there was nothing than loss.

Mean while I came across some digital type of indicators and now also Neural networks. These two things now forcing me to do MSc in mathematics because these things have their own interest other than Forex.

So while I was working on some digital filters, I applied a little trick on HP filter and Naturally I found an indicator which can give me some good profits on all TFs and on all Pairs.

When I manually look at this indi. chart I see some huge profits but when I tested it with EA, the results was not good enough. So I concluded the problem is not EA, problem is MT4. I don't know what they have built inside MT4 so that it always shows big draw downs even where I see some profit. So I wrote a script to test the indicator strategy and I am in profits.

I am attaching some script reports for newest 2000 candles to show you if something really like this possible. I will also send you my indi. but I am doing some back tests. I name my indi. kTrend, I took "k" from my name! Its not something like holygrail but I hope will do something good. In image Green for long and Red for short.

Kashif

usdchf.gif
 

Attachments

  • kTrendReports.zip
    18.3 KB · Views: 468
Kashif,

I experienced some following problems:
- each Broker may have a different price, spread, swap and margin.
- some slipage between our PC and the broker server due to internet connection.
- the running price between demo account and real account most of brokers are different.
- some broker are trusted but some of them may filtering the price, especially during fundametal news annoucement.
All this point should be considered as part of our trading strategy (including the broker selection).

Regarding your indicator, I think we can use it as input for NN. In case you create indicator only based on High pass filter then it is also good to have indicator based on Low Pass filter. Afterward we can train for NN. We can have a mutual benefits, e.g. you give your data/indicator and I tried to train them using my software and give you the dll file and you can create an EA based on it.

Thank you,
Arry
 
Arry,

Yes, well said. These all problems and also I have read on some other forum where a member told me that MT4 take broker side. So its my idea to you that try some other charting software if you can.

In my case I am just using MT4 to test the indicators, also MT4 has some good history data. My aim is to code a robot(EA) for my streamster which I can do in VB easily.

A good thing about my indi. is we don't need any thing extra with it. It will do the job alone. No need to train NN any apply it. The only thing is I have to back test it closely and may be manually.

Just a question, how can I change the MT4 broker in my present installation? I tried to change the server but its not working! may be I need to download from the concerning broker? I want to back test the indi. on some different brokers!

Kashif
 
Kashif,

You do not need to download MT4 from other brokers, just copy srv file into config folder. You can search and download them (try search engine). After having all srv file for all broker, you may have all brokers demo account in singe installation of MT4.

arry
 
Arry,

Thanks for you reply.



So while I was working on some digital filters, I applied a little trick on HP filter and Naturally I found an indicator which can give me some good profits on all TFs and on all Pairs.

When I manually look at this indi. chart I see some huge profits but when I tested it with EA, the results was not good enough. So I concluded the problem is not EA, problem is MT4. I don't know what they have built inside MT4 so that it always shows big draw downs even where I see some profit. So I wrote a script to test the indicator strategy and I am in profits.

Kashif

usdchf.gif

By HP filter, do you mean high pass or Hodrick Prescott?
The latter repaints, so what you see is not what you get. In other words, it's output at the time of decision making is not the same as what you see as a trace on your terminal. In this sense it is non-causal.

There are lots of wonderful indicators like this; SSA is one of the best. But just try to use it in a system.

Be very careful using scripts to evaluate a system. You must account for all the ticks in between open and close of each bar as well as spread and slip. I think it is very difficult to evaluate a system this way. If Strategy tester says it has big drawdowns, it probably is even worse.:(

BTW if you get different results using Strategy Tester from different brokers, it is because you have different history files, or different spreads. The broker does not cheat with Strategy Tester, why should he, and how could he? (You can run offline).He saves his cheating for when he can make real money.
fralo
 
Last edited:
Using MSA to analyze strategy (stock market)

Kryzs and all,

Please find here attached my complete report for trading strategy evaluation using MSA.
- Stock daily data (BMRI.JK) is taken from yahoofinannce
- The trading strategy is generated using Chaos Hunter
- The ouput file is converted to Trade Data for MSA Analyzing
(Note: since BMRI is Indonesian stock, all calculaiton is in Rp and not confuse for decimal points written in '.' and thousands written in ",".

My question is which one shall be selected?
- The one who get highest Net profit, Return of starting equity, Win-Loss ratio, profit factor, Return Drawdown ratio, modified sharp ratio and lowest % drawdown.
- few strategy can not be implemented since state the maximum share is below 500 shares (1 lot = 500 shares).
- Since MSA is only evaluate a trading strategy (Not generating) how to implement it back to our trading software (NST or MT4 or else)?

Thank in advacne for your prompt advice.
Arry
 

Attachments

  • Evaluate Trading Strategy Using MSA _short_.pdf
    990.3 KB · Views: 619
Re: Using MSA to analyze strategy (stock market)

Kryzs and all,

Please find here attached my complete report for trading strategy evaluation using MSA.
- Stock daily data (BMRI.JK) is taken from yahoofinannce
- The trading strategy is generated using Chaos Hunter
- The ouput file is converted to Trade Data for MSA Analyzing
(Note: since BMRI is Indonesian stock, all calculaiton is in Rp and not confuse for decimal points written in '.' and thousands written in ",".

My question is which one shall be selected?
- The one who get highest Net profit, Return of starting equity, Win-Loss ratio, profit factor, Return Drawdown ratio, modified sharp ratio and lowest % drawdown.
- few strategy can not be implemented since state the maximum share is below 500 shares (1 lot = 500 shares).
- Since MSA is only evaluate a trading strategy (Not generating) how to implement it back to our trading software (NST or MT4 or else)?

Thank in advacne for your prompt advice.
Arry

Hi,

I looked to your report and using of Chaos Chunter. Than perhaps I will tell you what is a Grail procedure so you will see the difference.

With Grail you do:

1) Using CASB for specific fitness function you find different strategies and examine their equity curves IS and OOS

2) you chose the strategy with linear equity curve which dont drop but continuer risng OOS

3) You make WF analysis of this strategy including cluster WF. If it passes you can trade it.

Obviously point 2 of this it kind of 'vodoo' step. I dont see any reason that strategy
chosen with linear equity curve even continuing rising temporary OOS, should have predictive power. You can not be sure that it continued due to simple luck or is really predictive.

However point 3 and cluster analysis saves you a bit, if you have enough of trades, you can consider this like kind of Montecarlo test so it increases confidence level.

So without WF analysis is very dificult to say if something is working or not. One step of WF like NS does is not enough.

Krzysztof
 
intermarket database

I started to create inter market database for training NN and looking patterns inside.

I made it at 15min chart from 19.07.2007 till now. So far i included

EURUSD HLC + lag(1,2,3,4)
GBPUSD HLC + lag(1,2,3,4)
USDJPY HLC + lag(1,2,3,4)

it has at the moment 65k of rows, I use Excel 2007 for it. I think we need to add to it

-time stamp in format readable by NN. This I can take care of and make conversion of date to julian date using Mulitcharts.

Stock indecies. It must be data from the futures contract as it has to be 15min data
Gold prices
Oil Prices
News data series. I think its one of the most important data in it

related thread is at
http://www.forexfactory.com/showthread.php?p=2877616

maybe something else. If somebody is interested in cooperation for developing it or has already some data let me know.

Krzysztof
 
By HP filter, do you mean high pass or Hodrick Prescott?
The latter repaints, so what you see is not what you get. In other words, it's output at the time of decision making is not the same as what you see as a trace on your terminal. In this sense it is non-causal.

There are lots of wonderful indicators like this; SSA is one of the best. But just try to use it in a system.

Be very careful using scripts to evaluate a system. You must account for all the ticks in between open and close of each bar as well as spread and slip. I think it is very difficult to evaluate a system this way. If Strategy tester says it has big drawdowns, it probably is even worse.:(

BTW if you get different results using Strategy Tester from different brokers, it is because you have different history files, or different spreads. The broker does not cheat with Strategy Tester, why should he, and how could he? (You can run offline).He saves his cheating for when he can make real money.
fralo

Fralo,

HP = Hodrick Prescott

Of course it will repaint, the way it works! And yes I cannot get what I see:(

To use a script is just to estimate the outcomes where a normal EA not gives proper results. Its true what I can get from tick data, cannot get from a script.

I cannot say if the brokers cheat or not but how many strategies I have tested all have very bad results. I know I can wrong but at last how much?:(

Kashif
 
Kashif,

For your information, in NST, HP is part of Advance Indicator Set 1, see help at http://www.neuroshell.com/manuals/ais1/index.html?keltnerchannels.htm then click HP)

"The Hodrick-Prescott filter CANNOT be used in trading strategies or neural nets used in trading strategies. This indicator was designed to be viewed as a trend curve through the entire set of data. It is not appropriate for use in a trading strategy because new data bars can cause the trend line to change the trend through past data. This in turn can cause the NeuroShell Trader signals to change in the past. Use this indicator ONLY for viewing in a static chart, but do NOT insert it in a trading strategy or a neural net used for trading. Use Hodrick-Prescott Window indicator instead."

Arry
 
Re: intermarket database

I started to create inter market database for training NN and looking patterns inside.

I made it at 15min chart from 19.07.2007 till now. So far i included

EURUSD HLC + lag(1,2,3,4)
GBPUSD HLC + lag(1,2,3,4)
USDJPY HLC + lag(1,2,3,4)

it has at the moment 65k of rows, I use Excel 2007 for it. I think we need to add to it

-time stamp in format readable by NN. This I can take care of and make conversion of date to julian date using Mulitcharts.

Stock indecies. It must be data from the futures contract as it has to be 15min data
Gold prices
Oil Prices
News data series. I think its one of the most important data in it

related thread is at
http://www.forexfactory.com/showthread.php?p=2877616

maybe something else. If somebody is interested in cooperation for developing it or has already some data let me know.

Krzysztof

I think also data like T-Bond and Bund must be added. So if somebody has this data let me know

Krzysztof
 
Kashif,

For your information, in NST, HP is part of Advance Indicator Set 1, see help at http://www.neuroshell.com/manuals/ais1/index.html?keltnerchannels.htm then click HP)

"The Hodrick-Prescott filter CANNOT be used in trading strategies or neural nets used in trading strategies. This indicator was designed to be viewed as a trend curve through the entire set of data. It is not appropriate for use in a trading strategy because new data bars can cause the trend line to change the trend through past data. This in turn can cause the NeuroShell Trader signals to change in the past. Use this indicator ONLY for viewing in a static chart, but do NOT insert it in a trading strategy or a neural net used for trading. Use Hodrick-Prescott Window indicator instead."

Arry

Thanks Arry,

I knew this thing by looking at HP filter.

Some questions!

1. Are you using NN for trading for demo/live?

2. How often you do retrain NN?

3. If you are trading NN, then howmany avg. trades based on NN you have on daily or weekely basis?

4. What is the wining rate wins/trades based on NN?

5. What you say from your experience that NN based trading can be really profitable?

Thanks for your time.

Kashif
 
Here I post the test result using Probabilistic Neural Network that evaluated within NSDT. PNN is supervised NN to classify the inputs.

Market: Indonesian Stock, BMRI.JK, yahoofinance daily data, with 1660 bars.
NN Inputs: All Price Momentum Indicators (12 indicators in NSDT)
NN Output: 7 categories trade signal based on optimal signal
NN architecture: Probabilistic Neural Network, 12 input neurons (slab 1), 1660 neurons (slab 2), 7 neurons (slab 3).

Implemented in NSDT using cross over without optimization (cross over directly from the winner neurons), there is no walk forward data available yet.

My temporary conclusion: PNN is useful to classify inputs, so far for training data give a good result. Walkforward test result to be confirmed.

Arry
www.ai-traders.org..for detail reports
 

Attachments

  • PNN applied in NSDT.png
    PNN applied in NSDT.png
    63 KB · Views: 1,208
  • trading statistics pnn.txt
    24.9 KB · Views: 489
  • Applied result NS2.txt
    805 bytes · Views: 441
Last edited:
More charts in detail...

- It works on trending or non-trending market
- it works for a small or large price movement

Unfortunately this occurred not in a real trade yet ....:p

Arry
www.ai-traders.org
 

Attachments

  • detail pnn5.png
    detail pnn5.png
    54.3 KB · Views: 486
  • detail pnn4.png
    detail pnn4.png
    54.3 KB · Views: 531
  • detail pnn3.png
    detail pnn3.png
    52.9 KB · Views: 454
  • detail pnn2.png
    detail pnn2.png
    52.7 KB · Views: 514
  • detail pnn1.png
    detail pnn1.png
    53 KB · Views: 599
  • detail pnn6.png
    detail pnn6.png
    56 KB · Views: 507
Can't be out-of-sample. I doubt it; PNNs do not generalize to new variation.

BTW do you use the Classifier from Ward Systems? they use a PNN too.
 
Can't be out-of-sample. I doubt it; PNNs do not generalize to new variation.

BTW do you use the Classifier from Ward Systems? they use a PNN too.

I agree, can't be OOS. But why do you say that PNN's do not generalize? Seems like they can if the data is stationary. So it depends to some extent on the choice of training data and target.
 
Top