//+------------------------------------------------------------------+ //| TestSymbolStochastic.mq4 | //| satori | //| http://www.metaquotes.ru/forum/7790/ | //+------------------------------------------------------------------+ #property copyright "satori" #property link "http://www.metaquotes.ru/forum/7790/" int handle; string filename="test_expert_log.csv"; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- handle= FileOpen(filename,FILE_CSV|FILE_WRITE,';'); if(handle<1) { Print("Файл не обнаружен, последняя ошибка ", GetLastError()); return(false); } //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- FileClose(handle); //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- double test1,test2,test3; int i; for (i=1;i<10;i++) { test1=iStochastic("GBPUSD",Period(),5,3,3,0,0,0,i); //test2=iStochastic("EURUSD",Period(),5,3,3,0,0,0,i); if (FileWrite (handle,TimeToStr(Time[i]),i,test1,test2)<=0) Print("Ошибка записи!"); } //---- return(0); } //+------------------------------------------------------------------+
It works for me (but I haven't checked the whole file)
Of course the problem is not closing the file, because as I said before I have faced with different values of indicator in the terminal and when called from the Expert Advisor. And then I drew the output to a file to study this "phenomenon".
In fact, it all worked on my other computer, too. However, it didn't work in the meantime.
I found it sufficient to add one more currency pair...
test1=iStochastic("GBPUSD",Period(),5,3,3,0,0,0,i); test2=iStochastic("EURGBP",Period(),5,3,3,0,0,0,i);
how the situation repeated itself
2006.10.22 22:00;1;74.83660131;19.04761905
2006.10.20 20:00;2;76.79738562;13.91304348
2006.10.20 16:00;3;78.13504823;25.26315789
2006.10.20 12:00;4;78.65853659;48.7804878
2006.10.20 08:00;5;80.50139276;81.57894737
2006.10.20 04:00;6;80.25974026;79.74683544
2006.10.20 00:00;7;86.36363636;74.66666667
2006.10.19 20:00;8;86.96969697;76.54320988
2006.10.19 16:00;9;80;79.22077922
2006.10.23 00:00;1;65.15151515;29.78723404
2006.10.22 22:00;2;74.83660131;19.67213115
2006.10.20 20:00;3;76.79738562;19.04761905
2006.10.20 16:00;4;78.13504823;13.91304348
2006.10.20 12:00;5;78.65853659;25.26315789
2006.10.20 08:00;6;80.50139276;48.7804878
2006.10.20 04:00;7;80.25974026;81.57894737
It can be seen that the first pair under the given conditions (!) works fine, however the second...
What's strange to me is that the problem is not systematic. The same code in seemingly similar conditions gives different results. The terminal is 198 everywhere. Tested on two different brokers. One of them is MIG.
Maybe the esteemed gentlemen developers will tell me how to fight this nasty thing?
If we do the following sampling,
string time1,time2,time3; for (i=1;i<10;i++) { time1=TimeToStr(iTime("GBPUSD",Period(),i)); time2=TimeToStr(iTime("EURGBP",Period(),i)); time3=TimeToStr(iTime("EURUSD",Period(),i)); if (FileWrite (handle,TimeToStr(Time[i]),i,time1,time2,time3)<=0) Print("Write error!"); }
I get the following:
2006.10.22 22:00;1;2006.10.22 22:00;2006.10.20 20:00;2006.10.22 22:00
2006.10.20 20:00;2;2006.10.20 20:00;2006.10.20 16:00;2006.10.20 20:00
2006.10.20 16:00;3;2006.10.20 16:00;2006.10.20 12:00;2006.10.20 16:00
2006.10.20 12:00;4;2006.10.20 12:00;2006.10.20 08:00;2006.10.20 12:00
2006.10.20 08:00;5;2006.10.20 08:00;2006.10.20 04:00;2006.10.20 08:00
2006.10.20 04:00;6;2006.10.20 04:00;2006.10.20 00:00;2006.10.20 04:00
2006.10.20 00:00;7;2006.10.20 00:00;2006.10.19 20:00;2006.10.20 00:00
2006.10.19 20:00;8;2006.10.19 20:00;2006.10.19 16:00;2006.10.19 20:00
2006.10.19 16:00;9;2006.10.19 16:00;2006.10.19 12:00;2006.10.19 16:00
2006.10.23 00:00;1;2006.10.23 00:00;2006.10.23 00:00;2006.10.23 00:00
2006.10.22 22:00;2;2006.10.22 22:00;2006.10.22 22:00;2006.10.22 22:00
2006.10.20 20:00;3;2006.10.20 20:00;2006.10.20 20:00;2006.10.20 20:00
From here on it is normal.
Sometimes the crash happens on one currency, sometimes on two. We have not been able to figure out the system. Either it depends on the computer power (although I ran it on a rather fast one), or it depends on something else.
But the fact is, testing is impossible. At the first accesses MT gives incorrect data.
The question remains: Is it a bug or a feature. :о) If it's a bug, how can I fight it? Maybe someone has faced such a problem?
the first print shows that the bar with the index 1 has become index 3, 2 has become index 4, moreover, it seems that you have started the Expert Advisor on H4, and the time 22:00 does not tell you anything
i would probably like to read the article about the simulation in the tester again, it would probably dot all the "i "s.
good luck, don't forget to report the results here ;)
P.S. alternatively you could try another version of the simulation and see the results, and there already some conclusions can be made
And this picture is also observed on other TFs (1H,30M,15M etc.) and different variants of price simulation (all three) still lead to the mentioned errors.
And there is nothing supernatural about the four o'clock bar at 22:00 - an ordinary "Sunday" bar. It does open at 22:00. Not all brokers cut the story, like Alpari for example. ;о)
However, the problem was localised even more. It turned out that this EA does not produce errors with all brokers. It is in those brokers that have "Sunday" data. Specifically, Alpari works normally, but FIBO and MIG have errors. And the errors appear only when we look at "Sunday" bars.
I don't think this is a "feature". It looks more like a bug. At least because the errors do not occur on the same pairs. It may occur at one moment on one pair, at another moment on another pair, and at the third moment on both pairs.
I still hope to attract developers' attention to this problem and get an answer from them: what is this problem and how to fight it ;o) (Don't tell me: "work with Alpari" :o))
P.S. In any case, thanks to Profi_R for participation, but as you see, simple solutions do not help, maybe I will have to go deep. :о)
#property copyright "Copyright Quark" #property link "" #property indicator_separate_window #property indicator_buffers 2 #property indicator_color2 Red #property indicator_minimum -1 #property indicator_maximum 1 // indicator parameters extern int nPeriod = 9; extern int nPeriod_1 = 6; // indicator buffers double dUsdChf, dUsdChfPrev; double arrGroupBuffer[]; double arrGroupMaBuffer[]; int nExtCountedBars = 0; //////////////////////// int init() { string strIndicatorShortName = "Group(" + Symbol() + " " + nPeriod + ")"; IndicatorShortName(strIndicatorShortName); // drawing settings SetIndexStyle(0, DRAW_NONE); SetIndexShift(0, 0); SetIndexStyle(1, DRAW_LINE); SetIndexShift(1, 0); IndicatorDigits(4); // indicator buffers mapping SetIndexBuffer(0, arrGroupBuffer); SetIndexBuffer(1, arrGroupMaBuffer); return(0); } /////////////////////////// int start() { if(Bars <= nPeriod) return(0); nExtCountedBars = IndicatorCounted(); if(nExtCountedBars < 0) return(-1); // last counted bar will be recounted // if(nExtCountedBars > 0) // nExtCountedBars--; int nPos = Bars - nExtCountedBars - 1; double dPr = 2.0 / (nPeriod + 1); while(nPos > 0) { if(!IsTesting()) { dUsdChf = iMA("USDCHF", 0, nPeriod, 0, MODE_EMA, PRICE_OPEN, nPos - 1); dUsdChfPrev = iMA("USDCHF", 0, nPeriod, 0, MODE_EMA, PRICE_OPEN, nPos); } arrGroupBuffer[nPos - 1] = 0; if(dUsdChfPrev - dUsdChf > 0) arrGroupBuffer[nPos - 1] += 1; else if(dUsdChfPrev - dUsdChf < 0) arrGroupBuffer[nPos - 1] -= 1; if(nPeriod_1 == 1) arrGroupMaBuffer[nPos - 1] = arrGroupBuffer[nPos - 1]; else { dPr = 2.0 / (nPeriod_1 + 1); arrGroupMaBuffer[nPos - 1] = arrGroupBuffer[nPos - 1] * dPr + arrGroupMaBuffer[nPos] * (1 - dPr); } nPos--; } return(0); }
There is little practical use for it as it does not lend itself to history testing (the second currency creates fantastic profits if the bars of the two histories are not synchronised, I've written about this before). But that's not the point.
As you can see from the code, the indicator does not depend on the currency it is attached to the chart. It always works for USDCHF. We attach the indicator to two charts, in my case AUDUSD and EURUSD, but I suppose we can attach it to any chart. We leave it for a few days. And we see that the charts are DIFFERENT. The same indicator. Real time. The same MT. Redraw forcibly (unhook - unhook) - they become the same. For some time.
I am tracing now and if I find anything, I will let you know. It may, of course, be because of me :)
The code (see below) takes (no matter which window the indicator is attached to) data from USDCHF, H1 and draws a graph a) Open, MA(Open, 6) and MA(Open, 6, calculated manually, without calling the standard indicator).
The indicator has been attached to EURUSD H1 and AUDUSD H1. After 12 hours of work the differences can be seen on the charts (mind you, the data is taken from USDCHF and there should not be any differences). Moreover, the differences are not in the MA, but exactly in the Open lines (of course, in the MA as well, but it is secondary, because of Open).
So there is a bug associated with using data from another currency. Dear developers?
#property copyright "Copyright Quark" #property link "" #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 Lime #property indicator_color2 Aqua #property indicator_color3 Red // indicator parameters extern int nPeriod = 6; double arrOpen[]; double arrMa[]; double arrMyMa[]; int nExtCountedBars = 0; double dUsdChf, dUsdChfPrev; //////////////////////// int init() { string strIndicatorShortName = "Test(" + Symbol() + " " + nPeriod + ")"; IndicatorShortName(strIndicatorShortName); // drawing settings SetIndexStyle(0, DRAW_LINE); SetIndexShift(0, 0); SetIndexStyle(1, DRAW_LINE); SetIndexShift(1, 0); SetIndexStyle(2, DRAW_LINE); SetIndexShift(2, 0); IndicatorDigits(4); // indicator buffers mapping SetIndexBuffer(0, arrOpen); SetIndexBuffer(1, arrMa); SetIndexBuffer(2, arrMyMa); return(0); } /////////////////////////// int start() { if(Bars <= nPeriod) return(0); nExtCountedBars = IndicatorCounted(); if(nExtCountedBars < 0) return(-1); int nPos = Bars - nExtCountedBars - 1; double dPr = 2.0 / (nPeriod + 1); while(nPos > 0) { dUsdChf = iMA("USDCHF", 0, nPeriod, 0, MODE_EMA, PRICE_OPEN, nPos - 1); dUsdChfPrev = iMA("USDCHF", 0, nPeriod, 0, MODE_EMA, PRICE_OPEN, nPos); arrOpen[nPos - 1] = iOpen("USDCHF", 0, nPos - 1); arrMa[nPos - 1] = dUsdChf; arrMyMa[nPos - 1] = arrOpen[nPos - 1] * dPr + arrMyMa[nPos] * (1 - dPr); nPos--; } return(0); }
First, the bigger the story, the bigger the errors.
Secondly, here's the code (apologies for the clumsiness of the code right away):
#property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 Red #property indicator_color2 Blue #property indicator_color3 Yellow //---- buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; extern int BarsCount=20; //кол-во считаемых баров, если 0 - то все extern string Currency1="EURUSD"; extern string Currency2="GBPUSD"; string Para; int TF; int handle,handle2; int init() { SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ExtMapBuffer1); SetIndexLabel(0,Currency1); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(1,ExtMapBuffer2); SetIndexLabel(1,Currency2); SetIndexStyle(2,DRAW_LINE); SetIndexBuffer(2,ExtMapBuffer3); string Para=Symbol(); int TF=Period(); handle= FileOpen("testfile.csv",FILE_CSV|FILE_WRITE,';'); handle2= FileOpen("testfile2.csv",FILE_CSV|FILE_WRITE,';'); if(handle<1 || handle2<1 ) { Print("Файл не обнаружен, последняя ошибка ", GetLastError()); return(false); } return(0); } int deinit() { FileClose(handle); return(0); } int start() { int counted_bars=IndicatorCounted(); int i; double test1,test2; datetime tt1,tt2; BarsCount=MathMin(Bars,(MathMin(iBars(Currency1,Period()),iBars(Currency2,Period())))); for (i=0;i<BarsCount-counted_bars;i++) { ExtMapBuffer1[i]=iTime(Currency1,Period(),i); Sleep(1000); ExtMapBuffer2[i]=iTime(Currency2,Period(),i); ExtMapBuffer3[i]=(ExtMapBuffer1[i]-ExtMapBuffer2[i]); tt1=Time[i]-ExtMapBuffer1[i]; tt2=Time[i]-ExtMapBuffer2[i]; if (ExtMapBuffer3[i]!=0 || tt1!=0 || tt2!=0) { if (FileWrite (handle, i,TimeToStr(Time[i]),TimeToStr(ExtMapBuffer1[i]),TimeToStr(ExtMapBuffer2[i]) )<=0) Print("нифига не пишет!!"); } FileFlush(handle); if ((iTime(Symbol(),Period(),i)!=iTime(Currency1,Period(),i) || Time[i]!=iTime(Currency1,Period(),i) || iTime(Currency1,Period(),i)!=iTime(Currency2,Period(),i) ) && i>0) { if (FileWrite (handle2, TimeToStr(Time[i])," ",TimeToStr(iTime(Currency1,Period(),i))," ",TimeToStr(iTime(Currency2,Period(),i)) )<=0) Print("нифига не пишет!!"); } } return(0); }
on the EURUSD and GBPUSD currency pairs, being run on EURGBP on 4H gives over 2000 errors
on 15M - over 26500.
And on 15M the shift is not one bar, but many, many more (over 100 (!) bars)
here is a piece of log:
15.06.2006 1:45 16.06.2006 0:45 16.06.2006 0:00
15.06.2006 1:30 16.06.2006 0:30 15.06.2006 23:45
15.06.2006 1:15 16.06.2006 0:15 15.06.2006 23:30
15.06.2006 1:00 16.06.2006 0:00 15.06.2006 23:15
15.06.2006 0:45 15.06.2006 23:45 15.06.2006 23:00
15.06.2006 0:30 15.06.2006 23:30 15.06.2006 22:45
15.06.2006 0:15 15.06.2006 23:15 15.06.2006 22:30
15.06.2006 0:00 15.06.2006 23:00 15.06.2006 22:15
14.06.2006 23:45 15.06.2006 22:45 15.06.2006 22:00
14.06.2006 23:30 15.06.2006 22:30 15.06.2006 21:45
14.06.2006 23:15 15.06.2006 22:15 15.06.2006 21:30
14.06.2006 23:00 15.06.2006 22:00 15.06.2006 21:15
14.06.2006 22:45 15.06.2006 21:45 15.06.2006 21:00
14.06.2006 22:30 15.06.2006 21:30 15.06.2006 20:45
This log was taken from Alpari server with fresh terminal and fresh history (before 3.10.2005 on 15M for all three currency pairs).
The point of all these investigations is to get an intelligible explanation of this phenomenon from developers.
And what confuses me is that I haven't heard a word from you, dear sirs, for about a week now.
I do not know how to prove the seriousness of the problem to you, so that you pay attention to it.
The transparent simplicity of the situation and the code prevents me from thinking about a trivial error. So I HEREBY PLEASE MAKE SURE PLEASE TO THE DESIGNERS:
Dear Sirs! I earnestly ask you to pay attention to this thread and give at least some comments on your part. If it's my mistake, please don't think it's my fault - at least tell me where to look for it. And in that case I will apologize for it. If it is an error in MT4 - then I think you should respect the time of people (not just me, I mean) that spend this precious resource in order to find and bring to your attention this situation, which actually is not their direct task.
With respect and hope for a constructive dialogue ... :о)
Almost twenty years ago, sitting in my dorm and stirring my tea in a circle with a spoon, I discovered that the image through the funnel became distorted. I immediately forgot the simple explanation and saw it as confirmation that water masses moving in a circle cause local changes of gravitation (and that explains disappearance of ships around the Bermuda Triangle) and consequently refraction of waves (light). This eclipse lasted a few minutes before I realised that it was a banal lens obtained from swirling water :)
I have changed your code slightly:
//+------------------------------------------------------------------+ //| RedrawIndicators.mq4 | //| Satori | //| http://www.metaquotes.ru/forum/7790/ | //+------------------------------------------------------------------+ #property copyright "Satori" #property link "http://www.metaquotes.ru/forum/7790/" #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 Red #property indicator_color2 Blue #property indicator_color3 Yellow //---- buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; extern int BarsCount=20; //кол-во считаемых баров, если 0 - то все extern string Currency1="EURUSD"; extern string Currency2="GBPUSD"; int handle,handle2; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ExtMapBuffer1); SetIndexLabel(0,Currency1); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(1,ExtMapBuffer2); SetIndexLabel(1,Currency2); SetIndexStyle(2,DRAW_LINE); SetIndexBuffer(2,ExtMapBuffer3); handle= FileOpen("TestFile.csv",FILE_CSV|FILE_WRITE,';'); handle2= FileOpen("TestFile2.csv",FILE_CSV|FILE_WRITE,';'); if(handle<1 || handle2<1 ) { Print("Файл не обнаружен, последняя ошибка ", GetLastError()); return(false); } else { FileWrite (handle,"index",Symbol(),Currency1,Currency2); FileWrite (handle2,"index",Symbol()," ",Currency1," ",Currency2); } return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- FileClose(handle); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); int i; double test1,test2; datetime tt1,tt2,TimeMain; BarsCount=MathMin(Bars,(MathMin(iBars(Currency1,Period()),iBars(Currency2,Period())))); for (i=0;i<BarsCount-counted_bars;i++) { TimeMain=Time[i]; ExtMapBuffer1[i]=iTime(Currency1,Period(),iBarShift(Currency1,Period(),TimeMain)); //Sleep(1000); ExtMapBuffer2[i]=iTime(Currency2,Period(),iBarShift(Currency2,Period(),TimeMain)); ExtMapBuffer3[i]=(ExtMapBuffer1[i]-ExtMapBuffer2[i]); tt1=Time[i]-ExtMapBuffer1[i]; tt2=Time[i]-ExtMapBuffer2[i]; if (ExtMapBuffer3[i]!=0 || tt1!=0 || tt2!=0) { if (FileWrite (handle, i,TimeToStr(Time[i]),TimeToStr(ExtMapBuffer1[i]),TimeToStr(ExtMapBuffer2[i]) )<=0) Print("нифига не пишет!!"); } FileFlush(handle); if ((iTime(Symbol(),Period(),i)!=iTime(Currency1,Period(),i) || Time[i]!=iTime(Currency1,Period(),i) || iTime(Currency1,Period(),i)!=iTime(Currency2,Period(),i) ) && i>0) { if (FileWrite (handle2,i, TimeToStr(Time[i])," ",TimeToStr(iTime(Currency1,Period(),i))," ",TimeToStr(iTime(Currency2,Period(),i)) )<=0) Print("нифига не пишет!!"); } }//---- return(0); } //+------------------------------------------------------------------+
So the question really sounds like this - why are they not the same, why are there holes in the history? I ran this indicator on GBPJPY H4 and opened the two resulting files.
You can see immediately that the timing is broken in two places and the second file shows a bunch of "errors"
PS Alpari quotes.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Please advise on the following problem.
Here is the code of the Expert Advisor.
The Expert Advisor runs on EURUSD with a quick simulation on the formed bars. It reads stochastic readings from another currency pair, eventually generating a report of the form:
2006.10.22 22:00;1;76.79738562
2006.10.20 20:00;2;78.13504823
2006.10.20 16:00;3;78.65853659
2006.10.20 12:00;4;80.50139276
2006.10.20 08:00;5;80.25974026
2006.10.20 04:00;6;86.36363636
2006.10.20 00:00;7;86.96969697
2006.10.19 20:00;8;80
2006.10.19 16:00;9;53.76884422
2006.10.23 00:00;1;65.15151515
2006.10.22 22:00;2;74.83660131
2006.10.20 20:00;3;76.79738562 and 78.13504823 (see above)
2006.10.20 16:00;4;78.13504823 and 78.65853659 (see above); etc.
2006.10.20 12:00;5;78.65853659
2006.10.20 08:00;6;80.50139276
2006.10.20 04:00;7;80.25974026
2006.10.20 00:00;8;86.36363636
2006.10.19 20:00;9;86.96969697
2006.10.23 04:00;1;52.85714286
2006.10.23 00:00;2;65.15151515
2006.10.22 22:00;3;74.83660131
2006.10.20 20:00;4;76.79738562
2006.10.20 16:00;5;78.13504823
2006.10.20 12:00;6;78.65853659
2006.10.20 08:00;7;80.50139276
2006.10.20 04:00;8;80.25974026
2006.10.20 00:00;9;86.36363636
2006.10.23 08:00;1;21.83406114
2006.10.23 04:00;2;52.85714286
2006.10.23 00:00;3;65.15151515
2006.10.22 22:00;4;74.83660131
2006.10.20 20:00;5;76.79738562
2006.10.20 16:00;6;78.13504823
2006.10.20 12:00;7;78.65853659
2006.10.20 08:00;8;80.50139276
2006.10.20 04:00;9;80.25974026
it's easy to see that the indicator values are different on the same bar on a new run.
I understand that practical use of this EA is doubtful :o) but the purpose was to show the problem. In practice it looks like this: in the terminal the indicator shows correctly, but when I call it from the Expert Advisor it shows wrong data. After cutting out everything that does not influence the indicator, we got the following result. I must be terribly dumb but cannot find my error.
By the way, if I change the currency pair to the current one, everything is OK.
I appreciate your help in advance.