Check the name of the base currency - page 3

 
Luciole:

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


I think I understand it. 

I isolated this code in a program but I cannot make it work, so I cannot be sure.

(I was hoping to understand better and expected something to be printed, as I put the indicator on a USDJPY chart)


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


What I do not understand is:

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

- and also why isolated it does not work.. (but it first seems related to the print function that I cannot make work)


What I wrote.. Does it makes sense?




Again, DRY. You should think,  "how can I make this intelligently so I can be as lazy as possible?"

If you alter the is_allowed_symbol function to use StringFind then you ensure that all you need is to use the regular symbol without the ECN sufffix.  

bool is_allowed_symbol(const string symbol, const string &allowed[])
{
   for(int i=ArraySize(allowed)-1; i>=0; --i)
      if(StringFind(symbol, allowed[i]) >= 0) //Find allowed[i] in symbol
         return true;
   return false;
}

void test()
{
   const string allowed_symbols1[] = {
      "USDJPY", "EURJPY", "CADJPY"
   };
   const string allowed_symbols2[] = {
      "EURCAD", "GBPCAD", "NZDCAD", "USDCAD"
   };
   bool allowed1 = is_allowed_symbol(_Symbol, allowed_symbols1);
   bool allowed2 = is_allowed_symbol(_Symbol, allowed_symbols2);
   
   if(allowed1)
   {
           //SET THE CALCUL OF THE LOT SIZE
   }
   else if(allowed2)
   {
           //SET THE CALCUL OF THE LOT SIZE
   }
}


Also, you don't need to use the equality operator when you use booleans or bool funcs in expressions. 

bool var = true;
if(var == true)
if(var)
if(var == false)
if(!var)

if(bool_func() == false)
if(!bool_func())
 
nicholi shen:

Again, DRY. You should think,  "how can I make this intelligently so I can be as lazy as possible?"

If you alter the is_allowed_symbol function to use StringFind then you ensure that all you need is to use the regular symbol without the ECN sufffix.  


Also, you don't need to use the equality operator when you use booleans or bool funcs in expressions. 

Got it !

Thanks a lot for your time and clear explanations.

:)

Luciole

Reason: