Longueur maximale d'un nom de symbole sur le FOREX - page 4

 

Maintenant, vous pouvez également l'utiliser sur le FOREX (en prenant n'importe quel caractère "croche", même tel que _BTCUSD_i).

//+------------------------------------------------------------------+
//|                                                    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);
  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 != "")
  { 
    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);
}
//+------------------------------------------------------------------+
 
prostotrader:

Maintenant, vous pouvez l'utiliser sur le FOREX (accepte n'importe quel caractère "croche", même tel que _BTCUSD_i)

A la kodobase

 
prostotrader:

Il y a longtemps, j'ai écrit un fichier plug-in pour récupérer automatiquement Magic

Quelle était la tâche ?

Veuillez vérifier si le message "FOREX fait." apparaît sur les symboles "tordus".

Il n'apparaît pas sur "EURUSD".

Le symbole de base est-il toujours le premier de la paire ?

Les symboles personnalisés peuvent avoir n'importe quoi. C'est probablement le moyen le plus pratique d'effectuer de telles vérifications sur des modèles personnalisés.


SZ

Forum sur le trading, les systèmes de trading automatisés et les tests de stratégie

Bibliothèques : AutoMagic

Dmitry Fedoseev, 2017.02.03 13:31

L'utilisation d'une poignée de graphique pour former une magie signifie que si le graphique est fermé accidentellement, les ordres seront perdus.

 
fxsaber:

N'apparaît pas sur l'EURUSD.

SZY

Corrigé

Ajouté à ZY

Écrire quelque chose de mieux

 
prostotrader:

Corrigé

Ça marche maintenant. J'aimerais maintenant entendre quelques mots sur le côté pratique des choses.


ZS "AUDNZD"...

 
fxsaber:

Ça marche maintenant. J'aimerais maintenant entendre quelques mots sur le côté pratique des choses.


ZS "AUDNZD"...

Crée automatiquement un Magik unique pour l'EA sur le graphique avec la possibilité d'utiliser 65535 Magiks supplémentaires.

Ajouté

Je n'ai pas de FOREX.

J'ai écrit la fonctionGetForexName sans vérifier

 
prostotrader:

Crée automatiquement un Magik unique pour l'EA sur le graphique avec la possibilité d'utiliser 65535 Magiks supplémentaires.

Et si l'EA est coupé par la fermeture du graphique à un moment où il y a ses positions/ordres ?


Je ne sais pas vraiment pourquoi quelque chose comme ça n'a pas fonctionné pour le Forex.

bool SymbolIsExist( const string Symb = NULL )
{
  ResetLastError();

  SymbolInfoInteger((Symb == NULL) ? _Symbol : Symb, SYMBOL_CUSTOM);

  return(::GetLastError() != ERR_MARKET_UNKNOWN_SYMBOL);
}

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

void OnStart()
{
  Print(GetForexName(_Symbol));
}
 
prostotrader:

Je n'ai pas de FOREX.

Faire - MQ-Demo.

 
fxsaber:

Et si l'EA est coupé par la fermeture du graphique à un moment où il y a une position/un ordre ?


S'il y a une position, toutes les données peuvent être récupérées lorsque le graphique est fermé, et les ordres en attente sur ce symbole peuvent simplement être "cloués".

Personne n'a encore trouvé une meilleure idée (pour ouvrir plusieurs EA sur le même symbole).

 
fxsaber:

ZS "AUDNZD"...

AUDNZD fonctionne sur Roboforex