Generatore di ID unico per un particolare indicatore - pagina 4

 
gchrmt4:
Non so quale versione di MT4 stai usando, ma sulla v616 sul mio computer, WindowFind() restituisce -1 durante OnInit(). La documentazione ha sempre detto "WindowFind() restituisce -1 se l'indicatore personalizzato cerca se stesso quando la funzione init() funziona".


la mia versione è 610.

oh mio Dio... ogni aggiornamento sembra essere sempre più brutto e sempre più brutto... non migliora.

Avevo un indicatore FFcalendar.

Avevo riparato con la versione 604... e lavorando bene.

quando ho aggiornato a 610 ... e l'ho compilato di nuovo ... è diventato di nuovo errore ...

così mi arrendo... e compilato di nuovo con la versione 509... hahaha (perché la mia versione 604 è andato)


ops scusa... hai ragione su WindowsFind retun -1.

si vede solo quando dopo che ho allegato quell'indi... poi cambio TF... ma il risultato è ancora unico

tag

 
I commenti che non si riferiscono a questo argomento, sono stati spostati in "Livelli Fib".
 

So che questo post è MOLTO vecchio, ma ecco come risolvo il problema del nome unico dell'istanza. Uso una combinazione di GetTickCount() insieme alla memorizzazione globale della variabile terminale. Questo funziona anche attraverso i carichi di istanza.

const string _uniqueSeedVarName = "MyVar";
string GetUniqueInstanceName(const string baseName)
{
   uint seed = 1;

   // See if our last stored unique seed value exists
   if (GlobalVariableCheck(_uniqueSeedVarName))
   {
      // It does, so get it
      seed = (uint)GlobalVariableGet(_uniqueSeedVarName);

      // Do some boundary checking and ensure the user didn't muck with the value
      // If we're okay, increment the seed by one      
      if (seed > 0 && seed < UINT_MAX)
         seed = seed + 1;
      else
         // The seed has been corrupted by the user or is too large; reset to current tick count
         seed = GetTickCount();   
   }
   else
      // First time in; initialize the seed to the current tick count
      seed = GetTickCount();

   // Store the value in global terminal variables
   // The user DOES have access to this value, so the handling above should account for any changes the user might make
   GlobalVariableSet(_uniqueSeedVarName, seed);

   // Initialize the random generator
   MathSrand(seed);
  
   // Create a unique instance name in the format of "[BaseName][Random1][Random2]"
   return StringFormat("%s%s%s", baseName, IntegerToString(MathRand()), IntegerToString(MathRand()));
}


E poi semplicemente lo chiamo in OnInit() come segue:

   Print(StringFormat("Indicator Id: %s", GetUniqueInstanceName("Sandbox")));


Finora, sembra funzionare correttamente.

 

Grazie mille. Questa funzione ha risolto un problema molto grande per me.


cdxadmin:

So che questo post è MOLTO vecchio, ma ecco come risolvo il problema del nome unico dell'istanza. Uso una combinazione di GetTickCount() insieme alla memorizzazione globale della variabile terminale. Questo funziona anche attraverso i carichi di istanza.


E poi semplicemente lo chiamo in OnInit() come segue:


Finora, sembra funzionare correttamente.

Motivazione: