Build Neural Network Indicator in MT4 using Neuroshell

On the chart, magenta dot can be used as early stop/exit..or Classifier to confirm it. I am sure that it is not a best indicator..but it can be improved after..

I tried to use iCustom to call my indicator and it make crash MT4 when the EA being started. Maybe because I am using a dll on my custom indicator?

I may testing after the EA built in MT4. To be noted that creating a trading strategy in NST using MT4 data require additional indicator to collect data and transmit the trading signal from NST to MT4. The result may be different in NST if you are using optimization.

Using trained dll directly in MT4 may reduce any slippage or error transmitting data/signals between MT4-NST.
regards,
Arryex
 
Finally I found an EA code, name it as Classifier, with the following properties:
- Open Buy when my custom indicator value =1
- Open Sell when my custom indicator value =-1
- Order Lots depend on available margin
- Stop loss added when placing the order
- New position opened when take profit/stop loss filled (need to solve this)

remaining:
- No trailing stop (currently, I put manually at 15 pips)
- No take profit target
- No magic number identification
- No EA comment on placed order
The EA can run properly but can not be tested, when using tester making crash MT4 (probably due to calling a dll). Any body know how to fix it?

For testing purpose I use 5M time frame just for EA testing purpose, but looks OK:cheesy:

regards,
Arryex
 

Attachments

  • Classifier EA in action.png
    Classifier EA in action.png
    78.9 KB · Views: 2,545
  • Classifier.mq4
    2.2 KB · Views: 1,790
Last edited:
How to fix it will depend on your indicator. Here's a url that may be helpful.
http://www.metatrader.info/node/150

For one thing, the ordersend function in the EA is wrong. There are several parameters missing. From here
http://docs.mql4.com/trading/OrderSend the definition of ordersend

int OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)

Also, MT4 will reject orders if certain parameters are not what the broker wants. e.g. the stops cannot be too close to market, the minimum and maximum lots must be in bounds for your account, and the lots digits must be correct.

I don't think that you can use MT4 to backtest an EA that uses more than one symbol, because the strategy tester in MT4 simulates tick data, and was not designed to handle more than one symbol at a time. It always hangs. To test an EA that uses more than one symbol you must forward test it on a demo, or use another program.. maybe Multicharts if you don't like NST. :(

I'm in the process of writing a (single symbol NN) DLL indicator and using MT4 to backtest. My problem is to get the DLL tested independenty. Then I will face the MT4 integration. If I find any secrets I will post.

Fralo
 
I remember a thread somewhere about using a DLL to build and train a neural net. Don't remember the thread, but here is source code for the DLL, and the MT4 indicator that calls it.View attachment BPNN.zip

Hope this helps.
Fralo
 
Fralo,

Thank you for the links given, by the way BPPN is only for creating indicator (BPPN predictor) not an EA.

Yes you are correct, my ordersend is not completed that's why i do not have stoploss.

By the way, I switch from 5M to 30M time frame has a less fluctuation on signal generated. my sell order still on going...:D

There are some options:
- Trade entry based on the signals
- Trade exit can be based on trailing stop, target profit or new signal.
- For small time frame,e.g. 5m target profit 30 to 50 pips possible.
- For high time frame 30M use trailing stop
- For huge time frame such as daily use new signals

I try to build the EA based on above options..unfortunately Sunday I will going to abroad for 1 month (i worked in oil & gas offshore) and may left this for a moment:(..

Here I add the MT4 crash report when the EA tester run, even I do not have problem when run the EA.

Regards,
Arryex
 

Attachments

  • Classifier EA in action 2.png
    Classifier EA in action 2.png
    18 KB · Views: 2,765
  • crash report1.png
    crash report1.png
    17.9 KB · Views: 1,335
Last edited:
Looks like you have the EA working on a demo account, though I'm not sure how you are sending orders. According to your terminal you have a stoploss, but no takeprofit. Your indicator must access your DLL. I still don't understand how you are getting non forex data into the DLL.

The tester crash must have something to do with using multiple symbols, or maybe non FX symbols, but I know little about the crash log. Maybe another member will help?

But never mind. Have a good safe month. The FX market will still be here when you return.
Regards,
Fralo
 
I modified the EA and include the stoploss, takeprofit and trailing stop as extern variables (adjustable) based on the orderSend command:

External variables:
extern double Risk_Level =0.002, SL=1.5;
extern double TakeProfit = 50;
extern double TrailingStop = 15;

Buy Code:
(TakeProfit>0) OrderSend(Symbol(),OP_BUY,Lots,Ask,5,Stop,Ask+TakeProfit*Point,"Classifier™",16384,0,Green);

Sell Code:
if (TakeProfit>0) OrderSend(Symbol(),OP_SELL,Lots, Bid,5,Stop,Bid-TakeProfit*Point,"Classifier™",16384,0,Red);

Trailing stop for buy position:
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}

Trailing Stop for sell position:
if(OrderType()==OP_SELL)
{
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
I named the EA as Classifier 0.1, any new order has green arrow for buy and red arrow for sell position as shown on the chart.

To get all non-forex data it depends on the server demo account you use, i use UWC-Demo to get them, I checked also that ODL may have others data such as Oil and other commodities, hence make us easier to do intermarket analysis. As you see on the picture, I have Index data such as #DJU.XDJ for Dow Jone Utilities Average Index, #DJT.XDJ for Down Jones Composite Average Index. They provide also stock streaming data that possible included as inputs for our neural network.

regards,
Arryex
 

Attachments

  • UWC-demo.png
    UWC-demo.png
    78 KB · Views: 5,505
Currently I created and tested the EA without crashing out the MT4, the cause of the problem is avoiding to call a same dll by several indicators or expert advisors.

Here I tested on the 4H chart, which I assumed not too much ripple on the signals. Just a starting point, good or not still can be improved after.

I will try to make GA optimization on MT4 afterward.

Cheers,
Arryex
 

Attachments

  • Test and result.pdf
    255.4 KB · Views: 1,411
Finally i found some time to read this thread and i don't understand a few things, also would like to get some more info

1) Why you want to use MT4 ?? is it because you want to make simulation of trading
with demo account ?? But NST as you know can send orders to demo account directly
though MT4.

Than why to make such simulation ?? You can make much more efficient back test
including out of sample test and Walk Forward test using e.g. Multicharts or even
by NST directly.

2) Did any of your backtests included out of sample test ??? Did you consider statistical significiance of this test according to the rules so e.g. to have such test valid it has to be at least 30 trades from one distribution out of sample. What was the result ??

Krzysztof
 
Hi Kryzs,

Here are the answer your questions:
1. For me its simple, I use MT4 is my main data source because it's free (no subscription fee). The data coverage as well sufficient especially for forex analysis and multimarket analysis (with stock, index, etc) as basis for neural network. Demo account can be use as our paper trading and forward test, while waiting the proper trading strategy. You are correct we can use NST to send the trading order to MT4, but I do not use it because I use all the indicators value as my NN input from MT4.
It should be not too much different either using indicator values from MT4 or NST, but the important point is in MT4 we get the indicator values at current bar while in NST we can get only the previous bar value (please correct me if I am wrong).
Other advantage is if we are using all data, indicator and NN firing in the same platform (MT4), we get benefit to remove any slippages or delay due to calculating process in NST and transferring the signals. That is why I use Neuroshell2 (not Neuroshell trader) to create the neural network dll and call it from MT4.
I get difficulties to use trained NN in NST if the NN inputs are coming from MT4, but it is possible to use indicators from NST and fire them in NST as well.

2. I know the back test result on MT4 not as good as NST, but I should accept it as long I do not have any other tools can be used. For your information, I took the data from trained NN from MT4 on 15 minutes time frame about 2500 data since 1999 (20% out of sample) and I implement to test it on 4H time frame after 2006. For me it can be considered as a full walk forward test. It give me a hints how a robustness of my trained NN (correct me if I am wrong).

Thank you for your sharing idea.

Arryex
 
Hi Kryzs,

Here are the answer your questions:
1. For me its simple, I use MT4 is my main data source because it's free (no subscription fee). The data coverage as well sufficient especially for forex analysis and multimarket analysis (with stock, index, etc) as basis for neural network. Demo account can be use as our paper trading and forward test, while waiting the proper trading strategy. You are correct we can use NST to send the trading order to MT4, but I do not use it because I use all the indicators value as my NN input from MT4.
It should be not too much different either using indicator values from MT4 or NST, but the important point is in MT4 we get the indicator values at current bar while in NST we can get only the previous bar value (please correct me if I am wrong).
Other advantage is if we are using all data, indicator and NN firing in the same platform (MT4), we get benefit to remove any slippages or delay due to calculating process in NST and transferring the signals. That is why I use Neuroshell2 (not Neuroshell trader) to create the neural network dll and call it from MT4.
I get difficulties to use trained NN in NST if the NN inputs are coming from MT4, but it is possible to use indicators from NST and fire them in NST as well.

2. I know the back test result on MT4 not as good as NST, but I should accept it as long I do not have any other tools can be used. For your information, I took the data from trained NN from MT4 on 15 minutes time frame about 2500 data since 1999 (20% out of sample) and I implement to test it on 4H time frame after 2006. For me it can be considered as a full walk forward test. It give me a hints how a robustness of my trained NN (correct me if I am wrong).

Thank you for your sharing idea.

Arryex



Thanks for Arryex and the other contributors.
Here are a few more bytes and questions on the subject.

Mt4 is indeed a very accessible system with tons of free data providers, huge community and lots publicly available documented experience.
My own problem with MT4 is its computational and programming limitations. For example, even if you manage to program a very fancy indicator that is heavier on resources, it will be extremely slow to backtest. Try testing an EA that includes Corona or other spectral indicators for example. In such cases you will have to give up the available intra-bar data and do with the lower quality MT4 backtesting options. Communicating with other systems is possible but very tedious.

It seems that many of the other alternatives like open quant and multi-charts aren't as prevalent and don't offer this attractive communal experience.
I therefore expect that it should be much harder to develop systems for them but assume that they offer many advantages (any experience of other members on this regard?)

I got to this thread because recently I've been considering NST. From what I understand this is a closed system in the sense that you can't really extract the internals of a trading strategy including its NN components. To me this is an obstacle (which I'm willing to overcome if I can really be convinced that it can generate for me $$ more efficiently). I imagine that this is also one of the attractions of Arryex Neuroshell 2, with which you are able to extract an all inclusive C routine. It also offers a fine control of the network learning process, which is a benefit if you know what you are doing.

One of my concerns regarding NST (including it's connectors to brokers) is that (as far as I understood) it doesn't provide sufficient flexibility to control money management.
Is that correct? Is it possible for example to program there an "EA" that trades according to Kelly fraction?

Your comments please.








I assume that some of these limitations will be alleviated with the forthcoming MT5, but we aren't there yet.
 
Thanks for Arryex and the other contributors.
Here are a few more bytes and questions on the subject.

Mt4 is indeed a very accessible system with tons of free data providers, huge community and lots publicly available documented experience.
My own problem with MT4 is its computational and programming limitations. For example, even if you manage to program a very fancy indicator that is heavier on resources, it will be extremely slow to backtest. Try testing an EA that includes Corona or other spectral indicators for example. In such cases you will have to give up the available intra-bar data and do with the lower quality MT4 backtesting options. Communicating with other systems is possible but very tedious.

It seems that many of the other alternatives like open quant and multi-charts aren't as prevalent and don't offer this attractive communal experience.
I therefore expect that it should be much harder to develop systems for them but assume that they offer many advantages (any experience of other members on this regard?)

I got to this thread because recently I've been considering NST. From what I understand this is a closed system in the sense that you can't really extract the internals of a trading strategy including its NN components. To me this is an obstacle (which I'm willing to overcome if I can really be convinced that it can generate for me $$ more efficiently). I imagine that this is also one of the attractions of Arryex Neuroshell 2, with which you are able to extract an all inclusive C routine. It also offers a fine control of the network learning process, which is a benefit if you know what you are doing.

One of my concerns regarding NST (including it's connectors to brokers) is that (as far as I understood) it doesn't provide sufficient flexibility to control money management.
Is that correct? Is it possible for example to program there an "EA" that trades according to Kelly fraction?

Your comments please.


I assume that some of these limitations will be alleviated with the forthcoming MT5, but we aren't there yet.

Hi Arry and trendick,

I believe such combination i.e. NS2 made net + MT4 is not good at all. The biggest disadvantage is lack of multithreading of MT4, lack of real time trade analysis, portfilio sizing and Money management. With this setup is also not possible to make Walk Forward analysis with cluster analysis.

I think the best combination will be to use Multicharts + MSA + Grail system.
Advantage wiil be full multithreading , WF optimizer build in, compatibile trade format wit MSA and compatiblility with Grail system.

FYI MSA - Market system Analyzer - makes real time trade analysis including MonteCarlo
analysis + Equity curve trading on single strategy and portfilio level www.adaptrade.com

Grail - www.thegrailsystem.com - its GO and WF analyzer capable to make cluster WF analysis. Another part called CASB is a genetic rule searcher.

Both those tools are compatibile with TS and MC.

For MC you can get also free FOREX data from forexite so its not a problem with it at all. MC is also capable to work with multiple data streams so it can use NN (dll) from NS2.

Krzysztof
 
Hi Arry and trendick,

I believe such combination i.e. NS2 made net + MT4 is not good at all. The biggest disadvantage is lack of multithreading of MT4, lack of real time trade analysis, portfilio sizing and Money management. With this setup is also not possible to make Walk Forward analysis with cluster analysis.

I think the best combination will be to use Multicharts + MSA + Grail system.
Advantage wiil be full multithreading , WF optimizer build in, compatibile trade format wit MSA and compatiblility with Grail system.

FYI MSA - Market system Analyzer - makes real time trade analysis including MonteCarlo
analysis + Equity curve trading on single strategy and portfilio level www.adaptrade.com

Grail - www.thegrailsystem.com - its GO and WF analyzer capable to make cluster WF analysis. Another part called CASB is a genetic rule searcher.

Both those tools are compatibile with TS and MC.

For MC you can get also free FOREX data from forexite so its not a problem with it at all. MC is also capable to work with multiple data streams so it can use NN (dll) from NS2.

Krzysztof

Hi Krzysztof,

These look like very interesting systems. Have you tried using this mix or any of the components? In any case, this discussion emphasizes a very important topic on its own, (which is off-subject in this thread): What would be the right mix of trading systems/components.
Although there us no "right choice" because it should match subjective requirements and constraints, I believe it can still pay off to consider the newer systems when they offer significant advantage. For example, if Grail is much faster then NS in its global optimization engine then it's worth considering switching and paying the big penalty
of studying it and coping with the usual hustles of every new system including bad documentation and bugs. Have you tried it?
In any case, it might be worth opening a dedicated thread that introduces new products and techniques with an attempt to generate a communal critical examination of their features. Is there already such a thread here or elsewhere?
From what I've seen here and on other Forex forums it seems that you are the right person to lead such a thread :).

Trendick
 
Hi Krzys,

Thanks for the information given, I am trace them seems quite interesting.

This is my case only, it may be due to the quality of internet in my place, I've used the data feeding from data feeder with other charting software, such as esignal as data feeder and NST or other for charting. I get some problems, i.e. slippage while displaying the data. Since then I try to avoid to use a different data feeder and charting software and prefer to have an integrated one. With MT4 I never have this problem, since the charting and data feeder is in one software.

I 've seen that Multichart, trade station need a different data feeder, multicharts lifetime license is $1497, it is good if we can integrate with MT4 otherwise we need to subscribe datafeeder.

For your proposed solution, we need tradestation, multicharts, Grail system, MSA and realtime data feeder. It is good to verify them as an integrated trading tools..

thank you
Arryex
 
I believe the main problem here is that with MT4 setup you are not able to verify
if you will make money or not.

I know the back test result on MT4 not as good as NST, but I should accept it as long I do not have any other tools can be used. For your information, I took the data from trained NN from MT4 on 15 minutes time frame about 2500 data since 1999 (20% out of sample) and I implement to test it on 4H time frame after 2006. For me it can be considered as a full walk forward test. It give me a hints how a robustness of my trained NN (correct me if I am wrong).

Such approach is not accurate enough. You dont know if optimization period and out of sample period are optimal, you also dont know how frequent to retrain/reoptimize.
This why Walk Forward cluster analysis can be used here.

You also dont know which MM method will me the most efficient for this strategy,
if there is a trade dependancy , if it passess MonteCarlo test etc.

All those answers you can find using MSA and Grail in this case.

Regarding my current set up. I'm using MC + MSA + Grail. As a data feed i use free
forexite data, so actually you can get this set up for free at least for 1 month
as you can take a trail of MC for one moth, trail of MSA and trail of Grail. After the trial
MC works OK offline so backtest is still possible.

Tradestation you dont need, you only need Global server which is part of TS package
but also stand alone application.

Regarding slippage....hmmmm you said that it is H4 TF than slippage should not matter so much here.

Krzysztof
 
Hi Kryzs,

I think it is good if you can show one of your trading strategy sample result (in forex or others), how you integrate your data feeder, training and walk forward test result, Monte Carlo test..etc.
1. Regarding data feeding, are you using realtime ASCII file transfer to feed your MC or manual transfer, which forexite data you are using, do you need additional software to transfer them.
2. Training and optimization, how long it takes?
3. Can you show us the sample pictures of those process? for example any steps that required, so I can easily to see your results.

Thank you & regards,
Arryex
How long you do the optimization, is it realtime data?
 
Hi Kryzs,

I think it is good if you can show one of your trading strategy sample result (in forex or others), how you integrate your data feeder, training and walk forward test result, Monte Carlo test..etc.
1. Regarding data feeding, are you using realtime ASCII file transfer to feed your MC or manual transfer, which forexite data you are using, do you need additional software to transfer them.
2. Training and optimization, how long it takes?
3. Can you show us the sample pictures of those process? for example any steps that required, so I can easily to see your results.

Thank you & regards,
Arryex
How long you do the optimization, is it realtime data?

1) I use real time forexite data feed. You can download small application from forexite
site which dowloads forex data to your PC. Than Global Server read this and transfers to MC. See enclosure.

2) For MC as it is multithread so all CPU cores are used so for quad core PC it is 4 times
faster than in NSDT. Additionally you can see optimization surface as a 3D picture
See this.

http://www.forex-tsd.com/indicators-metatrader-4/3479-all-john-ehlers-indicators-36.html#post329009

see post 351-353

In case you use Grail speed is about the same like in NSDT but Grail is very specialized application for this so you can see e.g. a lot of different equity curves and other parameters. Than trades files created by Grail GO are input for Grail WFA to make detailed WF analysis.

3) I will post some examples of reports and some screenshoots later this day.

Krzysztof
 

Attachments

  • Free_Forex_data for TradeStation 2000i.pdf
    550.2 KB · Views: 1,895
a few screens from MSA
 

Attachments

  • s1.JPG
    s1.JPG
    175.8 KB · Views: 2,164
  • s2.JPG
    s2.JPG
    111.4 KB · Views: 1,137
  • s3.JPG
    s3.JPG
    38.8 KB · Views: 1,063
It seems to me that the tools you use to build and test a system depend a lot on the stage of development. MT4 and an NS2 generated DLL should be adequate to simply try to test the robustness of a NN. But I'm not sure just what that means as explained below.

Regarding the slow speed of testing with MT4, I think this can be overcome using a DLL. e.g. a DLL to compute the Corona spectral indicators might speed things up a lot. The Net that Arryex uses would probably run very slowly if implemented in MLQ code. You can even multi thread the DLL if necessary.

It may be desireable to use other apps to make additional tests after the system has been developed and tweaked using MT4. And you may very well want to use a more rigorous test bed including MC, etc before you trade live. Krzysztof rightly points out some advantages of MC, MSA and the Grail.

But I have had enough talk of the tools. Each of us can select our own (the discussion so far has been very helpful in this regard). What about the concept? Does this EA backtest really verify that there are useful patterns in multiple markets? Do the patterns change with time? What is the best way to exploit the patterns if they exist? I am afraid that tests that use an EA may hide the true value, because they depend as much on the testing platform and the trading system as on the indicator.

I am initially concerned with two things:
1. How accurate are the predictions? (The mse is not a sufficient measure for me).

Suppose, for example that you could predict the next bar high and low perfectly. Then you could write an EA that entered at one extreme and exited at the other. A Holy Grail system!

But there are no such thing as perfect predictors. The question is, how large are the errors, and how are they distributed. e.g. if the 90% confidence intervals on the high and low predictions do not overlap for some set of values of predicted range, then one should be able to develop a trading system with controlled risk/reward ratio and controlled average gain per trade. There is no need for immediate testing with an EA, or for optimization. Such testing may easily hide the value of the prediction.

We do not need to rely on a difficult to program and understand platform for testing the error distribution. An Excel spread sheet will do the trick. However, we do need many predictions. I will volunteer to do the error measurements if Arryex will supply a file of at least 10000 predictions, or provide an indicator that can be used to make the predictions.

2. Are the errors stationary?
If the errors are not stationary, then it may be necessary to retrain the net periodically, or to use some form of adaption. This too can be measured with a spread sheet. If the mean and variance of the errors do not change with time or duration, then the errors are stationary enough. I know, I know, this is not the best, or even a complete test of stationarity, but it is good enough test to decide whether the Nets must be periodically retrained. I will also volunteer to make these measurements, because they are simple enough for me to grasp. We can all agree on what they mean. The performance of an EA is so dependent on the details of the EA that we probably would all disagree on what it meant.

Of course I would much prefer that you (Arryex) make the measurements, but if you are too busy, or not interested, then please post a file of the predicitions, or the indicator to make them.

Regards
Fralo...MadCow elsewhere.
 
Top