Weird: Can't use loop variable, or complex expression for buffer index

 

Hi Guys,

See below. I am using MT4 Build 509 on an Australian Global Prime ECN broker.

1. I cannot seem to use the loop variable i as the buffer array index directly. Have to change it to something else:

shift = i, for example. Reversing shift and i give same result: a dark screen. No compiler errors.

2. Same dark screen with complex expression as the buffer index based on another loop variable and int maxBars, e.g., instead of arrUSD[i], I use arrUSD [ i + j*maxBars]. No compiler errors. This hangs my MT4.

What I am doing here is trying to avoid over-write of buffer when I calculate the indi for further TFs in the same sub-window, so the new indi values are shifted accordingly for each new TF.

int i, shift;
   int tf = GettimeFrameInteger(MTF[j]);
   
  
 for ( int k = 0; k < CURRENCYCOUNT; k++ )
      { SetIndexShift(k, shiftChart[j]);          
  
   for ( i = maxBars-1; i >= 0; i --) 
   { 
        
      //shift= iBarShift(NULL,tf, Time[i], true)+1 ; // switch to false?, i vs. shift below
      
      shift = i; 

      ArrayInitialize(currencyValues, 0.0);

      // Calc Slope into currencyValues[]  
      calcCSS( tf, i ); 
      
    
      arrUSD[shift] = currencyValues[0]; 
      arrEUR[shift] = currencyValues[1]; 
      arrGBP[shift] = currencyValues[2]; 
      arrCHF[shift] = currencyValues[3];
      arrJPY[shift] = currencyValues[4]; 
      arrAUD[shift] = currencyValues[5]; 
      arrCAD[shift] = currencyValues[6]; 
      arrNZD[shift] = currencyValues[7]; 
      }
        
 
atharmian:

Hi Guys,

See below. I am using MT4 Build 509 on an Australian Global Prime ECN broker.

1. I cannot seem to use the loop variable i as the buffer array index directly. Have to change it to something else:

Yes you can . . . unless you have i globally declared also and are messing with it in another function, probably calcCSS . . . do yourself a favour, don't use i or j or h . . . use a meaningful variable name and keep them unique, it makes finding issues easier and makes your code easier to read.
 
RaptorUK:
Yes you can . . . unless you have i globally declared also and are messing with it in another function, probably calcCSS . . . do yourself a favour, don't use i or j or h . . . use a meaningful variable name and keep them unique, it makes finding issues easier and makes your code easier to read.


Thanks. The uniqueness suggestion I appreciate.

But still MQL4 is quite crappy: most other well used languages would not have these issues.

I did not declare i globally: to me such loop var should only be declared locally. Yes, calcCSS does have i declared

as local :(

Now any insights on #2 question?

 
atharmian:


Thanks. The uniqueness suggestion I appreciate.

But still MQL4 is quite crappy: most other well used languages would not have these issues.

I did not declare i globally: to me such loop var should only be declared locally. Yes, calcCSS does have i declared

as local :(

Now any insights on #2 question?

might be this is giving a solution
see https://www.mql5.com/en/code/7716

it takes some time before it is ready if you have a lot of historydata

but it will work

 
atharmian:


Thanks. The uniqueness suggestion I appreciate.

But still MQL4 is quite crappy: most other well used languages would not have these issues.

I did not declare i globally: to me such loop var should only be declared locally. Yes, calcCSS does have i declared

as local :(

When you say "as local" do you mean as part of the function definition or inside the function ?

Print i after . . .

shift = i; 

and after . . .

      calcCSS( tf, i );

and I think you will see it being changed, you need to find out why.

atharmian:

Now any insights on #2 question?

See my point about i . . .
 
RaptorUK:

When you say "as local" do you mean as part of the function definition or inside the function ?

Print i after . . .

and after . . .

and I think you will see it being changed, you need to find out why.

See my point about i . . .


Well, I guess, best is that I stick to the unique var names here :)

Will apply same to the arrUSD [ i + j*maxBars] problem.

BTW, in calcCSS (tf, shift) I have int i =0 defined insides it.

PS. Had I not been misled twice by WHRoeder, first with his telling me that I need iBarShift when in fact my shift (or i) was already defined as shift on the respective TFs in calc functions using iMA, iATR and iClose, I wouldn't be messing around so much. Then, he made me beat about the bush a second time with his dismissal of EMTPY_VALUE problem, which SDC solved nicely for me. Some people are quite irresponsible here, others just fine !

 
deVries:

might be this is giving a solution
see https://www.mql5.com/en/code/7716

it takes some time before it is ready if you have a lot of historydata

but it will work


Downloaded, will try. Thanks for the suggestion.

BTW, you are right about that crappy tonny software !!!

 
atharmian: Had I not been misled twice by WHRoeder,...

Please do not feed the troll.

When you respond, you give the troll power. When you ignore the troll, he starves for attention and eventually dies.

 
atharmian:


PS. Had I not been misled twice by WHRoeder, first with his telling me that I need iBarShift when in fact my shift (or i) was already defined as shift on the respective TFs in calc functions using iMA, iATR and iClose, I wouldn't be messing around so much. Then, he made me beat about the bush a second time with his dismissal of EMTPY_VALUE problem, which SDC solved nicely for me. Some people are quite irresponsible here, others just fine !

I was just about to put your indicator onto a chart and have a look at what is going on until I read this . . .
 
RaptorUK:
I was just about to put your indicator onto a chart and have a look at what is going on until I read this . . .


What I said is the truth. I was misled, and no funny cartoon can help that.

If you don't believe me, simply check the indi and you'll agree !

 
WHRoeder:

Please do not feed the troll.

When you respond, you give the troll power. When you ignore the troll, he starves for attention and eventually dies.


You had self-promised that you would ignore my threads. Just cannot control yourself?

Can't help me, just ignore me. Please.