Download MetaTrader 5
To add comments, please log in or register
Trade like successful traders - subscribe to their signals!
Daniel Petrovai
440
Daniel Petrovai 2014.03.10 07:40  
GumRai:


Well, I was just adjusting the OP's code, apart from that old habits die hard :)

To be honest, I've only just learnt how to use the new arrays. Before I was trying &high[index] and I now know that they need to be set as series if one wants to use them in the way that we are used to.

There seems so much new stuff that it will take some time to change. I do try to use the SymbolInfo stuff instead of Market info as that looks pretty good.


Hope you didn't mind my question, wasn't picking on anyone, just saying, you know.

On the other hand, you seem pretty god with array out of range kind of thing and I have one that gives me trouble. Would you look at it please ?

Here is one working in an indicator similar to OPs :

   if(prev_calculated<=0)
     {
      for(i=0; i<rates_total-InpPeriod+1; i++)
        {
         sum=0;
         for(k=1; k<InpPeriod; k++)
           {
            sum+=high[i+k];
           }
         ExtMainBuffer[i]=high[i]-(sum/InpPeriod);
        }//end for 
     }

and here's the one in question :

   if(prev_calculated<=0)
     {
      //--- Step 1, calculate average for bars 1-20
      for(i=0; i<rates_total-(CumulantPeriod+1); i++)
        {
         Average[i]=(high[i]+low[i])/2;
        }//end for 

This one returns an out of range error. I miss to see why.

I've set all arrays as series including high[] and low[], the period is 20 .

Any thoughts ?

Thanks

Keith Watford
Moderator
8842
Keith Watford 2014.03.10 10:24  

thrdel:

   if(prev_calculated<=0)
     {
      //--- Step 1, calculate average for bars 1-20
      for(i=0; i<rates_total-(CumulantPeriod+1); i++)
        {
         Average[i]=(high[i]+low[i])/2;
        }//end for 

This one returns an out of range error. I miss to see why.

I've set all arrays as series including high[] and low[], the period is 20 .

Any thoughts ?

Thanks

Well, I don't know what the value of CumulantPeriod is. Is it negative?

What about the array Average, is it a dynamic array? You don't re-size it. Is it also set as series?

Your comment suggests that you want to store the last 20 average prices in your array, so it is quite possible that you declared your array

double Average[20];

if so, is it possible that

rates_total-(CumulantPeriod+1)

can be more than 20?

If this doesn't answer your question, you will probably have to show more of the code.

Daniel Petrovai
440
Daniel Petrovai 2014.03.10 23:39  
GumRai:

Well, I don't know what the value of CumulantPeriod is. Is it negative?

What about the array Average, is it a dynamic array? You don't re-size it. Is it also set as series?

Your comment suggests that you want to store the last 20 average prices in your array, so it is quite possible that you declared your array

if so, is it possible that

can be more than 20?

If this doesn't answer your question, you will probably have to show more of the code.


Thanks GumRai,

I've fixed it. My mistake was to define the arrays before OnInit()

input int CumulantPeriod=20;

double sum=0;
double CumulantBuffer[];
double CumulantBuffer2[];
//--- Calculation Buffers
double Average[],Close_Average[],CloseZero_Close[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()

instead of inside OnCalculate() and not used SetIndexBuffer() for them. MT4 looked at them as buffers, normally.

Quite silly, isn't it.

Thanks a bunch anyway.

/ /12
To add comments, please log in or register