Maximum length of a symbol name on FOREX - page 5

 
prostotrader:

If there is a position, all data can be retrieved when the chart is closed, and pending orders on this symbol can simply be 'nailed down'.

What to get it for? The serious disadvantage of your variant is exactly the binding to the chart handle.

No one has thought of a better one (for opening several EAs on one and the same symbol).

It is possible to detach from the handle, but in this case, we have to connect it to something else. For example, to the input parameters of the EA + path to it. However, this solution has its own disadvantage, too.

 
prostotrader:

On Roboforex AUDNZD works

Print(GetForexName("AUDNZD"));
 
fxsaber:

So what if the EA is cut off by closing the chart at a time when there are its positions/orders?


Not quite sure why something like this didn't work for Forex

Because it is not clear what to place first

For EURUSD the base is EUR and forAUDNZD the base is NZD

 
//+------------------------------------------------------------------+
//|                                                    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)
{
  string s_base = SymbolInfoString(Symbol(), SYMBOL_CURRENCY_BASE);
  string a_prof = SymbolInfoString(Symbol(), SYMBOL_CURRENCY_PROFIT);
  if(StringLen(s_base) == 3)
  {
    int base_pos = StringFind(a_str, s_base, 0);
    if(base_pos > -1)
    {
      switch(base_pos)
      {
        case 0:
        case 1:
        case 2:
          return(StringSubstr(a_str, base_pos, 6));
        break;
        default:
          {
            string left_str = StringSubstr(a_str, base_pos - 3, 3);
            string right_str = StringSubstr(a_str, base_pos + 3, 3);
            if(right_str == "")
            {
              return(StringSubstr(a_str, base_pos - 3, 6));
            }
            else
            if(StringLen(right_str) < 3)
            {
              return(StringSubstr(a_str, base_pos - 3, 6));
            }
            else
            {
              bool is_match = true;
              uchar uch_array[];
              int result = StringToCharArray(right_str, uch_array, 0, WHOLE_ARRAY, CP_ACP);
              if(result == 4)
              {
                for(int i=0; i < result - 1; i++)
                {
                  if((uch_array[i] < 65) || (uch_array[i] > 90))
                  {
                    is_match = false;
                    break;
                  } 
                }
                if(is_match == true)
                {
                  return(StringSubstr(a_str, base_pos, 6));  
                }
                else
                {
                  is_match = true;
                  result = StringToCharArray(left_str, uch_array, 0, WHOLE_ARRAY, CP_ACP);
                  if(result == 4)
                  {
                    for(int i=0; i < result - 1; i++)
                    {
                      if((uch_array[i] < 65) || (uch_array[i] > 90))
                      {
                        is_match = false;
                        break;
                      } 
                    }
                    if(is_match == true)
                    {
                      return(StringSubstr(a_str, base_pos - 3, 6));  
                    }  
                  } 
                }
              }  
            }
          }
        break;  
      }
    }
  }
  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 != "")
  { 
    Print("in_str = ", 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);
}
//+------------------------------------------------------------------+
2018.08.25 15:29:02.174 Magic_test (AUDNZD,M1)  in_str = AUDNZD
2018.08.25 15:29:02.384 Magic_test (AUDNZD,M1)  FOREX done.
int OnInit()
  {

  ulong a_magic = GetMagic(Symbol());
  if(a_magic != 0)
  {
    a_magic+=25;
    if(IsMyMagic(a_magic, ChartID()) == true)
    {
      Print("FOREX done.");
    }
  }
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
 

There is a way to store the magik in a TERMINAL global variable, then nothing is lost at all

I'll write it now.

 
prostotrader:

There is a way to store the magik in a TERMINAL global variable, then nothing is lost at all

I'll write it down.

When it crashes, it is killed.

 
prostotrader:

Because it is not clear what to put first

For EURUSD the base is EUR and forAUDNZD the base is NZD

Always

Forum on trading, automated trading systems and trading strategies testing

Maximum length of a symbol name on FOREX

fxsaber, 2018.08.25 14:12

string GetForexName( const string Symb )
{
  return(SymbolIsExist(Symb) ? SymbolInfoString(Symb, SYMBOL_CURRENCY_BASE) + SymbolInfoString(Symb, SYMBOL_CURRENCY_PROFIT) : NULL);
}

You are making up a bicycle called "not a universal hash function". Here is a simple variant, with the same functionality as yours

#include <crc64.mqh> // https://www.mql5.com/en/blogs/post/683577

string GetMagicString()
{
  return(MQLInfoString(MQL_PROGRAM_PATH/*MQL_PROGRAM_NAME*/) + _Symbol + (string)ChartID()/* + (string)_Period*/);
}

ulong GetMagic()
{
  uchar Bytes[];
  
  return(crc64(0, Bytes, StringToCharArray(GetMagicString(), Bytes)));
}
  
void OnStart()
{
  Print(GetMagic());
}
 
fxsaber:

It's always like this.


You're making up a bicycle called "not a universal hash function". Here's a simple variant, with the same functionality as yours

The last two bytes are reserved for additional magicians on this chart

But I forgot about CRC that it is in MQL :) thanks

Then there won't be any problem at all.

fxsaber: thanks

 
Vitaly Muzichenko:

When it crashes, it is killed.

That's whyglobal terminalvariables are created, so they don't get 'killed'


 
fxsaber:

It's always like this.


You're making up a bicycle called "not a universal hash function". Here is a simple variant, with the same functionality as yours

Your variant will not work, because you can run the same EA on the same symbol