New article How to Order an Expert Advisor and Obtain the Desired Result is published:
Author: Andrey Khatimlianskii
New article How to Order an Expert Advisor and Obtain the Desired Result is published:
Author: Andrey Khatimlianskii
I already posted this question in the discussion section of an article about backtesting (http://www.mql5.com/en/forum/2309), but no one has responded so I'll post it here.
Is there a way to access the functionality of metatrader's genetic optimizer in code without having to manually run the optimization from the backtesting terminal?
What I'm looking for is a way to optimize an EA on the fly using mql. There has been mention of being able to do this with matlab interaction (http://www.mql5.com/en/articles/44), but I'm not familiar with matlab and therefore this would be quite difficult. Any help/recommendations with on the fly optimization would be greatly appreciated.
The other question I have concerns backtesting tick data. Currently I'm developing EAs and backtesting them using MT5 with a metaquotes demo account, but I'm not sure how accurate the backtesting tick data is. After looking at some simple output of prices during backtesting, it looks like the spreads might not be accurate during backtesting. Can anyone tell me how accurate this tick data is and if it isn't accurate, could someone tell me if it's possible to get accurate tick data?
Thank You.
SERIES_SYNCHRONIZED
not
It's A Miss Spelling In The candlestick_patterns.mq5 file
Hi,
this is something i am trying to achieve also.
First i would like to state that lots of stuff is possible in MT5, and this is also documented somewhere, but rather hard to find.
I don't know if you have found a .xml file in MT5\tester\cache\ that contains all calculations of every iteration.
This is something i am doing in DeInit(), analysing the complete pass and writing the information in a tester\file\ directory,
as there are some calculations that are not done and i am using it.
MT5 offers following methods:
OnTester methods (OnTester/Init/DeInit/Pass) and Frame methods.
At the moment i am trying to find a way how to use this methods to have a complete log of all iterations with all results.
However it is clear out of documentation: On cloud metatester, logging/file writing/dll's are not allowed.
Consequence is that the cache file (all results compiled) is not filled out completely with informations from iterations done on cloud.
I have tried out this and this needs to be changed.
IMO, methods that will fill out the .xml table with additional data, and also from cloud are ESSENTIAL AND NECESSARY.
Also, in MT4 there is an auxiliary list of optimization parameters for the inputs which will stop an optimization pass if a value is exceed. For example, maximum % drawdown can be set and the tester will automatically skip to the next pass if the current pass exceeds that value at any time.
Cant you use "continue", to skip to the next pass? I would like to know if there is a function to reffer to the %drawdown...
As recently as one month ago, MetaTrader 5 Android received full set of technical indicators providing traders with a powerful tool. The new version of the mobile application allows traders to use even more diverse functionality. We have implemented "Crosshair" mode and the ruler for more convenience. Besides, the system security has been improved by extended authorization using SSL certificates.
Image may be NSFW.
Clik here to view.
After downloading the application,
Android users receive the powerful tool for secure trading in the
financial markets. Trading, market analysis using charts and indicators,
tracking the quotes, viewing the history of performed deals - all that
can be done quickly right via your smartphone or tablet PC at any place
and at any time!
Hi all,
when i am doing a genetic based forward testing with balance max criteria, in the the optimization results tab, i get columns:
Forward -> Final Balance in forward test
Backtest -> Final Balance in backward test
Profit -> Profit in forward test
However, if i repeat the test with custom max criteria (using OnTester()), i get:
Forward -> results of OnTester in forward test, i.e. custom criteria
Backtest -> ????
Profit -> Profit in forward test
Another bug or i overlooked something?
Hi,
I came across a strange behavior of timer which I cannot comprehend.
When I run the following simple EA:
int period = 1800; // 0.5 hour int OnInit() { bool r = EventSetTimer(period); Print("Set Timer to ", period, " seconds. Result: ", r); return(0); } void OnDeinit(const int reason) { EventKillTimer(); } void OnTimer() { Print("Timer"); EventKillTimer(); period += 1800; if(period <= 3*3600) // 3 hours { bool r = EventSetTimer(period); Print("Set Timer to ", period, " seconds. Result: ", r); } }
I receive the expected behavior, i.e. OnTimer() function is called with expected increasing periods from 0.5 h to 3 h:
2012.10.29 18:05:08 2012.10.15 10:30:00 Timer 2012.10.29 18:04:56 2012.10.15 07:30:00 Set Timer to 10800 seconds. Result: true 2012.10.29 18:04:56 2012.10.15 07:30:00 Timer 2012.10.29 18:04:47 2012.10.15 05:00:00 Set Timer to 9000 seconds. Result: true 2012.10.29 18:04:47 2012.10.15 05:00:00 Timer 2012.10.29 18:04:39 2012.10.15 03:00:00 Set Timer to 7200 seconds. Result: true 2012.10.29 18:04:39 2012.10.15 03:00:00 Timer 2012.10.29 18:04:33 2012.10.15 01:30:00 Set Timer to 5400 seconds. Result: true 2012.10.29 18:04:33 2012.10.15 01:30:00 Timer 2012.10.29 18:04:29 2012.10.15 00:30:00 Set Timer to 3600 seconds. Result: true 2012.10.29 18:04:29 2012.10.15 00:30:00 Timer 2012.10.29 18:04:27 2012.10.15 00:00:00 Set Timer to 1800 seconds. Result: true
However, when I reverse the logic to decreasing periods:
int period = 3*3600; int OnInit() { bool r = EventSetTimer(period); Print("Set Timer to ", period, " seconds. Result: ", r); return(0); } void OnDeinit(const int reason) { EventKillTimer(); } void OnTimer() { Print("Timer"); EventKillTimer(); period -= 1800; if(period >= 1800) // 0.5 hour { bool r = EventSetTimer(period); Print("Set Timer to ", period, " seconds. Result: ", r); } }
I get the following output:
2012.10.29 18:11:10 2012.10.15 11:30:00 Timer 2012.10.29 18:11:08 2012.10.15 11:00:00 Timer 2012.10.29 18:11:08 2012.10.15 10:30:00 Timer 2012.10.29 18:11:04 2012.10.15 10:00:00 Set Timer to 1800 seconds. Result: true 2012.10.29 18:11:04 2012.10.15 10:00:00 Timer 2012.10.29 18:11:00 2012.10.15 09:00:00 Set Timer to 3600 seconds. Result: true 2012.10.29 18:11:00 2012.10.15 09:00:00 Timer 2012.10.29 18:10:54 2012.10.15 07:30:00 Set Timer to 5400 seconds. Result: true 2012.10.29 18:10:54 2012.10.15 07:30:00 Timer 2012.10.29 18:10:46 2012.10.15 05:30:00 Set Timer to 7200 seconds. Result: true 2012.10.29 18:10:46 2012.10.15 05:30:00 Timer 2012.10.29 18:10:37 2012.10.15 03:00:00 Set Timer to 9000 seconds. Result: true 2012.10.29 18:10:37 2012.10.15 03:00:00 Timer 2012.10.29 18:10:25 2012.10.15 00:00:00 Set Timer to 10800 seconds. Result: true
Where do these extra calls to OnTimer come from? It seems that the first calls to function EventKillTimer() are not effective.
Is it a bug or am I missing something here?
Tested on build 712.
sfc /scannow is prematurely terminating at 23%.
Does this mean I have to reinstall the whole OS?
// copying of next part forces data loading int copiedTimes = CopyTime(symbol, period, count, arraySize, times); int copiedRates = CopyRates(symbol, period, count, arraySize, rates);
I was surprised to find that 2000 - 2008 only has daily data; 2009 has hourly, and 2010 has hourly up until 7th April, and then minute bars from then until today.
So I then contacted my broker (Alpari UK) and their response was:
No unfortunately this is not possible, it’s a colossal amount of data you are trying to download. On MT5 it is possible on some currency pairs, but even then the data can sometimes be incomplete if you are trying to download such a vast amount of information which we do not support.
They suggested I try contact MetaQuotes.
I just find it so hard to believe that this is not supported.
If I go to the history folder (MetaQuotes\Terminal\...\bases\AlpariUK-MT5\history\EURUSD), the entire history for 2011 is 15MB. For ~15MB of data per year, I don't think it's that colossal to be honest.
In any event, I'm finding it hard to believe that Alpari and/or MetaTrader doesn't support back-testing before 2010, because it's just such a fundamental part of automated trading.
Is this a technical shortcoming, or is it the way Alpari has configured their server?
On a related note, does anyone know of an MT5 broker who does support minute bars back to 2000?
My script:
#property script_show_inputs input string InpLoadedSymbol="GBPUSD"; // Symbol to be load input ENUM_TIMEFRAMES InpLoadedPeriod=PERIOD_M1; // Period to be load input datetime InpStartDate=D'2000.01.01'; // Start date #include <Files\FileTxt.mqh> void OnStart() { Print("Start load",InpLoadedSymbol+","+GetPeriodName(InpLoadedPeriod),"from",InpStartDate); int res=CheckLoadHistory(InpLoadedSymbol,InpLoadedPeriod,InpStartDate); switch(res) { case -1 : Print("Unknown symbol ",InpLoadedSymbol); break; case -2 : Print("Requested bars more than max bars in chart"); break; case -3 : Print("Program was stopped"); break; case -4 : Print("Indicator shouldn't load its own data"); break; case -5 : Print("Load failed"); break; case 0 : Print("Loaded OK"); break; case 1 : Print("Loaded previously"); break; case 2 : Print("Loaded previously and built"); break; default : Print("Unknown result"); } datetime firstDate; SeriesInfoInteger(InpLoadedSymbol,InpLoadedPeriod,SERIES_FIRSTDATE,firstDate); int bars=Bars(InpLoadedSymbol,InpLoadedPeriod); Print("First date ",firstDate," - ",bars," bars"); } //------------------------------------------------------------------ int CheckLoadHistory(string symbol,ENUM_TIMEFRAMES period,datetime startDate) { if (symbol==NULL || symbol=="") symbol=Symbol(); if (period==PERIOD_CURRENT) period=Period(); // check if symbol is selected in the MarketWatch if (!SymbolInfoInteger(symbol, SYMBOL_SELECT)) { if (GetLastError() == ERR_MARKET_UNKNOWN_SYMBOL) return -1; SymbolSelect(symbol,true); } datetime firstDate=0; CFileTxt file; file.Open("out.txt", FILE_WRITE); #define arraySize 100 datetime times[arraySize]; MqlRates rates[arraySize]; // max bars in chart from terminal options int maxBars = TerminalInfoInteger(TERMINAL_MAXBARS); // load symbol history info datetime firstServerDate = 0; while (!SeriesInfoInteger(symbol, PERIOD_M1, SERIES_SERVER_FIRSTDATE, firstServerDate) && !IsStopped()) Sleep(5); // fix start date for loading if (firstServerDate > startDate) startDate = firstServerDate; if (firstDate > 0 && firstDate < firstServerDate) Print("Warning: first server date ",firstServerDate," for ",symbol," does not match to first series date ",firstDate); if (file.WriteString("date,open,low,high,close\n") <= 0) printf("error writing to file"); // load data step by step int failCount = 0; int count = 0; while(!IsStopped()) { // wait for timeseries build while(!SeriesInfoInteger(symbol, period, SERIES_SYNCHRONIZED) && !IsStopped()) Sleep(5); // copying of next part forces data loading int copiedTimes = CopyTime(symbol, period, count, arraySize, times); int copiedRates = CopyRates(symbol, period, count, arraySize, rates); // write times and rates to file for (int i = copiedRates - 1; i >= 0; --i) { string line = TimeToString(times[i]) + "," + DoubleToString(rates[i].open) + "," + DoubleToString(rates[i].low) + "," + DoubleToString(rates[i].high) + "," + DoubleToString(rates[i].close) + "\n"; if (file.WriteString(line) <= 0) printf("error writing to file"); } if (copiedRates > 0) { // check for data if (times[0] <= startDate) return 0; if (0 + copiedTimes >= maxBars) return -2; failCount = 0; count += arraySize; } else { // no more than arraySize failed attempts failCount++; if (failCount >= arraySize) return -5; Sleep(10); } } return -3; } //------------------------------------------------------------------ string GetPeriodName(ENUM_TIMEFRAMES period) { if (period==PERIOD_CURRENT) period=Period(); switch(period) { case PERIOD_M1: return "M1"; case PERIOD_M2: return "M2"; case PERIOD_M3: return "M3"; case PERIOD_M4: return "M4"; case PERIOD_M5: return "M5"; case PERIOD_M6: return "M6"; case PERIOD_M10: return "M10"; case PERIOD_M12: return "M12"; case PERIOD_M15: return "M15"; case PERIOD_M20: return "M20"; case PERIOD_M30: return "M30"; case PERIOD_H1: return "H1"; case PERIOD_H2: return "H2"; case PERIOD_H3: return "H3"; case PERIOD_H4: return "H4"; case PERIOD_H6: return "H6"; case PERIOD_H8: return "H8"; case PERIOD_H12: return "H12"; case PERIOD_D1: return "Daily"; case PERIOD_W1: return "Weekly"; case PERIOD_MN1: return "Monthly"; } return "unknown period"; } //------------------------------------------------------------------
In the below code, if no price is specified the code will use the market ask price.
Surely this should be the bid if we're going short?
double CExpertMoney::CheckOpenShort(double price, double sl) { if(m_symbol == NULL) { return(0.0); } //--- double lot; if(price == 0.0) { lot = m_account.MaxLotCheck(m_symbol.Name(), ORDER_TYPE_SELL, m_symbol.Ask(), m_percent); // <--- Here, should it not be m_symbol.Bid() ? } else { lot = m_account.MaxLotCheck(m_symbol.Name(), ORDER_TYPE_SELL, price, m_percent); } if(lot < m_symbol.LotsMin()) { return(0.0); } //--- return(m_symbol.LotsMin()); }
Anton, please tell us a little about yourself. This is your first championship, but apparently you have a rich experience in trading.
Yes, this is indeed my first Championship. I have worked as a software developer for the past 20 years in the engineering, medical, educational and financial sectors. In my personal capacity I have been trading online for the past 10 years. My love for finance and software development makes the perfect combination for the development of automated trading systems. In my spare time, I enjoy sports. My favorite sport at the moment is Squash, and I play 3-4 times a week.
Judging by deals, your EA is always in the market. It also does averaging if price is going in wrong direction. Does it enter the market by oversold/overbought CCI? Why do you use Heiken Ashi?
I have experimented with different Expert Advisors, but chose to enter current one for the competition, because it stays in the market, so there are no "dead" moments. Something is always happening. If the price goes in the wrong direction, I work on averaging or Stop Loss depending on the situation.
I use oversold/overbought CCI to enter the market and Heiken Ashi to exit. Heiken Ashi performed better than CCI on the back test, so that's why I opted to go with that indicator to exit the market.
The full text of the news can be found at the Championship's website - Interview with Anton Nel (ROMAN5).
Author: Nikolay Kositsin
Author: Nikolay Kositsin
Hi
How can I close some of volume(lot) a position?
Equivalent OrderClose(OrderTicket(),0.01,Ask,3,Violet) in mql4.
Const ulong 'percent' stores the percentage value of the position to close out first. When calling PositionClose() without stating a percent of the total volume to close, PositionClose() will attempt close out 100%, as normal. Also refer to line 329 and line 367. You will need to modify your EA ( the order close loop ) and perhaps include a scalar to block or permit the partial close. See the code segments below:
if(GetPositionInfo(symbol,pos)) // save data about pos { //--- close by time if(close_all) { Print("close_all:",close_all); if(m_trade.PositionClose(symbol)) { close_all=false; alreadyPartClosed = false; recalc=true; } return; } if(part_close) { Print("part_close:",part_close); if(m_trade.PositionClose(symbol, partially_exit_param.exit_percent)) { part_close=false; alreadyPartClosed = true; recalc=true; } return; }
//--- close percent of position volume by first trigger line if(bid>=BuyCloseBuffer[0] && !alreadyPartClosed) { if (partially_exit_param.scale_out && ScaleOutSignal) { part_close = true; return; } else { close_all=true; return; } } //--- close remaining position volume by second trigger line if(alreadyPartClosed && bid>=BuyCloseBuffer2[0]) { close_all = true; return; }
The above code is just an example, but I run a very similar EA and it works fine.
Chris_V