Maximum length of a symbol name on FOREX - page 2

 

Actually I wanted to do something nice for FORES, but I guess it wasn't meant to be.

Long time ago I wrote a plug-in file for Magic, and now I tweaked it

I decided to do it for forex, but it was not meant to be.

If someone adds functionGetForexName to it, it will work for FOREX too.

//+------------------------------------------------------------------+
//|                                                    AutoMagic.mqh |
//|                                 Copyright 2017-2018 prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
//version   "1.01
#define  FORTS
//---
struct SYMBOL_MAGIC
{
  long ch_id;
  ulong magic;
};
SYMBOL_MAGIC symb_magic;
//-------------------------------------------------------------------+
// Split string function                                             |
//+------------------------------------------------------------------+
string SplitString(const string a_str,ulong &a_month,ulong &a_year)
  {
   int str_size=StringLen(a_str);
   int str_tire=StringFind(a_str, "-");
   int str_tochka=StringFind(a_str, ".", str_tire);
   if((str_tire>0) && (str_tochka>0) &&(str_size > 0))
     {
      a_month= ulong(StringToInteger(StringSubstr(a_str,str_tire+1,str_tochka-str_tire-1)));
      a_year = ulong(StringToInteger(StringSubstr(a_str,str_tochka+1,str_size-str_tochka-1)));
      if((a_month > 0) && (a_year > 0)) return(StringSubstr(a_str, 0, str_tire));
     }
   return("");
  }
//-------------------------------------------------------------------+
// Get FOREX symbol function                                       |
//+------------------------------------------------------------------+
string GetForexName(const string a_str)
{
  //??????? Из любого названия пары функция долна возвращать ТОЛЬКО саму пару (н-р UERUSD)
  return("");
}  
//-------------------------------------------------------------------+
// Get Magic function                                                |
//+------------------------------------------------------------------+
ulong GetMagic(const string a_symbol)
{
//--- Get ChartID
  symb_magic.ch_id = ChartID();
//---
  if(SymbolSelect(Symbol(), true) == false)
  {
    Print(__FUNCTION__, ": Нет такого символа!");
    return(0);
  }  
#ifdef  FORTS
//--- Test symdol
  if(StringLen(a_symbol)>10)
  {
    Print(__FUNCTION__, ": Не правильный символ!");
    return(0);
  }
  if(symb_magic.ch_id != 0)
  {
    ulong month = 0;
    ulong year = 0;
    string new_str=SplitString(a_symbol,month,year);
    if(StringLen(new_str)>0)
    {
      symb_magic.magic = 0;
      uchar char_array[];
      int result=StringToCharArray(new_str,char_array,0,WHOLE_ARRAY,CP_ACP);
      if(result>0)
      {
        ulong value;
        for(int i = 0; i < result - 1; i++)
        {
          value=ulong(char_array[i]);
          value<<=(56 -(i*8));
          symb_magic.magic += value;
        }
        month<<=24;
        symb_magic.magic += month;
        year<<=16;
        symb_magic.magic += year;
        ulong a_chid = ulong(symb_magic.ch_id);
        a_chid<<=16;
        return(symb_magic.magic&=symb_magic.ch_id);
      }
    }
  }
#else
  string in_str = GetForexName(a_symbol);
  if(in_str != "")
  { 
    symb_magic.magic = 0;
    uchar char_array[];
    int result=StringToCharArray(a_symbol,char_array,0,WHOLE_ARRAY,CP_ACP);
    if(result>0)
    {
      ulong value;
      for(int i = 0; i < 6; i++)
      {
        value=ulong(char_array[i]);
        value<<=(56 -(i*8));
        symb_magic.magic += value;
      }  
      ulong a_chid = ulong(symb_magic.ch_id);
      a_chid<<=16;
      return(symb_magic.magic&=symb_magic.ch_id);
    }
  }
#endif    
  return(0); 
}
//-------------------------------------------------------------------+
// Is my magic function                                              |
//+------------------------------------------------------------------+
bool IsMyMagic(const ulong m_magic, const long chart_id)
{
  if(symb_magic.ch_id == chart_id)
  {
    ulong stored_magic=symb_magic.magic;
    stored_magic>>=16;
    ulong in_magic = m_magic;
    in_magic>>=16;
    if(in_magic == stored_magic) return(true);
  }
  return(false);
}
//+------------------------------------------------------------------+

The last 2 bytes are used to use a lot of wizards in one EA.

chart_id - is used to identify the chart (you can open as many identical symbols as you want)

Before any work with Magic, call the functionIsMyMagic, which will check if the magician belongs to the given EA

 
prostotrader:

It's just not clear how to analyse a symbol if it can have anything in front of it :(

Create an array of used currencies, for example "EUR" "USD" "JPY"
Then use this function to pair all possible combinations, for example "EURUSD" "EURJPY" "USDEUR" "USDJPY" "JPYEUR" "JPYUSD".
And each time you check if there is an occurrence of this combination in the name of the symbol you are analyzing. If there is an occurrence - the six-letter name is found.

 
Andrei Fandeev:

Create an array of used currencies, for example "EUR" "USD" "JPY".
Then use this function to pair all possible combinations, for example "EURUSD" "EURJPY" "USDEUR" "USDJPY" "JPYEUR" "JPYUSD".
And each time you check if there is an occurrence of this combination in the name of the symbol you are analyzing. If there is an occurrence - the six-letter name is found.

Do everyone a favour, add theGetForexName function

 
prostotrader:

Thanks, but I only need to get the "bare" name of the pair (6 characters).

Maybe someone has a ready-made solution?

Added

It's just not clear how to analyse a symbol if it can have anything in front of the pair itself :(

copiers often use 2 parameters prefix and suffix (an additional symbol before EURUSD or after)

 
prostotrader:

Thanks, but I only need to get the "bare" name of the pair (6 characters).

Maybe someone has a ready-made solution?

Added

It's just not clear how to analyse a symbol if it can have anything in front of the pair itself :(

StringFind

 

it depends on the broker I remember a situation that threw me into a kind of stupor - the client had an error, which really freaked me out and I figured that I would have to write crude kits for symbol recognition

2016.10.16 13:08:51.633 2016.08.25 04:39 Expert EURUSD(€),M15: OrderSend error 4106

2016.10.16 13:08:51.633 2016.08.25 04:40 Expert EURUSD(€),M15: unknown symbol name EURUSD(ˆ) for OrderSend function

 
prostotrader:

In forex there are symbols mostly with suffixes, with prefixes very rarely, but always the base (pair) is written in capital letters and all the prefixes in small letters, so you can build on that.

 
Vitaly Muzichenko:

In forex there are symbols with suffixes mostly, prefixes very rarely, but always the base (pair) is written in capital letters and all prefixes in small letters, so this is a good starting point.

It's more reliable, especially if it's an input parameter to reduce everything to single case StringToLower or StringToUpper and search StringFind. Then it doesn't matter where or what is added.

 

if only currency pairs are used:

For SymbolInfoString()

ENUM_SYMBOL_INFO_STRING

Identifier

Description

Property type

SYMBOL_BASIS

Name of the underlying asset for the derivative

string

SYMBOL_CURRENCY_BASE

Base currency of the instrument

string

SYMBOL_CURRENCY_PROFIT

Profit currency

string

SYMBOL_CURRENCY_MARGIN

Currency in which the margin is calculated

string

SYMBOL_BANK

Current quote source

string

SYMBOL_DESCRIPTION

String description of the symbol

string

SYMBOL_FORMULA

Formula for constructing the price of a custom symbol

string

SYMBOL_ISIN

Name of a trading symbol in the International Securities Identification Number (ISIN) system. The International Securities Identification Number is a 12-digit alphanumerical code which uniquely identifies a security. The presence of this characteristic is defined on the trade server side.

string

SYMBOL_PAGE

Address of the web page containing information on the symbol. This address will be displayed as a link when viewing the symbol properties in the terminal

string

SYMBOL_PATH

Path in the symbol tree

string

 
Konstantin Nikitin:

It is more reliable, especially if it is an input parameter, to reduce everything to a single case StringToLower or StringToUpper and search StringFind. Then it doesn't matter where or what is added.

But I don't understand the problem, why a character cannot be substituted there immediately, regardless of its length

Reason: