Don't use init or OnInit()! Both are executed even if a valid connection not yet exists (e.g. during the weekend) and then you might not get any valid quotes!
To make sure to have a valid connection (you might use something else) I use MarketInfo(_Symbol, MODE_TICKVALUE ) as this kind of information has to be updated by the server continuously!
bool DoSet; int Oninit() { DoSet = true; ... } void OnTick() { if ( MarketInfo(_Symbbol, MODE_TICKVALUE ) < 0.000001 ) return; if ( DoSet ) { int b = Bars; while (b-->0) { ... } } }This works even in the tester if you start the tester (Use date) that many bars later you need than the history base does have.
Thanks for your answers!
That means I have to rewrite the code to fill the arrays in reverse and a possibility to use the actual code by precaching data from back to front is not given?
Indicators (e.g. iCustom(..), iMA(), ...) are filled automatically!
If you want to use your own arrays read about ArraySetAsSeries() and don't forget to resize dynamic arrays.
May be you start here and here?
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello MQL4 community!
This is my first post as a MQL4 rookie. And before I start I'd like to say thank you! I have already got some helpful tips just by searching & reading the forum.
Well, I have a comprehension question. So far I have "coded" EAs just for the strategy tester. That means in a lot of cases I used arrays in which I saved variables that were calculated on the actual (testing) day. On the next testing day those variables are taken over and are recalculated on basis of the actual value and so on.
My question: Is there a possibility to start the EA for live operation in the past i.e. one month backwards to collect all data and fill the arrays that I need for the actual trading day (live operation) or do I have to rewrite the EA and collect all data at the initialization of the EA? If so I would use iHighest, iLowest and iBarShift. Is that correct? Do I put these calculations on the global level or do I use OnCalculate (thought it is reserved for indicators)?
Appreciate your help!
Thank you,
buscemi