conststring _uniqueSeedVarName = "MyVar";
string GetUniqueInstanceName(conststring baseName)
{
uint seed = 1;
// See if our last stored unique seed value existsif (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 makeGlobalVariableSet(_uniqueSeedVarName, seed);
// Initialize the random generatorMathSrand(seed);
// Create a unique instance name in the format of "[BaseName][Random1][Random2]"returnStringFormat("%s%s%s", baseName, IntegerToString(MathRand()), IntegerToString(MathRand()));
}
我不知道你使用的是哪个版本的MT4,但在我的电脑上的v616版本,WindowFind()在OnInit()期间返回-1。文档 中一直说 "WindowFind()返回-1,如果自定义指标在init()函数工作时搜索自己"。
我的版本是610。
哦,我的上帝......每一次的更新似乎都是越来越糟,越来越糟......没有好转。
我有一个FFcalendar指标。
我已经用604版本修复了它......而且工作得很好。
当我更新到610时......我再次编译它......它又变得错误了。
所以我放弃了......用509版本重新编译......哈哈哈(因为我的604版本已经消失了)。
对不起......关于WindowsFind retun -1你是对的。
它只在我附加了那个indi之后才显示......然后我改变了TF......但结果仍然是唯一的。
我知道这个帖子已经很老了,但我是这样完成唯一的实例名称问题的。 我使用GetTickCount()和全局终端变量存储的组合。 这也适用于跨实例加载。
然后在OnInit()中简单地调用它,如下所示。
到目前为止,似乎工作正常。
非常感谢你。这个功能对我来说解决了一个非常大的问题。
我知道这个帖子已经很老了,但我是这样完成唯一的实例名称问题的。 我使用GetTickCount()和全局终端变量存储的组合。 这也可以在实例加载时使用。
然后在OnInit()中简单地调用它,如下所示。
到目前为止,似乎工作正常。