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では、OnInit()中にWindowFind()が-1を返します。ドキュメントには 常に、"WindowFind() は init() 関数が動作するときにカスタムインジケータが自分自身を検索する場合は -1 を返します。" と書かれています。
私のバージョンは610です。
更新されるたびに、どんどん悪い方向に進んでいるような気がします。
FFcalendarのインジケータを持っていました。
私はバージョン604でそれを修復して、うまくいっていました。
610にアップデートして、コンパイルし直したら、またエラーになりました...。
で、あきらめて509でコンパイルし直したんですが...。
WindowsFindのretun -1については、あなたの言うとおりです。
そのインディをアタッチした後に、TFを変更しても、結果はユニークなままです。
この投稿は非常に古いものですが、私がユニークなインスタンス名の問題を達成する方法を紹介します。 私は、グローバルターミナル変数の保存と一緒にGetTickCount()を組み合わせて使用しています。 これは、インスタンスのロードをまたいで動作します。
そして、次のようにOnInit()で呼び出すだけです。
今のところ、正常に動作しているようです。
本当にありがとうございました。この関数によって、私にとって本当に大きな問題が解決されました。
この投稿は非常に古いものですが、私がユニークなインスタンス名の問題を解決した方法を紹介します。 私は、グローバルターミナル変数の保存と一緒にGetTickCount()を組み合わせて使用しています。 これは、インスタンスのロードをまたいで機能します。
そして、次のようにOnInit()で呼び出すだけです。
今のところ、正常に動作しているようです。