| / | Articles |
Articles
Trading Systems
Using MetaTrader 4 for a Time Based Pattern Analysis
To post a new articles, please log in or register
|
Using MetaTrader 4 for a Time Based Pattern Analysis [ ru ]IntroductionReading posts at the Automated Trading Championship forum and interviews leads always to a lot of interesting information buried in a lot of noise. Searching LiteratureFirst of all I looked for the confirmation of this idea in literature and I found a very interesting article about this subject in "New Trading Systems and Methods" by Perry J. Kaufman, a really heavy bible in technical analysis adventure. Chapter 15 tells about pattern recognition, and one of the very first arguments is the time of day and trading habits. Implementing the Basic EAThe first consideration about implementing a system that should catch a trade direction at a specific time of the day, is that the only relevant signals you can look for are those that give you information about a trend direction, and that countertrend methods or breakout systems are not suitable for this purpose.
Operation and Optimization ResultsI use MetaTrader engine on Apple MacBookPro using a virtual pc running under Parallel Desktop where it runs fast and reliably and I can take fast snapshots of the MS-windows virtual machine very easily for documentation. Two different signals must agree to chose the right direction. //+------------------------------------------------------------------+ //| Price Direction Analyzer //+------------------------------------------------------------------+ int Analyzer() { int signalCount=0; signalCount += EntrySignal1(); signalCount += EntrySignal2(); return(signalCount); } //+------------------------------------------------------------------+ //| ENTRY SIGNALS BLOCK MODULES //+------------------------------------------------------------------+ int EntrySignal1() { // Long term SMA trend detect int i,Signal; int LongTrend=0; for(i=0;i<3;i++) { if (iMA(Symbol(),PERIOD_H4,S1_MA_FAST,0,MODE_LWMA,PRICE_TYPICAL,i) > iMA(Symbol(),PERIOD_H4,S1_MA_FAST,0, MODE_LWMA,PRICE_TYPICAL,i+1)) LongTrend++; else LongTrend--; } if( LongTrend < 0) Signal=-1; else Signal=1; return(Signal); } int EntrySignal2() { // Daily MACD int Signal; if (iMACD(NULL,PERIOD_D1,S2_OSMAFast,S2_OSMASlow,S2_OSMASignal,PRICE_WEIGHTED,MODE_MAIN,0) > iMACD(NULL,PERIOD_D1,S2_OSMAFast,S2_OSMASlow,S2_OSMASignal,PRICE_WEIGHTED,MODE_MAIN,1) ) Signal=1; else Signal=-1; return (Signal); } Trading hour is matched in a block trading filter module that can be simply realized as follows. Modular architecture described can easily leave space for new blocking filters in the operation flow. //+------------------------------------------------------------------+ //| FILTER BLOCK MODULES //+------------------------------------------------------------------+ bool BlockTradingFilter1() { bool BlockTrade=false; //trade by default if (UseHourTrade) { if( !(Hour() >= FromHourTrade && Hour() <= ToHourTrade && Minute()<= 3) ) { // Comment("Non-Trading Hours!"); BlockTrade=true; } } return (BlockTrade); } As a matter of fact we should be able to have a lot of small profit trades without considering the whole balance at all. Here is the main optimization setting: ![]() To analyze time intervals that give best results you must set the FromHourTrades from 0 to 23 running at step of 1 hour and check Optimization flag in the backtesting setting form before starting the process. ![]() Here are the optimization results: ![]() As you can see there are hours in which trading using trend detection techniques should be very dangerous, while during other day hours choosing trend direction should be considerably more profitable, and this time interval, between 19:00 and 22:00 GMT+1, the afternoon in Eastern Time zone, is when every news has been digested by the market. In this case, with available historic data, the peak hour obtained from optimization process corresponds to 21:00 GMT+1 (Central Europe Time). Sure this results should be considered valid for the 2007 forex market, but Frank Tubbs old consideration about trading habits let us hope they should be valid in larger time periods. And here are the detailed results from optimization process: ![]() You must consider that this results depend also on trending signals chosen to decide on the direction of orders, and I can tell you that in this time-based strategy, choosing from a large number of different signals leads to quite similar results, but surely you can test other signals and maybe let me know your results. And here are backtesting reports at 21:00 GMT+1 ![]() As you can see there are 160 total trades and 154 profit trades (96.86%). This information confirms the one made by Wackena in his interview. Introducing Time-Based Stop LossThe number of trades during one year backtesting process may suggest that we should be able to improve trading results by introducing a time based Stop Loss, that should leave room for new orders, if there are any losses after 23 hours being in the market.To do this you can simply set the UseTimeBasedStopLoss flag to true and try different optimization parameters. The following report table shows the consequence of this strategy change. ![]() As you can see this exit strategy lets you guess that some long swing trade, in a weak market, could protect you from adding undesirable orders in bad moments, so it should be better to be patient and wait till the market exits dangerous sideways. ConclusionThe strategy of analyzing time based pattern recognition on trading habits suggests further more investigation and justifies adding a valid money management strategy to this Expert Advisor and most of all a valid trailing stop engine, but this should be the argument of a new article.The code attached can also be used to make further investigation over other patterns and currency pairs to analyze other timely based trading habits and behavior. Just let me know your experience in this investigation. REFERENCES New Trading Systems and Methods, by Perry J. Kaufman http://championship.mql4.com/2007/news/316 The Encyclopedia of Trading Strategies, by Jeffrey Owen Katz,Donna L. McCormick Forex conquered, by J.L.Person Trading with the odds, by Cynthia A.Kase Warning:
All rights to these materials are reserved by MetaQuotes Software Corp.
Copying or reprinting of these materials in whole or in part is prohibited.
The actual Time Based Stop Loss is incorrect and it does not work for more than 23 hours.
This code should correct the problem considering closed trading hours too. It should be placed in BUY and SELL position. int k=0; while(k < TradeHoldingPeriod) { if(iTime(NULL,PERIOD_H1,k) > OrderOpenTime()) k++; else break; } if(UseTimeBasedStopLoss && k >= TradeHoldingPeriod && OrderProfit() < 0 ) { if(SignalCount > 0) OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); return(0); }
2008.02.15 13:13 giaras
giaras wrote:
Done.
Just a misunderstanding in publication work flow. It will be attached as soon as possible. thanks and best regards Giampiero
2008.02.06 08:20 Rosh
Erik.VH wrote:
Just a misunderstanding in publication work flow.Hi Giampiero,
Regards Erik
It will be attached as soon as possible. thanks and best regards Giampiero
2008.02.05 18:33 giaras
5 comments
|