indicator から script を実行する。

トレメの投資顧問・プロ部門で確認できる Rob Booker のシグナル ( RBJ MA ) の結果が凄いらしいですね...^^;
シグナル紹介のページでは、

マンデーアクセラレーター手法について:
ロブ・ブッカ―と世界中のロブのトレーディングパートナーたちにより3年間にわたってバックテスト・検証を行った集大成の手法です。この手法はロブの2daysセミナーやマンツーマントレーニングを通してのみで教えており、またロブ自身もこの手法を使って自身のトレードを行っています。
検証とバックテストの中で、ロブは、マーケットが予測した方向へと非常に速いスピードで動くマーケットのパターンを発見し、そのパターンの中で、短時間の間に勝率の高いトレードを行うことができるよう、1つのポジションだけでなく複数のポジションを入れるトレード方法を考案しました。この手法を使ったトレードは通常30分から48時間で終わり、勝率も70−90%という結果が出ています。

と、興味を引かれるのですが、今日までの成績は、


で、今週にも -3000pipsの大台に突入か?という状況です。
勝率70% なら 6連敗も 0.05% より高い確率で起こりますから、運が悪ければこういう事態も有り得る..と思いますが、配信直後の DD が痛ましいです...。-3000で退場?という話しも聞くのですが、どうなることやら…。




さて、表題の通り、indicator から script や EA を呼び出すコードが公式フォーラムにあったので紹介しておきます。
http://forum.mql4.com/20946
細かく動作検証したわけではないのですが、まぁ、そういうことも可能なのかな..と思ってます。


使い方は、下記コードをコピーして、呼び出し時には、
StartScript(WindowHandle(Symbol(),0),"OrderSc");
のようにします。
PostMessageA の引数の4番目が文字列になっているのが、私的に謎なんですけど..正しく動きます..@@;

// Import of functions from User32. If their purpose isn't pretty much immediately
// clear, then documenting it here frankly isn't going to help much. Requires 
// "Allow DLL imports" to be turned on.

#import "user32.dll"
   int RegisterWindowMessageA(string MessageName);
   int PostMessageA(int hwnd, int msg, int wparam, string Name);
   void keybd_event(int VirtualKey, int ScanCode, int Flags, int ExtraInfo);
#import

// The hWnd parameter for all these functions is obtained using WindowHandle().
// For example, an EA/script can get the handle of its own chart using
// WindowHandle(Symbol(), 0). If the EA/script knows that another chart 
// is open, then its handle can be obtained using the known symbol and
// timeframe. Unpredictable behaviour if there are multiple charts for 
// the same symbol and timeframe. AutomaticallyAcceptDefaults clears
// the configuration window for the new indicator/EA/script by simulating
// a press of the Enter key after a small wait. A longer wait might 
// prove to be more robust. None of this is for the faint-hearted...

void StartStandardIndicator(int hWnd, string IndicatorName, bool AutomaticallyAcceptDefaults = false)
{
   int MessageNumber = RegisterWindowMessageA("MetaTrader4_Internal_Message");
   PostMessageA(hWnd, MessageNumber, 13, IndicatorName);
   if (AutomaticallyAcceptDefaults) ClearConfigDialog();
}
void StartCustomIndicator(int hWnd, string IndicatorName, bool AutomaticallyAcceptDefaults = false)
{
   int MessageNumber = RegisterWindowMessageA("MetaTrader4_Internal_Message");
   PostMessageA(hWnd, MessageNumber, 15, IndicatorName);
   if (AutomaticallyAcceptDefaults) ClearConfigDialog();
}
void StartEA(int hWnd, string EAName, bool AutomaticallyAcceptDefaults = false)
{
   int MessageNumber = RegisterWindowMessageA("MetaTrader4_Internal_Message");
   PostMessageA(hWnd, MessageNumber, 14, EAName);
   if (AutomaticallyAcceptDefaults) ClearConfigDialog();
}
void StartScript(int hWnd, string ScriptName, bool AutomaticallyAcceptDefaults = false)
{
   int MessageNumber = RegisterWindowMessageA("MetaTrader4_Internal_Message");
   PostMessageA(hWnd, MessageNumber, 16, ScriptName);
   if (AutomaticallyAcceptDefaults) ClearConfigDialog();
}
void ClearConfigDialog()
{
   Sleep(100);
   keybd_event(13, 0, 0, 0);
}