You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
That makes sense but let me ask you this... I'm populating my arrays in the OnInit() function but then I'm reading from and testing those arrays in the OnTick() function, so during the the OnInit() doesn't the array just get populated once? Im thinking it must because I only size it for 9 elements and anything more than 9 would error out. So when we get to the OnTick() function the array only contains eight elements correct? Or am I not understanding the flow of my program?
Take this as you would from someone who has little MQL specific coding experience, but some other programming language experience. Mostly because that is the case here.
I believe that the OnInit function is called each time that the EA (or other code that contains it) is initialized, as the name would suggest. What all the things are that set off that event I do not know. If it is not every time a new bar is generated, then you would need to do the update method if you wanted to use it as your source of accurate information. But on that note, while doing research, there is an ArrayCopy function that you could possibly make use of in the situation I proposed above if you need to update the information.
Sorry if you already know the following, but I am not sure the knowledge level you have regarding arrays, and do not want to miss something small but vital.
You can populate an array at any time, as long as it is before you try to read information from it. If you are saying you want it to hold 9 places, then it can be made with 9. The index for the last place would be 8. I think that as long as you populate the arrays in there with the latest information you should be alright, as long as every time a new bar comes in, it reinits the EA. When I posted that, I had forgotten about the fact that EAs are not usually open as long as a regular program might be. You would also have to adjust my example above to include one more element.
In an array, the computer usually sets it up by a numbering system (the index) so that it can easily access the info stored in each "box". However, because it is a computer, it usually starts counting that index at zero, not like humans would and count the first box as box 1. That is why you will see for loops, they are excellent for stepping through an array, among other things you need a counted process for. https://www.mql5.com/en/articles/567 has some info on arrays in case I missed anything. Trying to count past either end of the array's index will end up giving you an array index out of bounds error.In theory you could have 300 places within an array. Are you intentionally only giving it 9 spots or does it cause errors if you make it more than the 9? If there is something else that is causing you errors if you try to make more than 9 spots, that is another issue. But since you should try to keep your code (and memory usage) as minimal as you can to reduce operation time, you should only make the arrays and everything else as small as you can.
Take this as you would from someone who has little MQL specific coding experience, but some other programming language experience. Mostly because that is the case here.
I believe that the OnInit function is called each time that the EA (or other code that contains it) is initialized, as the name would suggest. What all the things are that set off that event I do not know. If it is not every time a new bar is generated, then you would need to do the update method if you wanted to use it as your source of accurate information. But on that note, while doing research, there is an ArrayCopy function that you could possibly make use of in the situation I proposed above if you need to update the information.
Sorry if you already know the following, but I am not sure the knowledge level you have regarding arrays, and do not want to miss something small but vital.
You can populate an array at any time, as long as it is before you try to read information from it. If you are saying you want it to hold 9 places, then it can be made with 9. The index for the last place would be 8. I think that as long as you populate the arrays in there with the latest information you should be alright, as long as every time a new bar comes in, it reinits the EA. When I posted that, I had forgotten about the fact that EAs are not usually open as long as a regular program might be. You would also have to adjust my example above to include one more element.
In an array, the computer usually sets it up by a numbering system (the index) so that it can easily access the info stored in each "box". However, because it is a computer, it usually starts counting that index at zero, not like humans would and count the first box as box 1. That is why you will see for loops, they are excellent for stepping through an array, among other things you need a counted process for. https://www.mql5.com/en/articles/567 has some info on arrays in case I missed anything. Trying to count past either end of the array's index will end up giving you an array index out of bounds error.In theory you could have 300 places within an array. Are you intentionally only giving it 9 spots or does it cause errors if you make it more than the 9? If there is something else that is causing you errors if you try to make more than 9 spots, that is another issue. But since you should try to keep your code (and memory usage) as minimal as you can to reduce operation time, you should only make the arrays and everything else as small as you can.
Take this as you would from someone who has little MQL specific coding experience, but some other programming language experience. Mostly because that is the case here.
I believe that the OnInit function is called each time that the EA (or other code that contains it) is initialized, as the name would suggest. What all the things are that set off that event I do not know. If it is not every time a new bar is generated, then you would need to do the update method if you wanted to use it as your source of accurate information. But on that note, while doing research, there is an ArrayCopy function that you could possibly make use of in the situation I proposed above if you need to update the information.
Sorry if you already know the following, but I am not sure the knowledge level you have regarding arrays, and do not want to miss something small but vital.
You can populate an array at any time, as long as it is before you try to read information from it. If you are saying you want it to hold 9 places, then it can be made with 9. The index for the last place would be 8. I think that as long as you populate the arrays in there with the latest information you should be alright, as long as every time a new bar comes in, it reinits the EA. When I posted that, I had forgotten about the fact that EAs are not usually open as long as a regular program might be. You would also have to adjust my example above to include one more element.
In an array, the computer usually sets it up by a numbering system (the index) so that it can easily access the info stored in each "box". However, because it is a computer, it usually starts counting that index at zero, not like humans would and count the first box as box 1. That is why you will see for loops, they are excellent for stepping through an array, among other things you need a counted process for. https://www.mql5.com/en/articles/567 has some info on arrays in case I missed anything. Trying to count past either end of the array's index will end up giving you an array index out of bounds error.In theory you could have 300 places within an array. Are you intentionally only giving it 9 spots or does it cause errors if you make it more than the 9? If there is something else that is causing you errors if you try to make more than 9 spots, that is another issue. But since you should try to keep your code (and memory usage) as minimal as you can to reduce operation time, you should only make the arrays and everything else as small as you can.
Thanks! And I was originally wrong about my my program; I'm populating the array and comparing in the OnTick() function. But after some more research it seem my for loop is not incrementing for whatever reason. It starts are zero and stays are zero. The first for loop works but the second does not increment. Any thoughts as to why this might be?