Build Neural Network Indicator in MT4 using Neuroshell

Real time testing my NN indicator (GA on NST used to find best parameter) recently
Take too long for me to upload this video here:eek:
Then I placed on this link
eurusd5m test video - Download - 4shared

Anyone an see the actual result eurusd now
 

Attachments

  • chart1.png
    chart1.png
    11.2 KB · Views: 566
  • chart2.png
    chart2.png
    9.2 KB · Views: 585
Hi,

Thanks for the comment for the testing result, I hope can improve in the next revision.

I have verified that the signal generated are still valid over a certain period until the new reversal signal. Probably we can include the repainting condition into trading signal, for example, limit the trade signal for certain period of time, in NST we can limit one buy order even the new buy signal generated. Another way is to include the volatility indicators.
 

Attachments

  • repaint.png
    repaint.png
    39.5 KB · Views: 536
I just develop Kalman filter indicator on NST, seems could become a good indicator candidate, ready for testing...

You can download free kalman filter library on C at sourceforge
 

Attachments

  • Build kalman filter dll.png
    Build kalman filter dll.png
    94.2 KB · Views: 1,280
  • kalmanfilter.png
    kalmanfilter.png
    67.6 KB · Views: 1,701
Here result of kalman prediction on eurusd daily
 

Attachments

  • Kalman FIlter-eurusd1D.zip
    132.4 KB · Views: 483
Here result of kalman prediction on eurusd daily

Hi, Looks very good.

Looking briefly at the Kalman Code it takes in a Matrix for it's input. Based on HLOC data how do you get that in to a Matrix? And what comes out the other end?
 
Hi Sanity,

Where you will implement your code, is it on mq4 or on C. Currently I build dll using Visual C++ then it can be called from NST or MT4. All the source code available are mostly on C++.
The input series should be one of OHLC or any other data series (moving average or any other indicator).

Here I attach the NST chart (with saved data) including all input prediction and its prediction result. Here I just insert the indicator data series (not the indicator dll).

Someone sold kalman filter dll for 800 Rubbels :rolleyes: here http://www.myfolder.nm.ru/htm/price.htm
 

Attachments

  • kalman prediction on stock AKRA.png
    kalman prediction on stock AKRA.png
    61.5 KB · Views: 2,732
  • Kalman NST chart stock.zip
    298.1 KB · Views: 432
Hi Sanity,

Where you will implement your code, is it on mq4 or on C. Currently I build dll using Visual C++ then it can be called from NST or MT4. All the source code available are mostly on C++.
The input series should be one of OHLC or any other data series (moving average or any other indicator).

Here I attach the NST chart (with saved data) including all input prediction and its prediction result. Here I just insert the indicator data series (not the indicator dll).

Someone sold kalman filter dll for 800 Rubbels :rolleyes: here Ïðîãðàììíûå èíòåðôåéñû

Hi Arryex,

I'll be implementing in C# in Visual Studio. The c# version I looked at ( A C# Kalman filter class « Autospreader's Blog ) takes in a Matrix, but it's just how to patch the 1 dimensional series data in to the matrix? Think I'm just missing that piece of knowledge. Is it fairly straight forward? Don't know if you could post over the c++ so I can convert may be?

I've had a play with an SSA filter that I've engineered into c# from MQ4 (uses arrays rather than matrix), and am currently writing a back tester as and when I get time as I've got access to a fair bit of financial data, both tick and otherwise. Have found the SSA filter fairly slow in performance, but Encog seems to predict fairly well some data, at least the direction anyway. Is the kalman filter any quicker? As soon as the back tester is done I can then concentrate more on the filtering... Have read that some people are using things like MACD to confirm predictive signals that come out of SSA predictions of time series forecasting... Seem to produce tighter responses - have you ever tried that?

San.
 
Hi San,

Have you download also the matrix processing from codeproject
http://www.codeproject.com/KB/recipes/PsDotNetMatrix/DotNetMatrix.zip
seems autospreader'sblog was mentioned it. To be frank I never coding using C# so I could not verify the content.

In this video I will shown how the prediction signal based on kalman filter is generated on NST, on the right side I display both SSA and kalman filter on MT4. I do not think there are speed difference between SSA or Kalman, both of them will depend on your coding complexity, amount of data to be processed (5000 bars wil be more longer than 500 bars) and also your cpu speed and RAM.

test prediction kalman eurusd1m b - Download - 4shared

MACD is delayed MA, most probably SSA will be more responsive rather MACD except you set the smaller fast and slow MA parameters. If you wait MACD signal to confirm the SSA signal, while MACD is lag then there is no point using SSA. On above video, I prefer to use SSA and Kalman filter both confirm each other with no delay.
 
Hi Sanity,

Where you will implement your code, is it on mq4 or on C. Currently I build dll using Visual C++ then it can be called from NST or MT4. All the source code available are mostly on C++.
The input series should be one of OHLC or any other data series (moving average or any other indicator).

Here I attach the NST chart (with saved data) including all input prediction and its prediction result. Here I just insert the indicator data series (not the indicator dll).

Someone sold kalman filter dll for 800 Rubbels :rolleyes: here Ïðîãðàììíûå èíòåðôåéñû

I have played with Kalman filters/smoothers already. Adaptive, recursive, online incremental and all possible derivations. My results were far from being as good as yours.

How did you obtain the indicator data series (pred Kalman.csv files) your charts rely upon?
 
I did not get very meaningful results with kalman filter on its own.But after I combined the kalman filter with other filters together with couple of oscillators the out of sample results are encouraging.
 

Attachments

  • comp.png
    comp.png
    132.3 KB · Views: 862
  • kalman.png
    kalman.png
    134.7 KB · Views: 1,088
Hi Tovim,

I think you have a good progress with CH, if you are using version 3, by selecting the range, you can see directly the OOS equity result while performing optimization.

I have small comment, your trading size 300 unit commission 4/side may not applicable in forex. Checkout the trade detail, normally to buy 1 lot in EURUSD for example, if the commission is 2 pip than put 0.0002/side. By having too large trading unit size, means you have very huge amount of money to trade. Hope your strategy still profitable after change the trade size.

I have checked the particle oscillator, unfortunately dysii only available for UNIX.

Here attached the last result for kalman prediction strategy, seems applicable for scalping
 

Attachments

  • Kalman scalping.zip
    377.8 KB · Views: 498
Hi Sanity,

Where you will implement your code, is it on mq4 or on C. Currently I build dll using Visual C++ then it can be called from NST or MT4. All the source code available are mostly on C++.
The input series should be one of OHLC or any other data series (moving average or any other indicator).

Here I attach the NST chart (with saved data) including all input prediction and its prediction result. Here I just insert the indicator data series (not the indicator dll).

Someone sold kalman filter dll for 800 Rubbels :rolleyes: here Ïðîãðàììíûå èíòåðôåéñû


I ask again because there is no way you can get such good results with Kalman filters. I had a look at the charts you posted and noticed that the series in your pred Kalman.csv files lead outrageously. See screenshot on akra.
 

Attachments

  • akra.png
    akra.png
    6.2 KB · Views: 730
Check out this video...you may have different conclusion..
:whistling
anyway I am still developing it...:love:
 

Attachments

  • Kalman2.zip
    5.5 MB · Views: 538
Dear Arryex,

I'm currently using matlab to train neural network on forex history quotes.
I understand from your message here-below that you are able to generate cpp code from matlab, compile a dll and then perform prediction in metatrader.

This is very interesting !!

Would you mind to share which rules/principles you are using for cpp generation ?
Sorry if my question is too intrusive ...
In any case, congratulation and respect to you for such a nice job !

Best Rgds

Pierre


By tracing how the neural network configuration within matlab, finally I can make a script to generate cpp code from the neural network training result.

The cpp code is ready to be compiled to create dll, this dll is ready to call from MT4..

Here are the screen shoots..

Kryzs, finally I come to this point..to deploy trained net into dll ...:D
 
Hi Jon,

In brief, I use a normal neural network procedure in matlab from data collecting, define neural net configuration (input, output, hidden size and training function, number of epoch, optimization-test-out of sample range, etc). Ensure that you understand the neural net configuration as what you define initially, hence you will transfer easily the result into the code.

After the training and have a good result then we save all net parameters such as weigh and bias values.

The next step is to convert all neural net parameters into C code, then compile it into dll.

Hope it answers your question.
 
Thanks Arryex for your quick answer.

It is still unclear how you do the step "convert all neural net parameters into C code".

I'm using matlab R2012a and after training one NN, I can save all or part of its parameters into a .mat file.

I presume that in the dll, in order to perform prediction, one needs the weight and bias values from the training, but also the neural net code (mathematical calculations and loops ...).

Do you also convert automatically the matlab neural net structure/type into NN C code or do you reference NN C code already existing separately ?

Thanks for your help

Best Regards,

Pierre

PS: what I'm currently using as NN I/O is a range of y-ema as Input and the difference of two y kernel regression with different bandwidth as Output on H1 timeframe. I train and test NN on 5 years history.


Hi Jon,

In brief, I use a normal neural network procedure in matlab from data collecting, define neural net configuration (input, output, hidden size and training function, number of epoch, optimization-test-out of sample range, etc). Ensure that you understand the neural net configuration as what you define initially, hence you will transfer easily the result into the code.

After the training and have a good result then we save all net parameters such as weigh and bias values.

The next step is to convert all neural net parameters into C code, then compile it into dll.

Hope it answers your question.
 
Hi Jon,

Please verify your neural net configuration result on your matlab, you will have all weight and bias.

As long as you know how to construct your code from defined neural net configuration then you will know how to configure them as c code.
From the figure, I have 3978 data, 17 inputs and 3 outputs, 100 hidden neuron, 100 bias inputs, 100x17 weight input, 100 weight layer2. I just convert them into c code afterward.

Currently I do not save the neural network structure into a mat file, you may save them but then you need to translate the mat file into c code.

I think It is possible for me to make an executable program to do all this thing, we just put all input and output data, assume back propagation net, then create c code at the same time. I will have a look on it.
 

Attachments

  • ttraining result.png
    ttraining result.png
    19.8 KB · Views: 506
Hi Arryex,

Sorry for my late answer, I was busy travelling the last days.
In the attached doc you find some details about one example NN in myNN.txt file.

In this NN, there are 20 inputs, 1 output and 1 hidden layer with 4 nodes.
I use the rule : nr of hidden nodes = sqrt (nr inputs x nr outputs)

you'll find also myNN.mat containing the net for you to load as matlab variable

Thanks very much for sharing your experience.
I never used Neuroshell and I hope to use matlab with metatrader, combining this with other ideas.

I also maintain one mysql database for historical data and possibly indicators that I can access from both from Matlab and meta through dll for back testing

Hi Jon,

Please verify your neural net configuration result on your matlab, you will have all weight and bias.

As long as you know how to construct your code from defined neural net configuration then you will know how to configure them as c code.
From the figure, I have 3978 data, 17 inputs and 3 outputs, 100 hidden neuron, 100 bias inputs, 100x17 weight input, 100 weight layer2. I just convert them into c code afterward.

Currently I do not save the neural network structure into a mat file, you may save them but then you need to translate the mat file into c code.

I think It is possible for me to make an executable program to do all this thing, we just put all input and output data, assume back propagation net, then create c code at the same time. I will have a look on it.
 

Attachments

  • myNN.zip
    12.4 KB · Views: 347
Top