Download MetaTrader 5

Load local history for iClose and iTime functions

To add comments, please log in or register
Oliver Mohr Bonometti
22
Oliver Mohr Bonometti  

I'm trying to run an algorithm over every symbol available. The problem is that if I want to get data with iClose for USDCAD for example, I need to have that chart open, otherwise I'll get 0 because local history hasn't been loaded. So far, I've been trying to Open and Close the symbol's chart programmatically to get that historic data loaded.

I'd like to know how to load that data (and getting rid of it so I don't run out of RAM) without having to open and close charts, so I can use those iClose and iTime functions.

Thanks.

Oliver Mohr Bonometti
22
Oliver Mohr Bonometti  

Ok, I think I figured it out myself. But I'm not sure if I'm fetching the data OK and free of mistakes. I just added this code lines bellow every iFunction i had on my script:


bananaValues[i] = iClose("BANANA", PERIOD_H1, i); //think i as an iteration variable
errorCode = GetLastError();
while (errorCode == 4073 || errorCode == 4066)
{
	Sleep(300);
	bananaValues[i] = iClose("BANANA", PERIOD_H1, i);
	errorCode = GetLastError();
}

Please comment if it's right, so other people can use this code too.

Thanks.

whroeder1
17111
whroeder1  
Oliver Mohr Bonometti: Please comment if it's right,
  1. Do not look at _LastError unless you have an error.
  2. Do not hard code constants, use the proper names/enumerations
  3. You must always RefreshRates, after blocking call (Sleep, web, or server calls.)
  4. Don't do the test there, do it once at the start of OnTick/OnCalcuate. Unless the chart is that specific pair/TF, you must handle 4066/4073 errors. See Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum
Oliver Mohr Bonometti
22
Oliver Mohr Bonometti  
whroeder1:
  1. Do not look at _LastError unless you have an error.
  2. Do not hard code constants, use the proper names/enumerations
  3. You must always RefreshRates, after blocking call (Sleep, web, or server calls.)
  4. Don't do the test there, do it once at the start of OnTick/OnCalcuate. Unless the chart is that specific pair/TF, you must handle 4066/4073 errors. See Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum
Sorry, I'm new to MQL4, so I have some doubts about what you said.

  1. But I can't know if I had an error or not. Didn't understand that point.
  2. Hardcoded "BANANA" for example, in my code it's a variable. The algorithm iterates over every symbol.
  3. The whole algorithm that's applied for any symbol needs a picture of the data and that data can't change over the execution time. It's really not that important if it's even 2 minutes lagged.
  4. What do you mean by test? Then you said "Unless the chart is that specific pair/TF, you must handle 4066/4073 errors", but I'm not using the charts. Didn't understand this point either.

Runtime Errors - Codes of Errors and Warnings - Standard Constants, Enumerations and Structures - MQL4 Reference
Runtime Errors - Codes of Errors and Warnings - Standard Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
Runtime Errors - Codes of Errors and Warnings - Standard Constants, Enumerations and Structures - MQL4 Reference
whroeder1
17111
whroeder1  
Oliver Mohr Bonometti:

  1. But I can't know if I had an error or not. Didn't understand that point.
  2. Hardcoded "BANANA" for example, in my code it's a variable. The algorithm iterates over every symbol.
  3. The whole algorithm that's applied for any symbol needs a picture of the data and that data can't change over the execution time. It's really not that important if it's even 2 minutes lagged.
  4. What do you mean by test? Then you said "Unless the chart is that specific pair/TF, you must handle 4066/4073 errors", but I'm not using the charts. Didn't understand this point either.

  1. Normally you look at your return codes (What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles,) but iClose doesn't have one. Look at the code I provided; I reset _LastError before the call.
  2. while (errorCode == 4073 || errorCode == 4066)
    What part of "hard code constants" was unclear? A variable is not a constant.
  3. Irrelevant babble.
  4. bananaValues[i] = iClose("BANANA", PERIOD_H1, i); 
    You are not using the charts? Of course you are.
  5. Insane babble. You previous said " I want to get data with iClose for USDCAD."

Oliver Mohr Bonometti
22
Oliver Mohr Bonometti  
whroeder1:
  1. Normally you look at your return codes (What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles,) but iClose doesn't have one. Look at the code I provided; I reset _LastError before the call.
  2. What part of "hard code constants" was unclear? A variable is not a constant.
  3. Irrelevant babble.
  4. You are not using the charts? Of course you are.
  5. Insane babble. You previous said " I want to get data with iClose for USDCAD."


1. Thanks for the tip. I've been using GetLastError() and I've seen that it's value differs from _LastError value. Why would that be?

4. Why do you say that? I recieve the data from all symbols in my script with all the Charts closed. Am I missing a concept here?

5. I previous said "I'm trying to run an algorithm over every symbol available. The problem is that if I want to get data with iClose for USDCAD for example (...)". I mean to iterate this algorithm over every available symbol in one run of the script.

whroeder1
17111
whroeder1  
Oliver Mohr Bonometti:

1. Thanks for the tip. I've been using GetLastError() and I've seen that it's value differs from _LastError value. Why would that be?

4. Why do you say that? I recieve the data from all symbols in my script with all the Charts closed. Am I missing a concept here?

5. I previous said "I'm trying to run an algorithm over every symbol available. The problem is that if I want to get data with iClose for USDCAD for example (...)". I mean to iterate this algorithm over every available symbol in one run of the script.

1. Impossible. Absolutely no difference. Perhaps you should read the manual.

GetLastError

Returns the contents of the

system variable _LastError.

GetLastError - Checkup - MQL4 Reference

4. You are missing the fact that any indicator, script, or EA must run on a chart. You can't run anything with all charts closed. Requesting data for other pairs/TF comes from other charts. If they are not currently open, they are opened (hidden,) then updated, they exist (for ten minutes after last access.)

5. You have repeated said that. So what? I gave you a link to my code with an example on how to wait for the other charts to update. Use it.

nicholishen
1547
nicholishen  
whroeder1:
1. Impossible. Absolutely no difference. Perhaps you should read the manual.

4. You are missing the fact that any indicator, script, or EA must run on a chart. You can't run anything with all charts closed. Requesting data for other pairs/TF comes from other charts. If they are not currently open, they are opened (hidden,) then updated, they exist (for ten minutes after last access.)

5. You have repeated said that. So what? I gave you a link to my code with an example on how to wait for the other charts to update. Use it.

4. I wasn't aware of that... I use copyrates instead with the exception of iBarshift and I have never had to open a chart. Would it be safe to say copyrates is exempt from those rules?
Oliver Mohr Bonometti
22
Oliver Mohr Bonometti  
nicholishen:
4. I wasn't aware of that... I use copyrates instead with the exception of iBarshift and I have never had to open a chart. Would it be safe to say copyrates is exempt from those rules?

Thanks for commenting nicholishen. I think CopyRates is what I need in my script. If you know anything about your question "Would it be safe to say copyrates is exempt from those rules?" please comment it on the thread.

To add comments, please log in or register