Download MetaTrader 5
To add comments, please log in or register
Publish your trading signal. Gain access to millions of traders!
buscemi
9
buscemi 2016.03.09 18:36 

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

Vasyl Nosal
18218
Vasyl Nosal 2016.03.09 19:14  
init
Carl Schreiber
5959
Carl Schreiber 2016.03.09 19:39  

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.
buscemi
9
buscemi 2016.03.13 09:11  

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?

Carl Schreiber
5959
Carl Schreiber 2016.03.13 10:36  

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?


/
To add comments, please log in or register