Maximum length of a symbol name on FOREX - page 11

 
prostotrader:

It won't work.

Same EA on the same (different) symbols.

Add all instances to a string (you can also add a period character),

 
prostotrader:
If anyone has any ideas on how to get unique magiks for each order differently (without crutches), by

Please share.

int magic = (int)TimeCurrent();
int magic = (int)TimeLocal();
As an option, no headache.
 
prostotrader:

Time, thank you, will give uniqueness to each EA and there is no need to link to ChartID() and path to the EA,

But you will still need to save wizard in Global Variable of the terminal.

Time will not give uniqueness - restart terminal with all EAs enabled - all will have the same time)

 
Konstantin Nikitin:
As an option, no headache.

What if the user manages to cast 2 or 3 EAs in a second?

 
Taras Slobodyanik:

time will not give uniqueness - restart the terminal with EAs enabled - all will have the same time)

Yes, exactly

 
prostotrader:

What if the user manages to cast 2 or 3 EAs in a second?

Well, actually this is unlikely.

Taras Slobodyanik:

the time will not give uniqueness - restart the terminal with Expert Advisors enabled - all will have the same time)

But here we have another song. When restarting the EA, the Expert Advisor must continue to work with its magician to maintain previously opened positions. So remembering will not be a problem.

 
Konstantin Nikitin:

Well, it's actually not very likely.

This is a different story. When restarting, the Expert Advisor must continue to work with its magician to maintain previously opened positions. So remembering will not hurt.

I stopped at this variant for FOREX (FORTS without changes)

If someone comes up with a better one, please do not hesitate.

//+------------------------------------------------------------------+
//|                                                    AutoMagic.mqh |
//|                                 Copyright 2017-2018 prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
//version   "1.01
//#define FORTS
//---
#include ".\..\include\crc64.mqh"
//---
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 Magic function                                                |
//+------------------------------------------------------------------+
ulong GetMagic(const string a_symbol)
{
//--- Get ChartID
  symb_magic.ch_id = ChartID();
  if(SymbolSelect(Symbol(), true) == false)
  {
    Print(__FUNCTION__, ": Нет такого символа!");
    return(0);
  }
  if(symb_magic.ch_id != 0)
  {
#ifdef  FORTS
  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;
      return(symb_magic.magic);
    }
  }
#else
  uchar Bytes[];
  ulong result = crc64(0, Bytes, StringToCharArray(string(symb_magic.ch_id), Bytes, 0));
  if(result > 0)
  {
    symb_magic.magic = result<<12;
    if(ulong(GlobalVariableSet(Symbol() + ":" + DoubleToString(double(symb_magic.magic), 0), double(symb_magic.magic))) > 0)
    {
      Print("Terminal Global variable created.");
    }
    return(symb_magic.magic);
  }
#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;
    ulong in_magic = m_magic;
#ifdef  FORTS  
    stored_magic>>=16;
    in_magic>>=16;
    if(in_magic == stored_magic) return(true);
#else
   stored_magic>>=12;
  in_magic>>=12;
  if(m_magic == symb_magic.magic) return(true);
#endif     
  }
  return(false);
}
//-------------------------------------------------------------------+
// Get stired magic function                                         |
//+------------------------------------------------------------------+
ulong GetStoredMagic(const long cha_id)
{
  if(cha_id == symb_magic.ch_id)
  {
    return(symb_magic.magic);
  }
  return(0);  
}
//+------------------------------------------------------------------+

The Expert Advisor should have

//+------------------------------------------------------------------+
//|                                                   Magic_test.mq5 |
//|                                      Copyright 2018 prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018 prostotrader"
#property link      "https://www.mql5.com"
#property version   "1.00"
#include   "AutoMagic.mqh"

ulong a_magic;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {

  a_magic = GetMagic(Symbol());
  if(a_magic != 0)
  {
    if(IsMyMagic(a_magic, ChartID()) == true)
    {
      Print("Magic = ", a_magic);
    }
  }
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  
    string a_name = Symbol() + ":" + DoubleToString(double(a_magic), 0);
    if(GlobalVariableCheck(a_name) == true)
    {
      GlobalVariableDel(a_name);
      Print("Terminal Global variable deleted.");
    }
  }
 
ChartID()

also changes on restart, and the EA will not be able to continue working with the same labels (unless you save them)

The uniqueness of each copy of the EA in parameters (inputs) and in the symbol.
Then, the label does not need to be saved, it will be the same for the same Expert Advisor-parameters.

 
prostotrader:

I've settled on this version for FOREX (FORTS without changes)

If someone comes up with a better one - you are welcome.

The question was on each position a unique magician. It occurred to me now. It is easier to take the last ticket and set it as a magik. I similar applied in the copier. Took the ticket of position from a server part and assigned it to position which was opened by magician in clients. Also works without any extra efforts.

 
Konstantin Nikitin:

The question went to each position a unique magician. Now I'm thinking. It's easier to take the last ticket and put it as a magik. I used the similar in the copier. Took position's ticket from server part and assigned it to position opened by magician in clients. Also it works without any extra efforts.

I have to have my own master for each order.

You are right, when you reload the ChartID will change, therefore, we do not need to save anything in Global Variables of the terminal.

//+------------------------------------------------------------------+
//|                                                    AutoMagic.mqh |
//|                                 Copyright 2017-2018 prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
//version   "1.01
//#define FORTS
//---
#include ".\..\include\crc64.mqh"
//---
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 Magic function                                                |
//+------------------------------------------------------------------+
ulong GetMagic(const string a_symbol)
{
//--- Get ChartID
  symb_magic.ch_id = ChartID();
  if(SymbolSelect(Symbol(), true) == false)
  {
    Print(__FUNCTION__, ": Нет такого символа!");
    return(0);
  }
  if(symb_magic.ch_id != 0)
  {
#ifdef  FORTS
  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;
      return(symb_magic.magic);
    }
  }
#else
  uchar Bytes[];
  ulong result = crc64(0, Bytes, StringToCharArray(string(symb_magic.ch_id), Bytes, 0));
  if(result > 0)
  {
    symb_magic.magic = result<<12;
    return(symb_magic.magic);
  }
#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;
    ulong in_magic = m_magic;
#ifdef  FORTS  
    stored_magic>>=16;
    in_magic>>=16;
    if(in_magic == stored_magic) return(true);
#else
   stored_magic>>=12;
  in_magic>>=12;
  if(m_magic == symb_magic.magic) return(true);
#endif     
  }
  return(false);
}
//-------------------------------------------------------------------+
// Get stщred magic function                                         |
//+------------------------------------------------------------------+
ulong GetStoredMagic(const long cha_id)
{
  if(cha_id == symb_magic.ch_id)
  {
    return(symb_magic.magic);
  }
  return(0);  
}
//+------------------------------------------------------------------+
#property copyright "Copyright 2018 prostotrader"
#property link      "https://www.mql5.com"
#property version   "1.00"
#include   "AutoMagic.mqh"

ulong a_magic;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {

  a_magic = GetMagic(Symbol());
  if(a_magic != 0)
  {
    if(IsMyMagic(a_magic, ChartID()) == true)
    {
      Print("Magic = ", a_magic);
    }
  }
   
//---
   return(INIT_SUCCEEDED);
  }
Reason: