"invalid index buffer number in iCustom function" question. - page 2

 

@ Simon:

"your issue that you started with was "invalid index buffer number in iCustom function""

// EA was trying to access all icustom function parameters, BUT ;), I accidentally left out the "shift value" parameter of the icustom function call. The icustom function call-
// could not access the shift value parameter. MetaEditor was thinking, "where is that darn shift?!?" ;) 
// This was the partial problem which I did not announce and was aware of. 
// The incomplete function calls below the "MAextern" function call were the error source. MetaEditor notified me with an error of "invalid index buffer number in iCustom function".

// Original code: 

   int MAextern = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0,y);        // y is the missing "shift" value. MetaEditor was think'n, "where is that darn shift?!?" ;)
     
    
   int maPeriod_1_shift0 = iCustom(NULL, 0, "MAonMA",13,0);             // Here, I was trying to use the "maPeriod_1,2,3" functions from icustom indicator MAonMA with a shift value-    
   int maPeriod_2_shift0 = iCustom(NULL, 0, "MAonMA",34,0);   // was 0  // of 0.
   int maPeriod_3_shift0 = iCustom(NULL, 0, "MAonMA",89,0);
   
   int maPeriod_1_shift1 = iCustom(NULL, 0, "MAonMA",13,1);    // was 1 // Here, I was trying to use the "maPeriod_1,2,3" functions from icustom indicator MAonMA with a shift value-
   int maPeriod_2_shift1 = iCustom(NULL, 0, "MAonMA",34,1);             // of 1.
   int maPeriod_3_shift1 = iCustom(NULL, 0, "MAonMA",89,1);
  
   int maPeriod_1_shift2 = iCustom(NULL, 0, "MAonMA",13,2);             // Here, I was trying to use the "maPeriod_1,2,3" functions from icustom indicator MAonMA with a shift value-
   int maPeriod_2_shift2 = iCustom(NULL, 0, "MAonMA",34,2);  // was 2   // of 3.
   int maPeriod_3_shift2 = iCustom(NULL, 0, "MAonMA",89,2);   

 
(Inside EA) I can write...
int maPeriod_1 = iCustom(NULL,0,"MAonMA",13,0,0,34,0,89,0,0,0); // this is becaue icustom looks at this and thinks "Hmm, yeah, I know what maPeriod_1 is... It is 13!

I am aware that I can give-

int maPeriod_1 = iCustom(NULL,0,"MAonMA",13,0,0,34,0,89,0,0,0); 

-a shift of 0,1,2,3, or even 20!


The problem which I currently have is this...

Lets just say that I write "int maPeriod_1" with a shift of zero (0) inside my expert advisor.

NOW, I wish to write an additional "int maPeriod_1" with a shift of one (1) inside my expert advisor.

How can I write "int maPeriod_1" with a shift of one (1), when I have already declared "int maPeriod_1" with a shift of zero (0)?

Thank u.

 
WhooDoo22:
The problem which I currently have is this...

Lets just say that I write "int maPeriod_1" with a shift of zero (0) inside my expert advisor.

NOW, I wish to write an additional "int maPeriod_1" with a shift of one (1) inside my expert advisor.

How can I write "int maPeriod_1" with a shift of one (1), when I have already declared "int maPeriod_1" with a shift of zero (0)?

Thank u.

OK,

I would do it like this, it avoids confusion IMO . . .

int maPeriod_1;   //  <--  declare the variable here

maPeriod_1 = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0,0);    // <-- use the variable here . . .
                                                                  
maPeriod_1 = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0,1);    // <-- use the variable here . . .
 

@ Simon:

// inside EA (below the start() function).

   iCustom(NULL,0,"MAonMA",0,0); // I declare "MAonMA", to simply show me the three lines on the chart.
   
   int maPeriod_1;
   
   maPeriod_1 = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0,0); 
                                                                  
   maPeriod_1 = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0,1);  

I now understand how to declare "maPeriod_1"-

   maPeriod_1 = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0,0); 
                                                                  
   maPeriod_1 = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0,1);  

- but how can I distinguish the two, when using either shift 0 or shift 1 of "maPeriod_1", in lower blocks of code? Both "maPeriod_1" of shift 0 and shift 1 have the same name, "maPeriod_1".

Thank you.

 
WhooDoo22:

@ Simon:

I now understand how to declare "maPeriod_1"-

- but how can I distinguish the two, when using either shift 0 or shift 1 of "maPeriod_1", in lower blocks of code? Both "maPeriod_1" of shift 0 and shift 1 have the same name, "maPeriod_1".

Thank you.

RaptorUK:

Use a different variable name . . . . perhaps maPeriod_1_0 and maPeriod_1_1 ?

Ask I already told you . . . use different variable names, one for shift 0 and one for shift 1
 

@ Simon:

   int maPeriod_1;
   
   maPeriod_1 = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0,0); 
                                                                  
   maPeriod_1 = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0,1); 
/*
  lets say that we change the name of "maPeriod_1" to "maPeriod_1_0". If this change is incorporated inside the EA, then the iCustom function (when called) would not recognize this 
  new name "maPeriod_1_0". MetaEditor would pop out the error, " 'maPeriod_1_0' - variable not defined " because this new name "maPeriod_1_0" is nowhere to be found inside the-
  iCustom indicator. 
*/
// Example:

   maPeriod_1_0 = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0,0);  // Variable "maPeriod_1_0" is nowhere to be found inside the "MAonMA" iCustom indicator. 

// MetaEditor is thinkin', "where is that darn maPeriod_1_0 located inside the iCustom indicator "MAonMA"? Hmmm.... ;)

Thank you.

 
WhooDoo22:

@ Simon:

Thank you.

I think you need to re-read the Book especially the section about variables . . .

int maPeriod_1_0, maPeriod_1_1;
   
   maPeriod_1_0 = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0,0); 
                                                                  
   maPeriod_1_1 = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0,1); 
 

@ Simon:

Understood, I will read the book.

Thank you!

 

Hello MQL4 community,

There are two types of "return();" operators.

Type 1. ("return operator") terminates the current function execution and returns the control to the calling program.

Type 1. example: "return;".

Type 2. ("return(expression); operator") terminates the current function execution with "result transmission".

Type 2. example: "return(x+y);".

1. Once "return;" has been executed, where is the "calling program" location that the control is given to? (Referring to "Type 1.")

2. What is "result transmission"? (Referring to "Type 2.")

3. What is the purpose of "void"? (please provide simple example)

Thank you.

 
WhooDoo22:

Hello MQL4 community,

There are two types of "return();" operators.

Type 1. ("return operator") terminates the current function execution and returns the control to the calling program.

Type 1. example: "return;".

Type 2. ("return(expression); operator") terminates the current function execution with "result transmission".

Type 2. example: "return(x+y);".

1. Once "return;" has been executed, where is the "calling program" location that the control is given to? (Referring to "Type 1.")

2. What is "result transmission"? (Referring to "Type 2.")

3. What is the purpose of "void"? (please provide simple example)

Thank you.

There is one type of return operator . . . return; returns no value but passes control back to where the function was called from, return(x); returns x and passes control back to where the function was called from.

3. All functions have a type, the type refers to the type of variable returned from the function. If a function returns no variable then it is returning type void . . or nothing.

2. I don't know where you have seen "result transmission" so i don't know it's context, I guess it means the returning of the returned value.

1. If a function was called from start() when the function finishes with the return control passes back to the start() function to the point just after the function was called.



Reason: