"invalid index buffer number in iCustom function" question.

 

Hi all! I am running tests on version II of an expert advisor I recently added to the "Code Base". I am aware that I am using another coder's icustom indicator, but obviously I would not use his icustom indicator in my expert advisor and take credit for it! I simply wish to use it for testing purposes.

If anyone from MQL4 community could drop the indicator and expert (attached below) into their mt4 folder and give it a spin in their strategy tester to view the error that is popping up in the journal, and then give me their opinion and/or thoughts please.

Thank you.

 
WhooDoo22:

"invalid index buffer number in iCustom function" question.

When you got this error you looked at the Documentation for iCustom and found what that would explain your error ?


double iCustom( string symbol, int timeframe, string name, ..., int mode, int shift)

mode - Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions.

   int MAextern = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0);
     
    
   int maPeriod_1_shift0 = iCustom(NULL, 0, "MAonMA",13,0);    
   int maPeriod_2_shift0 = iCustom(NULL, 0, "MAonMA",34,0);   // was 0
   int maPeriod_3_shift0 = iCustom(NULL, 0, "MAonMA",89,0);
   
   int maPeriod_1_shift1 = iCustom(NULL, 0, "MAonMA",13,1);    // was 1
   int maPeriod_2_shift1 = iCustom(NULL, 0, "MAonMA",34,1);
   int maPeriod_3_shift1 = iCustom(NULL, 0, "MAonMA",89,1);
  
   int maPeriod_1_shift2 = iCustom(NULL, 0, "MAonMA",13,2);    
   int maPeriod_2_shift2 = iCustom(NULL, 0, "MAonMA",34,2);  // was 2
   int maPeriod_3_shift2 = iCustom(NULL, 0, "MAonMA",89,2);   
 

@RaptorUK:

First, thank you for replying to my post Simon.

"When you got this error you looked at the Documentation for iCustom and found what that would explain your error ?"

Yes, I looked at the iCustom definition. I did notice partial solutions, but not a solution for using "maPeriod_1, maPeriod_2, and maPeriod_3" for crossings of SMMA period 1 using different shift values.

I am trying to use the crossing of SMMA period 1 with 13,34, and 89 ( 13,34, and 89 are located in basisforex's icustom indicator) as order close signals. I understand that to complete this task "maPeriod_1, maPeriod_2, and maPeriod_3" should be written into my expert advisor to use for this function. The problem seems to be, "How to write these to use different shift values? Example: shift 0, shift 1, shift 2." I wish to use these lines for crossings with different shifts. This is a puzzler for me. I realize that the code in the "SRC" above is incorrect.

Thank you.


 

@ WHRoeder: I am reading the "Detailed explanation of iCustom - MQL4 forum", but it is not simple for me to isolate information that can assist me with this problem from these boxes containing lines after lines of code.

I did find this interesting located under the "EA section".

#define SFX "SFX"

The calls then are

double     STDBuffer = iCustom(NULL,0,SFX,
                        PairName, StdDev.MA.Period, StdDev.MA.Shift, 
                        StdDev.MA.Method, StdDev.MA.Price, MA.Fast.Period, 
                        MA.Fast.Method, MA.Fast.Shift, CheckOncePerBar,
                                SFX_STD, 0)
double     stddevma =  iCustom(NULL,0,SFX,
                        PairName, StdDev.MA.Period, StdDev.MA.Shift, 
                        StdDev.MA.Method, StdDev.MA.Price, MA.Fast.Period, 
                        MA.Fast.Method, MA.Fast.Shift, CheckOncePerBar,
                                SFX_STDMA, 0)

and this...

"Yes. The problem is that the last two parameters of the iCustom are crucial so you cannot omit anything." - dabbler.

I have much respect for dabblers coding abilities and had experience discussing coding MQL4 with him before.


Thank you.

 
WhooDoo22:

Hi all! I am running tests on version II of an expert advisor I recently added to the "Code Base". I am aware that I am using another coder's icustom indicator, but obviously I would not use his icustom indicator in my expert advisor and take credit for it! I simply wish to use it for testing purposes.

If anyone from MQL4 community could drop the indicator and expert (attached below) into their mt4 folder and give it a spin in their strategy tester to view the error that is popping up in the journal, and then give me their opinion and/or thoughts please.

Thank you.


looka here ! the parameters don't match in your calls:


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

int maPeriod_1_shift0 = iCustom(NULL, 0, "MAonMA",13,0); <<== you neeed all the 7 in MaonMa, plus two more

like this

int maPeriod_1_shift0 = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0, x, y );

x--for the buffer you are trying to get. MaonMa has 3 index buffers.

y- for the shift position you are trying to get

 

// Declaration of the iCustom indicator inside expert advisor ;

int MAextern = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0,y) ;  // I realize that I was missing a zero (y = shift). 


// The question that pops into my head, is, "How to use the "maPeriod_1" with different shift values?" I will provide an example...
// Inside my expert advisor. 
                                                                  // The last "0" was y. Now it is 0 (0 is the shift value according to the "iCustom definition").
int maPeriod_1 = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0,0); 
                                                                  // The last "1" was y. Now it is 1 (1 is the shift value according to the "iCustom definition"). 
int maPeriod_1 = iCustom(NULL, 0, "MAonMA",13,0,0,34,0,89,0,0,1); 


// ALERT! Here is the problem... "maPeriod_1" and "maPeriod_1" have the same name! (they may have different shifts, but they have the same name! I can't run EA with buggies :) .

// the question is, how can I select maPeriod_1 with different shift values and have it running in the EA ? 

// still working on this. 

// Thank you skaboy.
 
WhooDoo22:

There is no problem, All you gotta do is look at the MaOnMa, see what it does. Then decide it that's what you want. Seems to me that's where your confusion is.

 

@skaboy: Thank you for your reply.

// ALERT! Here is the problem... "maPeriod_1" and "maPeriod_1" have the same name! (they may have different shift values, but they have the same name! I can't run EA with buggies :)

// Error pops up and reads, "maPeriod_1 - variable already defined".
 
WhooDoo22:

@skaboy: Thank you for your reply.

I'm really not clear on what your problem is now . . . your issue that you started with was "invalid index buffer number in iCustom function" and that is clearly caused by your iCustom calls trying to access buffers 13, 34, & 89 and these buffers cannot exist. You never stated that you understood this . . . instead you went on to talk about something different . . .

"Yes, I looked at the iCustom definition. I did notice partial solutions, but not a solution for using "maPeriod_1, maPeriod_2, and maPeriod_3" for crossings of SMMA period 1 using different shift values."

You need to understand the Functions that you are using . . . if you don't understand how to use iCustom how can you hope to use it correctly or to address any issues you have with it. You MUST read the Documentation and experiment with iCustom until you understand how to use it correctly. I have never used iCustom in any of my own code as I don't use Technical Indicators, but I have taken the time to understand it so that I can help other people.

The main issue is that you have to either pass all the Indicators extern values in the iCustom call or pass none of them . . . so your iCustom call will be . . .

iCustom( string symbol, int timeframe, "MAonMA", int mode, int shift)

or

iCustom( string symbol, int timeframe, "MAonMA",   int maPeriod_1, int maMethod_1, int maAppPrice_1, int maPeriod_2, int maMethod_2, int maPeriod_3, int maMethod_3,    int mode, int shift)



If you are happy to use the default values for the externs then you can leave them out of your iCustom call and use the first example above . . . these are the extern defaults in your Indicator . . .

extern int maPeriod_1   = 13;

extern int maMethod_1   = 0;

extern int maAppPrice_1 = 0;

extern int maPeriod_2   = 34;

extern int maMethod_2   = 0;

extern int maPeriod_3   = 89;

extern int maMethod_3   = 0;
 
WhooDoo22:

Here is the problem... "maPeriod_1" and "maPeriod_1" have the same name! (they may have different shift values, but they have the same name! I can't run EA with buggies :)

Error pops up and reads, "maPeriod_1 - variable already defined".

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