Is this for stock exchanges/indices? I am not sure what you are trying to get data for. If its indices then it may be because (just a guess) all of them are opening and closing simultaniously at different times and there will be gaps, missing bars or static prices. Other than that I do not know, you could try downloading more data from the history centre.
Run on currency pairs bro, used on a 1min chart. Its the bare bones code of my actual bot I use to test different price action patterns. Just taken the bling bling out for testing purposes.
My testing data is sourced from dukascopy, converted with tickstorylite and I test with Birts tickdata suite.
int OnInit(){ : spd4 = Time[10]; spd5 = Time[12];
You initialize these once when the EA is loaded instead of in start.
- You know the line, print the size of the array and the variables and track it down.
int OnInit(){ : spd4 = Time[10]; spd5 = Time[12];
You initialize these once when the EA is loaded instead of in start.
- You know the line, print the size of the array and the variables and track it down.
So I loaded the code with print() functions. Again in visual mode no problems, all the valves are returned as required. Yet still, during optimizing, the first pass runs no problems but then the error occurs. As the print() function doesn't work during optimizing I can't see what is happening there.
Any other suggestions???
The code is extracted from an indicator I have developed. I have attached it as it shows clearly what the code is identifying. Might make things more clearer
Since the Bar History Data is continually updating, how do you expect it to work in OnInit() when it is only called once when the code is initialised. The only way to keep getting the latest data is to check it in the OnTick(). In order to be efficient however, you should detect when I new bar is created and only then update these values.
The only way to keep getting the latest data is to check it in the OnTick(). In order to be efficient however, you should detect when I new bar is created and only then update these values.
This is the part I am having trouble getting my head around. Because the value of the variable is set here (calculated on the new bar)
switch(boxNo) { case 4: spd4=Time[i];break; case 5: spd5=Time[i];break; case 6: spd6=Time[i];break; case 7: spd7=Time[i];break; case 8: spd8=Time[i];break;
If I loaded the value OnTick() won't it just reset back to this value on each tick. Because of the price pattern this code detects once this "spd4..." value is set it needs to hold this valve as each new bar is formed until the price action is void.
This is the part I am having trouble getting my head around. Because the value of the variable is set here (calculated on the new bar)
If I loaded the value OnTick() won't it just reset back to this value on each tick. Because of the price pattern this code detects once this "spd4..." value is set it needs to hold this valve as each new bar is formed until the price action is void.
The root of the problem, is that your whole approach seems incorrect and adhoc (in my opinion, as I still don't understand what it is you are trying to achieve). In my own opinion, you should rewrite your entire code from scratch and in a more structured way (as it is very "stringy"), but only once you understand the underlying principals of how the MQL environment works.
- OnInit() only gets called when the code is first initialised (eg. when the EA is attached to the chart).
- OnTick() gets called on every new tick (in real trading however, some get skipped).
- On every new tick (not necessarily on every OnTick() event), there will be updates to Volume[0], Close[0], and if applicable, to High[0] or Low[0]. There will be no change to Open[0], Time[0] and all the other [i] instances, as they remain the same (provided no new bar is formed, see next point).
- When the new tick is for a new bar forming, then all the previous [0] data moves on over to the [1] position, and [1] to [2], and [2] to [3], etc. and a new bar is created at [0] with Open[0]=Close[0]=High[0]=Low[0]=Bid and Volume[0]=1 and Time[0]=CurrentTime.
- Incidentally, that is how you detect a new bar, when Time[0] changes, as you have correctly coded.
- With regards to all your "spd#" variables, use arrays and loops instead.
- As it is, it looks a mess - it is long and "stringy" and is difficult to read or understand what it is you are trying to accomplish.
EDIT: PS! It may be easier and probably more correct and efficient, for you to first code an Indicator to detect and signal all the so called "boxes", and then to call that logic from "iCustom". That way you can visually test and make sure your Indicator logic is working correctly, before you start worrying about the order and trade management of an EA with the added bonus that you will be able to use the Indicator for manual trading and visualisation, independently of the EA.
What part of "in start" was unclear? Old style start, new style onTick. Perhaps you need to read the documentation. Event Handling Functions - Functions - Language Basics - MQL4 Reference |
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
So I run this code in strategy tester
When I run a visual test in strategy tester works fine (to the best of my very limited programming ability). However when I do optimizing runs, more often than not, I receive the following errors after the first pass
So its blaming this bit of code
This error occurs solely based on the start date for each run. Some start dates it works fine, most won't and it makes it annoying cause one can't do in sample and out of sample back testing. Can someone help with what's going wrong