Check the name of the base currency - page 2

 
Print(SymbolInfoString(_Symbol,SYMBOL_CURRENCY_BASE));
 
Taras Slobodyanik:

This is the correct way to check the base currency. Unfortunately, OP mistitled the thread. The title should have been, "How to check if a symbol is in a list of symbols?" 

 
Taras Slobodyanik:

That's what I use. 

live_base   = SymbolInfoString(Symbol(),SYMBOL_CURRENCY_BASE);

But I can only find this solution for the quote. 

live_quote   = StringSubstr(Symbol(), 3, 3);

Why isn't there? SymbolInfoString(Symbol(),SYMBOL_CURRENCY_QUOTE);

 
Lars Rompe:

I use this to get that character.  

last_char  = StringSubstr(Symbol(),6);

 
Conor Dailey:

That's what I use. 

live_base   = SymbolInfoString(Symbol(),SYMBOL_CURRENCY_BASE);

But I can only find this solution for the quote. 

live_quote   = StringSubstr(Symbol(), 3, 3);

Why isn't there? SymbolInfoString(Symbol(),SYMBOL_CURRENCY_QUOTE);

The thread is mistitled. OP wants,

"if the currency pair on the current chart is one of those : USDJPY or EURJPY or CADJPY".

 
nicholi shen:

The thread is mistitled. OP wants,

Sorry for writting the wrong title.

I did not know there were so many problems.


unfortunately, I am still stuck to the same point, as I really do not know what to write in my code.

Should I create a program that check the name of the symbols an then use those names?

 
Luciole:

Sorry for writting the wrong title.

I did not know there were so many problems.


unfortunately, I am still stuck to the same point, as I really do not know what to write in my code.

Should I create a program that check the name of the symbols an then use those names?

Did you read my post? I gave you the answer... 

 
nicholi shen:

Did you read my post? I gave you the answer... 

Are you talking about that?


void OnStart()
{
   const string allowed_symbols[] = {"USDJPY", "EURJPY", "CADJPY"};
   bool allowed = is_allowed_symbol(_Symbol, allowed_symbols);
   printf("%s %s an allowed symbol.", _Symbol, allowed ? "is" : "is NOT");
}
bool is_allowed_symbol(const string symbol, const string &symbol_array[])
{
   for(int i=ArraySize(symbol_array)-1; i>=0; --i)
      if(StringFind(symbol, symbol_array[i]) >= 0)
         return true;
   return false;
}

And then, I will know the right format of the symbol?

So I use that and then I can use :

if( (Symbol() == "USDJPY") || (Symbol() == "EURJPY") || (Symbol() == "CADJPY") ) 
 
Luciole:

Are you talking about that?


And then, I will know the right format of the symbol?

So I use that and then I can use :

There's a principal in programming called DRY, which means don't repeat yourself. Since you're new I'm sure on the surface it looks more intimidating to make a function instead of writing out our expressions longhand, but what happens when you want to add a few more symbols? What happens when you need to do a similar evaluation with different symbols?

Your code should be as reusable as possible. That's why the problem you are describing has a commonly used design pattern. You add the acceptable values to an array then loop over the array to check if your value is contained within the array. So just to confirm, do you fully understand how the code I shared with you works?

 
nicholi shen:

There's a principal in programming called DRY, which means don't repeat yourself. Since you're new I'm sure on the surface it looks more intimidating to make a function instead of writing out our expressions longhand, but what happens when you want to add a few more symbols? What happens when you need to do a similar evaluation with different symbols?

Your code should be as reusable as possible. That's why the problem you are describing has a commonly used design pattern. You add the acceptable values to an array then loop over the array to check if your value is contained within the array. So just to confirm, do you fully understand how the code I shared with you works?

DRY >> I did not know that, and I will try my best to respect it.


I think I understand 95% it but it took me some time.


So, what I understand is:

- that your function check if the currency pair is one of the one allowed.


- that the rest of your code is supposed to print a message saying if it is allowed or not.


What I do not understand is:

- why shouldn't I add the other formats of the symbols such as USDJPYe and USDJPYm.


Here what I wrote.. Does it makes sense?

void OnTick()
  {
//---
    const string allowed_symbols1[] = {"USDJPY","USDJPYm","USDJPYe","EURJPY","EURJPYm","EURJPYe","CADJPY","CADJPYm","CADJPYe"};
    const string allowed_symbols2[] = {"EURCAD","EURCADm","EURCADe","GBPCAD","GBPCADm","GBPCADe","NZDCAD", "NZDCADm","NZDCADe","USDCAD","USDCADm","USDCADe"};

    bool allowed1 = is_allowed_symbol(_Symbol, allowed_symbols1);
    bool allowed2 = is_allowed_symbol(_Symbol, allowed_symbols2);
    
    if allowed1 == 1
      {
	//SET THE CALCUL OF THE LOT SIZE
      }
    else if allowed2 == 1
      {
	//SET THE CALCUL OF THE LOT SIZE
      }
   }


Thanks for your time and understanding