Download MetaTrader 5
To add comments, please log in or register
Have you found an interesting application? Publish it in Code Base - millions of traders will appreciate that!
Ian Venner
2583
Ian Venner 2014.04.20 03:04 

Looking at the code for included indicators I noticed MQ now does this in most if not all of them:

example from Heiken Ashi

//--- counting from 0 to rates_total
   ArraySetAsSeries(ExtLowHighBuffer,false);
   ArraySetAsSeries(ExtHighLowBuffer,false);
   ArraySetAsSeries(ExtOpenBuffer,false);
   ArraySetAsSeries(ExtCloseBuffer,false);
   ArraySetAsSeries(open,false);
   ArraySetAsSeries(high,false);
   ArraySetAsSeries(low,false);
   ArraySetAsSeries(close,false);
Is this really neccessary to do in all indicators ? The docs says we shouldnt depend on them already not being series arrays but I dont really understand why. The old Open[] High[] low[] Close[] arrays were series arrays right ? Does this mean the new ones are not series arrays ? And what about the buffers why do we need to set then to false now we never did that before either ?
whroeder1
13627
whroeder1 2014.04.20 13:20  
SDC: Is this really neccessary to do in all indicators ? The docs says we shouldnt depend on them already not being series arrays but I dont really understand why. The old Open[] High[] low[] Close[] arrays were series arrays right ? Does this mean the new ones are not series arrays ? And what about the buffers why do we need to set then to false now we never did that before either ?
  1. If you're going to use those parameters.
  2. Only your code knows wither you are counting up or down and Metaquotes didn't tell you a default. The ordering must match!
    for(int i=Bars-1-IndicatorCounted(); i>=0; i--)
       buffer[i] = High[i];
    Buffer must be asSeries (default) as High is. If you want to use high instead (of High) then it must be set asSeries
    while(prev_calculated < rates_total){
       buffer[prev_calculated]=high[prev_calculated];
       prev_calculated++;
    }
    Both buffer and high must not be since you are counting up to the future.
  3. Still is.
  4. The default for buffers is series, but you can change it. Indexing Direction in Arrays, Buffers and Timeseries - MQL4 Documentation
  5. The choice is now the coder. Count down or count up toward the future. The latter is slightly more efficient in terms of indexing, memory access and is what ArrayCopy does.
Ian Venner
2583
Ian Venner 2014.04.20 15:45  

I understand what your saying, but ...ok if an array is set as series or not set as series before the data is entered, it makes no diference right ? Surely the data has to be entered into the array explicitly by index in the first place ? So at that time, whatever is entered into the zero index,( array[0] = val ) regardless of indexing direction will be entered correctly into the zero index and so on for the rest of the array. So it is only when we change the setting from series to not series, or from not series to series that that the data gets reversed ? This is why i dont understand why we would want to set the indexing direction of an array when we dont know which direction it was indexed to start with ... do you see what I mean ?

Also if buffers must be series, why are MQ coders setting the series as false on all the buffers ?

Alain Verleyen
Moderator
28626
Alain Verleyen 2014.04.20 16:50  
SDC:

I understand what your saying, but ...ok if an array is set as series or not set as series before the data is entered, it makes no diference right ? Surely the data has to be entered into the array explicitly by index in the first place ? So at that time, whatever is entered into the zero index,( array[0] = val ) regardless of indexing direction will be entered correctly into the zero index and so on for the rest of the array. So it is only when we change the setting from series to not series, or from not series to series that that the data gets reversed ? This is why i dont understand why we would want to set the indexing direction of an array when we dont know which direction it was indexed to start with ... do you see what I mean ?

Also if buffers must be series, why are MQ coders setting the series as false on all the buffers ?

Timeseries (open, high, low, close...) provided in OnCalculate seems to be indexed as series for now. But Metaquotes said clearly, it's not reliable and you have to set yourself as series or not. If you don't do it and in the future the ohlc value are provided index not as series, there is great chance you indicator will not work any more. In MT5, these data are provided index not as series but default (and MQ write also in the doc it's not reliable and can be changed).

The old Open[] High[] low[] Close[] arrays were series arrays right ? Does this mean the new ones are not series arrays ? And what about the buffers why do we need to set then to false now we never did that before either ?

The new ones are timeseries provided index as series (mql4) or not(mql5), that can change. You can choose to program with timeseries and buffers indexed as series or not, for some indicator 1 way is more easy, for other the other is more easy. But if your timeseries are not indexed as series, it's certainly easier to use indicator's buffers as not indexed too.

Ian Venner
2583
Ian Venner 2014.04.20 18:02  

angevoyageur

Timeseries (open, high, low, close...) provided in OnCalculate seems to be indexed as series for now. But Metaquotes said clearly, it's not reliable and you have to set yourself as series or not. If you don't do it and in the future the ohlc value are provided index not as series, there is great chance you indicator will not work any more. In MT5, these data are provided index not as series but default (and MQ write also in the doc it's not reliable and can be changed).

Yes I read that in the documentation too but do you see my point about changing them ? It is not about whether they should be series or not, it is about if you change them or not. Look at this code:

void OnStart()
  {
//---
   int test1[5]={0};
   int test2[5]={0};
   
   ArraySetAsSeries(test1,true);  // set this one as series
   ArraySetAsSeries(test2,false);  //set this one not series
   
//---
   for(int i=0; i<5; i++) test1[i]=i;  //put the same data in both of them
   for(int i=0; i<5; i++) test2[i]=i;

// now print the values
   for(int i=0; i<5; i++) Print("series array (INDEX ",i,") val = ",test1[i]);
   for(int i=0; i<5; i++) Print("not series (INDEX ",i,") val = ",test2[i]);
  }

output;

not series (INDEX 4) val = 4
not series (INDEX 3) val = 3
not series (INDEX 2) val = 2
not series (INDEX 1) val = 1
not series (INDEX 0) val = 0
series array (INDEX 4) val = 4
series array (INDEX 3) val = 3
series array (INDEX 2) val = 2
series array (INDEX 1) val = 1
series array (INDEX 0) val = 0

See what I mean ? It makes no difference from a practical point of view whether the array was series or not when the data is added. But if we change either one of them to the opposite setting after they are filled the indexing will be reversed and the all the data will be in the wrong indexes. This is why I dont understand how could the indexing be ambiguous ? It cant work unless we know exactly which indexing mode was used to begin with.

Edit: ok i have now realised when this could apply. When data is not entered explicity by index and is entered array[5] = {0,1,2,3,4} I guess if the open[] high[] low[] close[] arrays are filled that way it does matter, if you can even do that ? I dont know how you could set an array to series or not before you initialize it with values but even if you can I still dont see how that applies to buffers which are filled by our own code explicitly by index.

Alain Verleyen
Moderator
28626
Alain Verleyen 2014.04.20 19:49  

Of course data are not changed. If you affect value 4 to element four and then you print element four you will get 4. But what if you change indexing after setting the values.

This code should better demonstrate the issue :

void OnStart()
  {
//---
   int test1[5]={0};
   int test2[5]={0};
      
//---
   for(int i=0; i<5; i++) test1[i]=i;  //put the same data in both of them
   for(int i=0; i<5; i++) test2[i]=i;

   ArraySetAsSeries(test1,true);  // set this one as series
   ArraySetAsSeries(test2,false);  //set this one not series

// now print the values
   for(int i=0; i<5; i++) Print("series array (INDEX ",i,") val = ",test1[i]);
   for(int i=0; i<5; i++) Print("not series (INDEX ",i,") val = ",test2[i]);
  }   
Ian Venner
2583
Ian Venner 2014.04.20 21:03  
Yes i did that too and the indexing is reversed, but that still does not explain how the rates arrays can be ambiguously set, and then setting them to false fixes it. I imagine a scenario where we end up with some arrays with correct indexing and some reversed. The logic behind this does not make sense to me.
Alain Verleyen
Moderator
28626
Alain Verleyen 2014.04.20 21:22  
SDC:
Yes i did that too and the indexing is reversed, but that still does not explain how the rates arrays can be ambiguously set, and then setting them to false fixes it. I imagine a scenario where we end up with some arrays with correct indexing and some reversed. The logic behind this does not make sense to me.
Sorry, but I don't know how to explain that otherwise.
/
To add comments, please log in or register