SetIndexBuffer : add an buffer to an indicator

 
string SymName[];
int Action[];
SetIndexBuffer(2,SymName); 
SetIndexBuffer(3,Action);

With this error :

'SymName' - parameter conversion not allowed    43      21
'Action' - parameter conversion not allowed     43      48 


Hi, I'm working on an indicator that already works with 2 buffers, I want to add a 3rd & 4th one, 3 as a string, 4 as a int but i'm getting an error. How to please ?

 
blouf:

With this error :


Hi, I'm working on an indicator that already works with 2 buffers, I want to add a 3rd & 4th one, 3 as a string, 4 as a int but i'm getting an error. How to please ?

Seems impossible to use array as string, so how to ?
 
blouf:
Seems impossible to use array as string, so how to ?
If the number of possible values for the string array is finite, you can declare a custom enum, and then use an int array to feed on the buffer.
 
blouf:

With this error :


Hi, I'm working on an indicator that already works with 2 buffers, I want to add a 3rd & 4th one, 3 as a string, 4 as a int but i'm getting an error. How to please ?

Indicator's buffer can only be of double type. Please read the documentation about SetIndexBuffer().
 
angevoyageur:
Indicator's buffer can only be of double type. Please read the documentation about SetIndexBuffer().

I've used an ENUM as suggested by Iceron. Now, I face a new problem.

(GBPAUD,M30)    array out of range in 'Ext.mq5' (127,7)


After some calculations I obtain a variable called "results", I'd like it to be the buffer. So ...

double Buffer[]; <--- declared as this higher in the code
Buffer[0] = StringToDouble(results); <--- results being a 'string'
printf("Buffer : %g",Buffer[0]);
I don't need Buffer to be multiple, I'd rather want it to show the results as they are. From the expert I will ask only one Buffer[0] at the time.
 
blouf:

I've used an ENUM as suggested by Iceron. Now, I face a new problem.

I do not see the entire code, but usually this error comes when the number of declared buffers is less than the buffers you assigned indices to. Make sure that IndicatorBuffers() and/or #property indicator_buffers are updated to the number of buffers you want to use.

blouf:

After some calculations I obtain a variable called "results", I'd like it to be the buffer. So ...

double Buffer[]; <--- declared as this higher in the code
Buffer[0] = StringToDouble(results); <--- results being a 'string'
printf("Buffer : %g",Buffer[0]);

You may use a switch or if-then-else statement for this, e.g.:

#property indicator_buffers 1
enum NUMBER {
   NUMBER_ONE = 1,
   NUMBER_TWO,
   NUMBER_THREE,
   NUMBER_FOUR,
   NUMBER_FIVE,
};

int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Buffer,INDICATOR_CALCULATIONS);
//---
   return(INIT_SUCCEEDED);
  }

int OnCalculate(/*...*/)
{
   string results;
   //get value of results
   if (StringCompare(results,EnumToString(NUMBER_ONE))==0) //NUMBER_ONE = 1
   {
      Buffer[0] = (double) (EnumToString(NUMBER_ONE)); //you can typecast to avoid warnings
   }   
   if (StringCompare(results,EnumToString(NUMBER_TWO))==0) //NUMBER_TWO = 2
   {
      Buffer[0] = (double) (EnumToString(NUMBER_TWO)); 
   }      
   else
   {
      //other enums as needed
   } 
}
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Language Basics / Preprocessor / Program Properties (#property) - Reference on algorithmic/automated trading language for MetaTrader 5
 
Iceron:

I do not see the entire code, but usually this error comes when the number of declared buffers is less than the buffers you assigned indices to. Make sure that IndicatorBuffers() and/or #property indicator_buffers are updated to the number of buffers you want to use.

You may use a switch or if-then-else statement for this, e.g.:

Solved. Thanks dude for your help, the array had to be resized.
 
blouf:
Solved. Thanks dude for your help, the array had to be resized.

Now, I can obtain buffer[0], but when I try to use it inside an EA, Buffer[0] is always = to 0 ????????????????? The code below shows the correct value for the buffer inside the EA log windows

printf("Buffer : %g",Buffer[0]);
 
blouf:

Now, I can obtain buffer[0], but when I try to use it inside an EA, Buffer[0] is always = to 0 ?????????????????

Show your code if you need help.
 
angevoyageur:
Show your code if you need help.
EDIT : it may be relevant 
#property indicator_buffers 3
#property indicator_plots 2
#property indicator_color1 clrNONE
#property indicator_color2 clrNONE
#property indicator_type1 INDICATOR_DATA
#property indicator_type2 INDICATOR_CALCULATIONS
///////////////
<Same code> + 
ArrayResize(Buffer,1);
Buffer[0] = (double)results;
//printf("Buffer Size : %g",(ArraySize(Buffer)));
//printf("Buffer : %g",Buffer[0]); <--- when uncommented works it shows in the EA log correctly

///////
return(rates_total);}

Inside the EA :

Classical : 
<Handle call>
   // CPM Handle
   if (CopyBuffer(CPMHandle, 2, 0, 1, CPMBuffer) <=0) return;
   if (CopyBuffer(CPMHandle, 1, 1, 1, CPMBuffer2) <=0) return;
   if (CopyBuffer(CPMHandle, 0, 1, 1, CPMBuffer3) <=0) return;

   printf("1 : %g / 2 : %g / 3 : %g",CPMBuffer[0],CPMBuffer2[0],CPMBuffer3[0]);

Results in the EA windows :

2014.12.06 11:35:40     Core 1  2014.06.05 16:00:00   1 : 0 / 2 : 3 / 3 : 2.5
 
blouf:

Inside the EA :

Results in the EA windows :

//--- indicator buffers mapping
   SetIndexBuffer(0,Buffer,INDICATOR_CALCULATIONS);

What is the actual buffer index ?

   if (CopyBuffer(CPMHandle, 0, 1, 1, CPMBuffer3) <=0) return;