Need help for using SymbolExist() in mq5 format

To add comments, please log in or register
budiali
58
budiali  
Can anyone help me to give some simple example on how to use SymbolExist() in EA of MT5 ? Thank you
Vladimir Karputov
Moderator
160805
Vladimir Karputov  
budiali :
Can anyone help me to give some simple example on how to use SymbolExist() in EA of MT5 ? Thank you

For example:

string current_symbol=Symbol();
double point=SymbolInfoDouble(current_symbol,SYMBOL_POINT);
double volume_min=SymbolInfoDouble(current_symbol,SYMBOL_VOLUME_MIN);
budiali
58
budiali  

I mean some example for this instruction:

bool  SymbolExist(
   const string  name,    // symbol name
   bool&   is_custom      // custom symbol property
   );

like: if the symbol exist then X=1; or

        if the symbol not exist then X=0

Vladimir Karputov
Moderator
160805
Vladimir Karputov  
budiali :


Function SymbolExist

Example of use: You write a multi-symbol Expert Advisor (an Expert Advisor that can trade several symbols at once). In the input parameters you specify symbol names. Before starting work, the adviser should check: Have you set the correct symbols?

//+------------------------------------------------------------------+
//|                                                  SymbolExist.mq5 |
//|                              Copyright © 2019, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
//--- input parameters
input string   InpSymbol_0 = "EURUSD"; // Symbol #0
input string   InpSymbol_1 = "EURUSF"; // Symbol #1
input string   InpSymbol_2 = "USDJPY"; // Symbol #2
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   bool is_custom=false;
   if(!SymbolExist(InpSymbol_0,is_custom))
     {
      Print(__FILE__," ",__FUNCTION__,", ERROR: Symbol #0 (",InpSymbol_0,") is not exist");
      return(INIT_FAILED);
     }
   if(!SymbolExist(InpSymbol_1,is_custom))
     {
      Print(__FILE__," ",__FUNCTION__,", ERROR: Symbol #1 (",InpSymbol_1,") is not exist");
      return(INIT_FAILED);
     }
   if(!SymbolExist(InpSymbol_2,is_custom))
     {
      Print(__FILE__," ",__FUNCTION__,", ERROR: Symbol #2 (",InpSymbol_2,") is not exist");
      return(INIT_FAILED);
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+

Result:

2019.10.19 08:00:27.375 SymbolExist (EURUSD,M1) SymbolExist.mq5 OnInit, ERROR: Symbol #1 (EURUSF) is not exist
Files:
budiali
58
budiali  
ok, thank you very much
budiali
58
budiali  
Vladimir Karputov:

Function SymbolExist

Example of use: You write a multi-symbol Expert Advisor (an Expert Advisor that can trade several symbols at once). In the input parameters you specify symbol names. Before starting work, the adviser should check: Have you set the correct symbols?

Result:

Can you convert that the EA print if the symbol exist ?  I am still confused on the bool i_custom, Thank you.

Vladimir Karputov
Moderator
160805
Vladimir Karputov  
budiali :

Can you convert that the EA print if the symbol exist ?  I am still confused on the bool i_custom, Thank you.

The variable is_custom is not used.

And the rest: I could not understand your question.

budiali
58
budiali  
Vladimir Karputov:

The variable is_custom is not used.

And the rest: I could not understand your question.

ok thanks

To add comments, please log in or register