Unique ID Generator for a Particular Indicator - page 4

 
gchrmt4:
I don't know which version of MT4 you are using, but on v616 on my computer, WindowFind() returns -1 during OnInit(). The documentation has always said "WindowFind() returns -1 if custom indicator searches itself when init() function works."


my version is 610.

oh my God.. every updates seem to be more bad and more bad.. not getting better.

i had an FFcalendar indicator.

i had repaired it with version 604.. and working well.

when i update to 610.. and i compiled it again.. it became error again..

so i give up.. and compiled again with version 509... hahaha ( because my version 604 has gone)


oops sorry.. you are right about WindowsFind retun -1 .

it only show when after i attach that indi.. then i change TF.. but the resulst is still unique

tag

 
Comments that do not relate to this topic, have been moved to "Fib levels".
 

I know this post is VERY old, but here's how I accomplish the unique instance name problem.  I use a combination of GetTickCount() along with global terminal variable storage.  This also works across instance loads.

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()));
}


And then simply call it in OnInit() as follows:

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


So far, appears to work properly.

 

Thank you soo much. This funcion solved a really big problem to me.


cdxadmin:

I know this post is VERY old, but here's how I accomplish the unique instance name problem.  I use a combination of GetTickCount() along with global terminal variable storage.  This also works across instance loads.


And then simply call it in OnInit() as follows:


So far, appears to work properly.

Reason: