Enum Input and Result Not Working

I am trying to select the input for an Enum using the results of a Function (Symbol). It is not working. I can MANUALLY type the input (Example: EURUSD) and get the correct result. However, if I use the Function (in this case Symbol) it does not work. I’ve tried every method to convert Symbol() to some other type without luck. What am I missing here?

Example:

If you run the code below on a EURUSD chart it SHOULD return the rate of 5.2. The code with the pair of EURUSD manually specified works. The code with the pair provided by the Symbol function does not work; even thought the returned pair from Symbol() APPEARS to be exactly the same as the manual pair.

Why isn’t this working and how do I fix it? It seems so simple but something is not right.

Note: in my final version Symbol() is actually OrderSymbol(). However, the concept should be the same.

Thank you for the assistance!

enum Pairs {EURCAD, EURUSD, USDCAD,};
double Rates[] = {3.0, 5.2, 2.2};

double Selected_Pair_Rate_Version1;
double Selected_Pair_Rate_Version2;

int start(){
Pairs Pair_Version1 = EURUSD;        //Version 1. Pair Manually specified. Works!! 5.2 is returned.
Pairs Pair_Version2 = Symbol(); //Version 2. Pair provided by the Symbol() of the Chart. If the chart is EURUSD this SHOULD work and also return 5.2. It does NOT! How do I fix this?

Selected_Pair_Rate_Version1 = Rates [Pair_Version1];
Selected_Pair_Rate_Version2 = Rates [Pair_Version2];

Alert (Symbol(),"  ","Pair_Version1: ",Selected_Pair_Rate_Version1,"   ","Pair_Version2: ",Selected_Pair_Rate_Version2); // The result SHOULD be 5.2. Version 1 is Correct. Version 2 is not. How do I get it to work with Version 2?

};
Pairs Pair_Version2 = Symbol();

An enum isn’t a string.

Underlying an enum are integer values. Per the docs: “After the enumeration is declared, a new integer-valued 4-byte data type appears.”

Don’t ignore the compiler warning that says “implicit enum conversion.” In fact, don’t ignore compiler warnings ever.

I’m not ignoring the warning. I just don’t know how correct it. I am aware Symbol() is not an enum. How do I correctly format Symbol() so it CAN be used as the input for the enum?

If you want to attach a rate to a specific currency pair by name, then you could use an array of structs or objects.

struct Pairs
{
        string symbol;
        double rate;
};

void OnStart()
{

        Pairs pairs[3];
        pairs[0].symbol = "EURCAD";
        pairs[0].rate = 3.0;
        pairs[1].symbol = "EURUSD";
        pairs[1].rate = 5.2;
        . . .
        
}
#property strict
#property script_show_inputs


enum Pairs {EURCAD, EURUSD, USDCAD,};

input Pairs  pair=EURUSD;     //Pairs

double Rates[] = {3.0, 5.2, 2.2};

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   string   Pair_Version = EnumToString(pair);        
   double   Selected_Pair_Rate_Version = Rates [pair];

   Alert (Symbol(),"  ","Pair_Version: ",Pair_Version,"   ","Selected_Pair_Rate_Version: ",Selected_Pair_Rate_Version);
  }
//+------------------------------------------------------------------+

This uses the hard coded, manually typed input pair which is not going to work for this situation. The input pair needs to be fed by Symbol() ( It will be OrderSymbol() in my final version). It cannot be hard coded. This is important because in the final version the input OrderSymbol() will occur inside a “for” loop. Thank you for the suggestion though.

Any other ideas? There must be some kind of conversion to convert Symbol() directly to the format enum will understand as an input. How is it that you can type EURUSD and it works, but if you [Symbol() which is also EURUSD it does not work?

this conversion is done by

string   Pair_Version = EnumToString(pair);

It’s never a good idea to hard code these things because of broker compatibility they add all kind of post and pre fixes.

If you ever want to market your product that will deliver you the necessary headaches.

If you do want to enumerate inputs:

enum symbol  // Enumeration of named constants 
   { 
    EURUSD=1,  // EURUSD
    USDCAD=2,  // USDCAD 
    USDCHF=3,  // USDCHF 
    AUDCAD=4,  // AUDCAD 
    // etc
   };
   
sinput symbol sym=1; // Select Symbol 

But like i said it’s best if you respect the instrument name as is you can use:

SymbolName(position,1);

Quickly fill an array:

int symbols;string symbol[];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- symbols array
   symbols=SymbolsTotal(1);      //instrument count in marketwatch
   ArrayResize(symbol,symbols,0);//resize array
   for(int x=0;x<symbols;x++)
     {
      symbol[x]=SymbolName(x,1);// fill symbol array 
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+

Now you have a shadow copy and if you respect and keep the position numbers equally synchronized throughout your program you can accomplish many things.