Geting data from LOWER TF problem. ArrayCopySeries, iHigh / iLow etc.

LastViking
27
LastViking  

I need to get some data from lower TF's in my indicator, I thoght ArrayCopySeries or iHigh / iLow would be the way too do it in MT but Im only geting old (64 hours) M1 data and a fantastically informative error message (4055 -> Custom indicator error) (Geting data from higher TF's this way works just fine however, buts thats not what i need). Anyone knows of a workaround?


Example code that dosn't work as I thoght it would (try on M5 or higher):

//+------------------------------------------------------------------+
#property copyright "Copyleft 2009, LV"
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
#property indicator_width1 2
#property indicator_maximum 2
#property indicator_minimum 1
//+------------------------------------------------------------------+
double Buffer[];
//+------------------------------------------------------------------+
int init() {

SetIndexStyle(0, DRAW_HISTOGRAM);
SetIndexBuffer(0, Buffer);

IndicatorShortName("BUG ");

return(0);
}
//+------------------------------------------------------------------+
int start() {

double M1High[];
datetime M1Time[];

int Error;

int j = 0;
while(j < 20) {
if(j != 0) Sleep(5000);
j++;
ArrayCopySeries(M1High, MODE_HIGH, NULL, PERIOD_M1); Error = GetLastError();
if(Error != 0) {
Print("Error: " + Error);
continue;
}
ArrayCopySeries(M1Time, MODE_TIME, NULL, PERIOD_M1); Error = GetLastError();
if(Error != 0) {
Print("Error: " + Error);
continue;
}

if((Time[0] - M1Time[0])/60 > 15) continue;
break;
}


Print(M1High[0] + " " + iHigh(NULL, PERIOD_M1, 0));
Print(M1Time[0] + " " + iTime(NULL, PERIOD_M1, 0));
Print("Data is " + (Time[0] - M1Time[0])/(60*60) + " Hours old");

return(0);
}

[Deleted]  

Hello LV,

my notes below are bit scatter gun'ish and most likely repeated more than once, but may help never the less.

.

Are sure is not ERR_HISTORY_WILL_UPDATED (4066 - the requested history data are under updating) ?

Which is very common and must be caught. Code should pause a bit and then retry,..., until no errors.

Object is to get the latest data. M1Time[0] must be latest possible otherwise the out of date data you get presently is possible.

You must verify this. Generally, >1 ACS() call will sort out this issue. Since your are only doing the default symbol, is strange that you experience issues. Also, 4055 I have never obtained (must be your lucky day :)

4066 you can handle. Docs tell you what I've basically said. Must pause then retry. Client Terminal requests so many bytes each time does request to server. That is shown by the increasing value given by ACS() after each call when doing retries do to 4066 and of course, your codes verifying that M1Time[0] actually is the latest M1 time associated with your default chart ie, predefined TimeSeries variable Time[0]

ClientTerminal on the loading of each EA allocates eleven predefines to the EA for easy access of default chart environment ie, ask,bars,bid,close,digits,high,low,open,point,time,volume. Also updated each time start() entered and programmatically via RefreshRates(), if say an error code indicates that data out of date, etc.

.

You should notice that the count of 'copied elements' grows each time you call ACS() Why? Client must update local history from Server and that can take time and not just a few milliseconds either.

You have an issue also because the call can complete OK but the data is not the latest. I see that you do not check to see how much data was returned. Is good idea to check function return values. eg, ACS() called - no error code - and even ACS() rets int value. So how can you determine IF data is latest?

hth

LastViking
27
LastViking  

Hi fbj,


Thanks for taking the time to reply.


Now this IS strange... As I was writing the reply belowe I just thougth I hade to try one more time, so I changed the name of the "M1High" & "M1Time" Array and everything works... Bugger.


It seems that I get in truble if two diffrent indicators uses the same name of the Array passed to ACS() at the same time (I guess this make sence as data aren't realy copyed by ACS()). I'l investigate some more, and if it's caled for I vill fill in a bug report.


/LV


Old reply:

Unfortunately it IS error 4055 i get (as you say, 4066 we can hadle). However if I try to load data from higher TF (like ataching the indi to M1 chart and load M5 data, rather then the other way a round) then it behave like one would expect (first we get error 4066, then, after data have been downloed everthing works).


Im lost (and bafeld at this). It dosen't make any sence too me at all (MT Bug maybe???). E'm I realy the first one trying to do this? I could not find anyting about this then searching the forum (only about loading data from higher TF's).

//

[Deleted]  

LV - good. But this can not be real. Two different programs having same variable names - each with their own data space. There must be some other explanation.

Is not rocket science for the MT crew. Only a redirection mapping is being done, nothing is transferred into your arrays.

LV, I would suggest you move the declarations of your arrays to the programs global scope outside any function.

Each time start() called, doing memory allocations for arrays that is really needed only once - at runtime loading.

Maybe longshot, but does not harm, yes?

Additionally, no disrespect to you but to be honest, MT is pretty solid. Personally, I have learned to always look and look again at my own code and interpretation of the systems documents.

Every time, I will eventually spot the issue and it is always 'my issue' not MT's.

.

Again, unless I not understand your reply, you state that just by using different names in two programs, ACS() appears to behave?

Cannot accept that at face value, sorry...

.

Bug report? Why? - MT'5' environment is fast approaching. Why would MT bother? MT4 is stable, many are sad to see it superseeded, many will most likely leave MT system altogether for newer pastures. But is believed that further MT4 maintenance is not on their agenda!

.

No, you are not the only one to use.

.

eg, I have any number symbols and period combinations EA that uses the 11 predefines and ACS() to emulate complete virtual chart environments and as required context switching, such that the main code modules do not have any attachment to the default chart. Once a virtual chart environment is mapped to and the required mappings loaded, the code works as if on default chart.

Never have encountered 4055.

.

However, due to syntax limitations in MQL4 and the desire to embrace fully the KISS principle, have regressed back to single EA = single CCY+period workings on xx charts etc.

.

The system is so much easier to maintain, modify etc....

.

good luck

Rafael
412
Rafael  

Arrays M1High and M1Time are not defined as ind. buffers.

double M1High[];
datetime M1Time[];

maybe you need to define size of array, before use:

eg.:

ArrayResize ( M1High, iBars(Symbol(), PERIOD_M1);

.

.

or

daclared as:

M1High[SomeIntValue]

[Deleted]  
rafaell:

Arrays M1High and M1Time are not defined as ind. buffers.

maybe you need to define size of array, before use:

eg.:

ArrayResize ( M1High, iBars(Symbol(), PERIOD_M1);

.

.

or

daclared as:

M1High[SomeIntValue]

Not needed. Have you read the documentation?

https://docs.mql4.com/array/ArrayCopySeries

Have you reviewed the MQL Book?

https://book.mql4.com//