Build Neural Network Indicator in MT4 using Neuroshell

so which algorithm from ensemble learning you are using to switch between strategies ??

Did you convert your strategies to have output compatibile with this algorithm i.e. to output all elements of confusion matrix ??? How ??

Or you just feed results (success/failure) from trading strategies to ensemble without any preprocesing ??
 
Last edited:
so which algorithm from ensemble learning you are using to switch between strategies ??

Did you convert your strategies to have output compatibile with this algorithm i.e. to output all elements of confusion matrix ??? How ??

Or you just feed results (success/failure) from trading strategies to ensemble without any preprocesing ??

It is customized. I don’t use a confusion matrix but a Q-Q plot. I maintain 2 equity curves: the equity from the meta algorithm and a random path equity for which each entry is random instead. I then draw the % of random paths that beat the model vs. theorical quantile and use it to dynamically adjust the costs and payoffs from the ensemble. This way the system is automatically pushed into positive territories.
 
Lcs

Learning classifier system for FOREX
 

Attachments

  • introchapter.pdf
    74.2 KB · Views: 1,583
  • uwelcsg05-007r.pdf
    168.3 KB · Views: 1,257
It is customized. I don’t use a confusion matrix but a Q-Q plot. I maintain 2 equity curves: the equity from the meta algorithm and a random path equity for which each entry is random instead. I then draw the % of random paths that beat the model vs. theorical quantile and use it to dynamically adjust the costs and payoffs from the ensemble. This way the system is automatically pushed into positive territories.


I don't know this method, I only know that perhaps the best model for financial time series is random walk with drift (random trends) and those trends so up/down biases have huge impact for evaluation. See e.g this confusion matrix its from the system on 1min EURUSD during 'down day'. Row 1 - sell trades, Row 2 - buy trades, Row 3 - no trade.

So for sell trades there is 178 succesfull trades and 46 uncuccesfull, for buy trades 28 and 9. Than %profitable is for sell 79.5% and for buy 75.7%. Great results !!

But if you consider statistic of 'no trades'- row 3, precision there is only 38.5% and overall accuracy 45.8%.

so clearly all those good results (sell 79.5% and for buy 75.7%)were kind of biased by bias of 'down day' and little number of buy trades, in reality accuracy is just 45.8%

So in your case how you solve this 'bias' problem if there is any problem for this method ?
 

Attachments

  • Confusion_ALL_system__IS_bars=20000_OOS_bars=1440_PP=78.9272_SL=7_TP=23_AC=0.45833_Profit=35700_.jpg
    Confusion_ALL_system__IS_bars=20000_OOS_bars=1440_PP=78.9272_SL=7_TP=23_AC=0.45833_Profit=35700_.jpg
    57.7 KB · Views: 574
I don't know this method, I only know that perhaps the best model for financial time series is random walk with drift (random trends) and those trends so up/down biases have huge impact for evaluation. See e.g this confusion matrix its from the system on 1min EURUSD during 'down day'. Row 1 - sell trades, Row 2 - buy trades, Row 3 - no trade.

So for sell trades there is 178 succesfull trades and 46 uncuccesfull, for buy trades 28 and 9. Than %profitable is for sell 79.5% and for buy 75.7%. Great results !!

But if you consider statistic of 'no trades'- row 3, precision there is only 38.5% and overall accuracy 45.8%.

so clearly all those good results (sell 79.5% and for buy 75.7%)were kind of biased by bias of 'down day' and little number of buy trades, in reality accuracy is just 45.8%

So in your case how you solve this 'bias' problem if there is any problem for this method ?

The meta-algorithm is always in; 'no trades' = 0
 
I think that the individual efforts should go in deploying meta algorithms.
I think if someone has particular interests in machine learning is OK. But I am a firm believer in the no free launch.
No free lunch in search and optimization - Wikipedia, the free encyclopedia

Yes it is difficult. But for me there is no need to know everything. And I hope it is true because I can know really a few things ;).

My ensembles invariably work well so I wondered about the NFLT.

By the No Free Lunch Theorem (NFLT) no optimization algorithm exists superior to random choice. Or said differently there is no better model than any other model when averaged out over various market conditions.

Well? Ensembles seem to challenge the NFLT since they combine the advice of several models that can perform well under certain conditions while being bad under others. If you Google for it you'll see that the NFLT has been challenged in many other cases.
 
Hello Arryex,

I'm currently reviewing machine learning for automated trading.
This is a big journey in the long grass ...

I found the ebook herebelow quite interesting
Unfortunately the code is not available anymore.

I have background in Matlab, R, Weka and plan to have a look at encog ..

Maybe you still have the tradeFX.zip file or you know if I could get it somewhere

Thanks for your help

PS: I'm new here and available to contribute to the topic !


Hi Krzys,

Thanks for your given link, by the way here is the complete ebook

Index of /~gms2155/projectspring2009

Here are the complete collection about tradefx available there
[ ] Project1a.pdf 09-Sep-2009 23:03 1.8M
[ ] Project1b.pdf 09-Sep-2009 23:04 3.0M
[ ] Project2a.pdf 09-Sep-2009 23:06 6.4M
[ ] Project2b.pdf 09-Sep-2009 23:06 1.2M
[ ] Project3a.pdf 09-Sep-2009 23:07 941K
[ ] Project3b.pdf 09-Sep-2009 23:07 75K
[ ] Project4a.pdf 09-Sep-2009 23:07 808K
[ ] Project4b.pdf 09-Sep-2009 23:07 421K
[ ] Project5a.pdf 09-Sep-2009 23:07 520K
[ ] Project5b.pdf 09-Sep-2009 23:08 2.7M
[ ] Project6b.pdf 09-Sep-2009 23:09 3.8M

The correct link for tradefx is http://www.columbia.edu/~xv2103/finance/TradeFX/TradeFX.zip

Additional link for MT4 to Matlab for producing csv file is available here:
Interaction between MetaTrader 4 and Matlab via CSV Files - MQL4 Articles

I trace the required LibSVM has no more available. Any one can advice?

Arryex
 

Attachments

  • data.zip
    5.7 MB · Views: 251
Thank you very much.
This thread is really interesting to me.

I don't know Neuroshell.
I have some experience with Matlab, R
My interfaces with MT4 is through MySQL (home made dll) or MT4R.dll
(https://sites.google.com/site/prof7bit/r-for-metatrader-4)
Weka can also be accessed through RWeka
(CRAN - Package RWeka)

I try to setup an environment for backtesting:

1. feed MySQL database with quotes and indicators from MT4
2. Train the neural net from database and store result in R environment data or database
3. Back test with MT4 using EA calling R function directly or getting Matlab forecasts stored back in database.

I will go through the posts when time allows and I hope to contribute as far as I can.

Rgds,

Pierre




see post #652 of this thread

Krzysztof
 
Thank you very much.
This thread is really interesting to me.

I don't know Neuroshell.
I have some experience with Matlab, R
My interfaces with MT4 is through MySQL (home made dll) or MT4R.dll
(https://sites.google.com/site/prof7bit/r-for-metatrader-4)
Weka can also be accessed through RWeka
(CRAN - Package RWeka)

I try to setup an environment for backtesting:

1. feed MySQL database with quotes and indicators from MT4
2. Train the neural net from database and store result in R environment data or database
3. Back test with MT4 using EA calling R function directly or getting Matlab forecasts stored back in database.

I will go through the posts when time allows and I hope to contribute as far as I can.

Rgds,

Pierre

My setup is like this

MATLAB as a core

than interface MATLAB-WEKA and MATLAB-Theano (deep nets)

and interface MT4-MATLAB for trading

with this setup you have access to all Weka algos, all Theano based algos and all MATLAB algos

so if I choose to use e.g. Theano algo MT4 feeds quotes to MATLAB, MATLAB passes
to Theano, Theano makes classfication and passes class to MATLAB and MATLAB to MT4 EA. Additionally MATLAB makes trade file compatibile with MSA so is very easy to analyze the results

for backtest I have two modes. With MT4 and just internally with MATLAB only (based on TradeFX). Is much faster and convinient.

Be aware that TradeFX in original form requires a lot of bug fixing and additional development. The real time part is completlly ****ed up but i think is very good starting point.

Krzysztof
 
So long not see the updates..

Based on recent discussion about classification, I am trying to make classification based on two predicted indicators, as the following:
1. Create new signal values for both predicted indicators, example 1 for uptrend/buy and -1 for downtrend/sell
2. Make a simple logic:
if first indicator signal=1 and second indicator signal =1 -> trade signal =1 (Buy)
if first indicator signal=-1 and second indicator signal =-1 -> trade signal =-1 (Sell)
if first indicator signal=-1 and second indicator signal =1 -> trade signal =0 (Hold)
if first indicator signal=1 and second indicator signal =-1 -> trade signal =0 (Hold)

The code as simple as below:

if(iCustom(NULL, 0, "aaNeuroTrendsignal", 0, i)==1 && iCustom(NULL, 0, "aaNeuroMACD", 2, i)==1) X1=1;
else if(iCustom(NULL, 0, "aaNeuroTrendsignal", 0, i)==-1 && iCustom(NULL, 0, "aaNeuroMACD", 2, i)==-1) X1=-1;
else X1=0;

Here sample indicator as result of above classification, seems prospective and better than single indicator. I would like to develop EA based on this classification (including set the profit target) and check out the result..
 

Attachments

  • aaNeuroClass2i.png
    aaNeuroClass2i.png
    45.7 KB · Views: 823
Thanks very much Krzysztof

I really have a lot to learn and work around here
But that's very exciting

Indeed building around Matlab is a powerful choice but the realtime part is for sure challenging, particularly in case of loss of MT4 quotes.

I think I will keep MySQL database because it sounds more reliable than CSV files for data exchange. Also It's very easy to store the database on dedicated CPU and access it over IP.

Best Rgds,

Pierre

My setup is like this

MATLAB as a core

than interface MATLAB-WEKA and MATLAB-Theano (deep nets)

and interface MT4-MATLAB for trading

with this setup you have access to all Weka algos, all Theano based algos and all MATLAB algos

so if I choose to use e.g. Theano algo MT4 feeds quotes to MATLAB, MATLAB passes
to Theano, Theano makes classfication and passes class to MATLAB and MATLAB to MT4 EA. Additionally MATLAB makes trade file compatibile with MSA so is very easy to analyze the results

for backtest I have two modes. With MT4 and just internally with MATLAB only (based on TradeFX). Is much faster and convinient.

Be aware that TradeFX in original form requires a lot of bug fixing and additional development. The real time part is completlly ****ed up but i think is very good starting point.

Krzysztof
 
Here another version, where zero signal is removed.

if the first indicator as X1, then we display revised indicator as X2, with following code:
if(X1==1 && X1[i+1]==1) X2=1;
else if(X1==0 && X1[i+1]==1) X2=1;
else if(X1==-1 && X1[i+1]==1) X2=1;
else if(X1==1 && X1[i+1]==0) X2=1;

else if(X1==-1 && X1[i+1]==-1) X2=-1;
else if(X1==0 && X1[i+1]==-1) X2=-1;
else if(X1==1 && X1[i+1]==-1) X2=-1;
else if(X1==-1 && X1[i+1]==0) X2=-1;

else if(X1==0 && X1[i+1]==0) X2=X2[i+1];

Here is he result.
 

Attachments

  • aaNeuroClass2i ver a.png
    aaNeuroClass2i ver a.png
    36.8 KB · Views: 496
When I put the value of X1, X[i+1] and Y into Chaoshunter
X1 X1[i+1] Y
1 1 1
0 1 1
-1 1 1
1 0 1
-1 -1 -1
0 -1 -1
1 -1 -1
-1 0 -1

then I get this formula
Y = n3((X1[i+1] + X1[i+1]), 88.9884, ((-1.390839) + tanh(sigmoid(X1))), tanh((-1.390839)), X1, 16.59961)

where Y is X2

then I change the indicator code become

if(X1==0 && X1[i+1]==0) X2=X2[i+1];
else
X2= n3((X1[i+1] + X1[i+1]), 88.9884, ((-1.390839) + tanh(sigmoid(X1))), tanh((-1.390839)), X1, 16.59961);

also not forget to add tanh, sigmoid and n3 function as part of the code.

The result is still same as previous coding, but now I am using chaoshunter formula instead. I named this version as indicator NClass2i-b.
 

Attachments

  • CH model NClass2ia.png
    CH model NClass2ia.png
    70.5 KB · Views: 582
  • NClass2i-b using CH model.png
    NClass2i-b using CH model.png
    36.6 KB · Views: 592
Here I tried to make NClass using NS2 back propagation, after feed the data, training them and generate c code from the trained net. Compile the c code into dll and call it from MT4.

Additional code in new mq4:

#import "aaNeuroClass2i-ns2.dll"
void Nclass2ins2(double inarray[], double outarray[]);
#import

and modified parts:
for(i=barlength-1; i>=0; i--)
{
inarray[1] = X1;
inarray[2] = X1[i+1];


//Network output
Nclass2ins2(inarray, outarray);

if(X1!=0 && X1[i+1]!=0) X2= outarray[0];
else X2=X2[i+1];
}

After plotted indicators on the chart, output values from NS2 dll is not fixed at 1 or -1, see the last value is 0.999898, but still in a good approximation. I named this indicator as aaNS2class2idll.
 

Attachments

  • NClass in NS2.png
    NClass in NS2.png
    126.8 KB · Views: 575
  • aaNeuroClass2i dll from NS2.png
    aaNeuroClass2i dll from NS2.png
    35.5 KB · Views: 560
I just check that my indicator works properly in small time frame (5m). Hope it will be successful..:)
 

Attachments

  • NClass2i-b in 5M chart.png
    NClass2i-b in 5M chart.png
    34.6 KB · Views: 2,411
Top