Build Neural Network Indicator in MT4 using Neuroshell

This is a discussion on Build Neural Network Indicator in MT4 using Neuroshell within the Trading Software forums, part of the Commercial category; Originally Posted by arryex Anybody know about VantagePoint's Intermarket Anaylisis? As explained in the book "Trend Forecasting with Technical Analysis" ...

Reply
 
LinkBack Thread Tools Search this Thread
Old Jan 27, 2010, 6:52pm   #16
Joined Jan 2007
Re: Build Neural Network Indicator in MT4 using Neuroshell

Quote:
Originally Posted by arryex View Post
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. 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
fralo is offline   Reply With Quote
Old Jan 28, 2010, 2:31am   #17
Joined Feb 2008
Re: Build Neural Network Indicator in MT4 using Neuroshell

arryex started this thread 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.. I need some body to help me to convert the indicator to an EA...

Regards,
Arryex
Attached Thumbnails
figure2-map-nn.gif   posting-trading-idea-1.png  
arryex is offline   Reply With Quote
Old Jan 28, 2010, 6:15am   #18
Joined Jan 2007
Re: Build Neural Network Indicator in MT4 using Neuroshell

Quote:
Originally Posted by arryex View Post
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.. 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..
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.
fralo is offline   Reply With Quote
Old Jan 28, 2010, 6:40am   #19
Joined Feb 2008
Re: Build Neural Network Indicator in MT4 using Neuroshell

arryex started this thread 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
Attached Thumbnails
neural-indicators.png   aaneuro-trend-properties.png   aaneuro-classifier-properties.png  

aaneuro-trend-mq4.png  
arryex is offline   Reply With Quote
Old Jan 28, 2010, 7:18am   #20
Joined Jan 2007
Re: Build Neural Network Indicator in MT4 using Neuroshell

Quote:
Originally Posted by arryex View Post
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.


Quote:
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).

whiplash.jpg
fralo is offline   Reply With Quote
Old Jan 28, 2010, 7:57am   #21
Joined Feb 2008
Re: Build Neural Network Indicator in MT4 using Neuroshell

arryex started this thread 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
arryex is offline   Reply With Quote
Old Jan 28, 2010, 1:09pm   #22
Joined Feb 2008
Re: Build Neural Network Indicator in MT4 using Neuroshell

arryex started this thread 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

regards,
Arryex
Attached Thumbnails
classifier-ea-action.png  
Attached Files
File Type: mq4 Classifier.mq4 (2.2 KB, 1469 views)

Last edited by arryex; Jan 28, 2010 at 1:17pm.
arryex is offline   Reply With Quote
Thanks! The following members like this post: puiu288
Old Jan 28, 2010, 5:44pm   #23
Joined Jan 2007
Re: Build Neural Network Indicator in MT4 using Neuroshell

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
fralo is offline   Reply With Quote
Old Jan 29, 2010, 12:53am   #24
Joined Jan 2007
Re: Build Neural Network Indicator in MT4 using Neuroshell

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.BPNN.zip

Hope this helps.
Fralo
fralo is offline   Reply With Quote
Old Jan 29, 2010, 1:47am   #25
Joined Feb 2008
Re: Build Neural Network Indicator in MT4 using Neuroshell

arryex started this thread 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...

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
Attached Thumbnails
classifier-ea-action-2.png   crash-report1.png  

Last edited by arryex; Jan 29, 2010 at 2:04am. Reason: Add crash report when testing EA
arryex is offline   Reply With Quote
Old Jan 29, 2010, 5:34am   #26
Joined Jan 2007
Re: Build Neural Network Indicator in MT4 using Neuroshell

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
fralo is offline   Reply With Quote
Old Jan 29, 2010, 7:08am   #27
Joined Feb 2008
Re: Build Neural Network Indicator in MT4 using Neuroshell

arryex started this thread 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+Take Profit*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+Poi nt*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
Attached Thumbnails
uwc-demo.png  
arryex is offline   Reply With Quote
Old Feb 8, 2010, 3:39pm   #28
Joined Feb 2008
Re: Build Neural Network Indicator in MT4 using Neuroshell

arryex started this thread 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
Attached Files
File Type: pdf Test and result.pdf (255.4 KB, 1008 views)
arryex is offline   Reply With Quote
Old Feb 9, 2010, 5:17pm   #29
Joined Jan 2009
Re: Build Neural Network Indicator in MT4 using Neuroshell

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
Krzysiaczek99 is offline   Reply With Quote
Old Feb 10, 2010, 7:04am   #30
Joined Feb 2008
Re: Build Neural Network Indicator in MT4 using Neuroshell

arryex started this thread 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
arryex is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Neuroshell Cluster Indicator > Comments? Skyhr Forex 6 Nov 25, 2014 12:25pm
MTFeed Pro Neuroshell MT4 Input Orders Problem eurgbp Trading Software 3 Mar 24, 2010 3:13pm
Neural Network indicator - Any potential users? Flo_UniS Forex 5 Jan 15, 2009 8:27am
Neural Network Trading Models gs2004 Educational Resources 7 Sep 23, 2005 11:40pm

Currently Active Users Viewing This Thread: 4 (0 members and 4 guests)