String in inputs in "iCustom"

 
Hello everyone, in advance, thanks to whoever reads this query and can help me.
I ask for the favor, if someone can guide me on how to do this in the correct way:
As we know, the iCustom function has some fixed parameters, but other parameters are "changing" and this is completely tied to the amount of the indicator inputs in such a way that
iCustom (Symbol (), TF, "Indicator_Name", input1, input2, inputN, inputN, Buffer, index):

the "inputs" parameters can be 1 or they can be 5 or they can be 8 or they can be many more.

It turns out that I need to fill those values ​​with information that I extract automatically and that for now, I have in a string.
but I would like to use it in such a way that those spaces are filled in automatically, without knowing if they will be 3 inputs or 5 inputs or 10 inputs.

I insist, I can already put all the inputs in a string (Sometimes the string has 7 values ​​because the indicator has 7 inputs, or sometimes the string has 5 values ​​because the indicator studied has 5 inputs), I already have that. But no matter how much I locate or place that string with "the information of the inputs", the iCustom function takes me (and is quite right) that as a single input in a string.

How can I fill in automatically, taking into account that I don't know how many inputs I may have in advance?

string a="0.7,650";
//string a2="0.9,450,1600,150,false,120";
//string a3="false,1,clrRed";
   double indicatorResult=iCustom(Symbol(),0,"NAMEINDICATOR",a,0,0);
//double expectedCode =iCustom(Symbol(),0,"NAMEINDICATOR",0.7,650,0,0);
   Print(indicatorResult);


 
Miguel Antonio Rojas Martinez:
Hello everyone, in advance, thanks to whoever reads this query and can help me.
I ask for the favor, if someone can guide me on how to do this in the correct way:
As we know, the iCustom function has some fixed parameters, but other parameters are "changing" and this is completely tied to the amount of the indicator inputs in such a way that
iCustom (Symbol (), TF, "Indicator_Name", input1, input2, inputN, inputN, Buffer, index):

the "inputs" parameters can be 1 or they can be 5 or they can be 8 or they can be many more.

It turns out that I need to fill those values ​​with information that I extract automatically and that for now, I have in a string.
but I would like to use it in such a way that those spaces are filled in automatically, without knowing if they will be 3 inputs or 5 inputs or 10 inputs.

I insist, I can already put all the inputs in a string (Sometimes the string has 7 values ​​because the indicator has 7 inputs, or sometimes the string has 5 values ​​because the indicator studied has 5 inputs), I already have that. But no matter how much I locate or place that string with "the information of the inputs", the iCustom function takes me (and is quite right) that as a single input in a string.

How can I fill in automatically, taking into account that I don't know how many inputs I may have in advance?



@ Miguel Antonio Rojas Martinez

You can simply do it in 3 ways.

void OnTick()
  {
//--- Str

    // 1. 
     string a[10]={"0.7","650"};
    double expectedCode =iCustom(Symbol(),0,"NAMEINDICATOR",a[0],a[1],0,0);
     Print(a[0]," X ",a[1]);
     // 2.
   string b="0.7,650";
   string sep=",";                // A separator as a character 
   ushort u_sep;                  // The code of the separator character 
   string b1[];               // An array to get strings 
   u_sep=StringGetCharacter(sep,0); 
   int k=StringSplit(b,u_sep,b1); 
   Print(b1[0]," X ",b1[1]);
     double expectedCodeb;
    //3.
      switch(ArraySize(b1))
    {
      //Close opened long positions
      case 1  : expectedCodeb =iCustom(Symbol(),0,"NAMEINDICATOR",b1[0],0,0); break;
      case 2  : expectedCodeb =iCustom(Symbol(),0,"NAMEINDICATOR",b1[0],b1[1],0,0); break;
      case 3  : expectedCodeb =iCustom(Symbol(),0,"NAMEINDICATOR",b1[0],b1[1],b1[2],0,0); break;
      case 4  : expectedCodeb =iCustom(Symbol(),0,"NAMEINDICATOR",b1[0],b1[1],b1[1],b1[2],b1[3],0,0); break;
     
    }
    
    
    
   
 
 
  }
//+------------------------------------------------------------------+
 
Friend, thank you very much for responding, thank you for taking the time.

I can't apply option 1 directly, because I don't know the size or quantity of inputs,


option 2, I didn't understand it, but it will help me to partially extract each value.
And finally, option 3, is the one that I had considered before, but I wanted to avoid the switch case where, I even have to put at least 50 cases, so I wanted to avoid that work, but since you see it the same as me , and since you confirm that it is the most "viable" option, then I will apply that

Thank you very much again for your time.
 
You can do it with a hash table.
You can take a look here if you want.
https://www.mql5.com/en/forum/326539/page2
How can I write the following code in practice
How can I write the following code in practice
  • 2019.11.19
  • www.mql5.com
MQL4 and MetaTrader 4: How can I write the following code in practice
 
Miguel Antonio Rojas Martinez: but I would like to use it in such a way that those spaces are filled in automatically, without knowing if they will be 3 inputs or 5 inputs or 10 inputs.

There are no variadic functions.

See the following:
          Define Variadic Arguments in Functions? - Bollinger Bands, BB - Expert Advisors and Automated Trading - MQL5 programming forum 2018.04.19
          Function with variable number of parameters - MQL4 programming forum 2018.01.06
          Different Indicators Parameters to iCustom - MQL5 programming forum 2020.04.27

Post #1 only works if the data types are the same.
 
Friend, thank you very much for your help

I still have a huge problem and that is that the icustom parameters receive either a double or a string (maybe I need to be clearer and also consider the Integer, but for now I'm trying between those 2 options)

So, no matter how hard I try, I can't put a data that is a bool or a double without "knowing" it beforehand.

My idea is to be able to put a function that returns me, or a string or a double, but I always need, at some previous moment, to have declared a variable, with a type, either double or string and it doesn't work for me.

I explain a bit: I have the parameters in a string array and I use the ISNUMBER function to check if it is a number or not.



The closest thing I have applied is to use a ternary operator, in each input of the Icustom, but it does not work for me, because I take both results as a string.
"(ISNUMBER (array [0]))? (Double) array [0]: array [0]"

So the ternary operator, at that point, always returns a string in that "input" of the icustom

iCustom(Symbol(),0,NameIndicator,( ISNUMBER  (array[0]))?(double)array[0]:array[0],(ISNUMBER  MERO(array[1]))?(double)array[1]:array[1],Buffer, 0);


I also tried with this, templates and a class, but it doesn't help me, because I have to declare the class variable with a type, and then, the same, I don't advance.

template<typename T>
T val (T val1)
  {
   return val1;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class INPUT
  {
   public:
      xxxxx          ret; // Here the problem, because i need  declare a type.
   public:
                     INPUT(string valor);
  };
//------------------------------------------------------------+
INPUT::INPUT(string valor)
  {
   if(ISNUMBER(valor))
     {
      ret = val( StringToDouble(valor));
     }
   else
     {
      ret = val(string(valor));
     }
  }
//+------------------------------------------------------------------+


Thanks for if you can give me a hand

 
Miguel Antonio Rojas Martinez: Thanks for if you can give me a hand

What part of “There are no variadic functions.” was unclear?

 
You cannot use the ternary operator to select between types. If the types of the two operands differ the compiler will try an implicit cast.
Reason: