関数 | 詳細 |
PlaySound() | サウンドファイルを再生します |
ObjectCreate() | グラフィカルオブジェクトのOBJ_BITMAPとOBJ_BITMAP_LABELを使用して、
bmpファイルを使ったユーザーインターフェースを作成出来ます。 |
void OnInit(){ PlaySound("Ok.wav"); }
void OnInit(){ string terminal_path; terminal_path = TerminalInfoString(TERMINAL_PATH); // ターミナルディレクトリパスを取得 Print(terminal_path); }
void OnInit(){ string terminal_path; terminal_path = TerminalInfoString(TERMINAL_DATA_PATH); // データディレクトリパスを取得 Print(terminal_path); }
void OnInit(){ PlaySound("\\Files\\demo.wav"); }
#define OBJ_TEST_NAME "ObjectTest" string bmp_on = "\\Include\\Controls\\res\\CloseDisable.bmp"; // 画像ファイルのパス・ファイル名 string bmp_off = "\\Include\\Controls\\res\\CloseOn.bmp"; // 画像ファイルのパス・ファイル名 //+------------------------------------------------------------------+ //| 初期化 //+------------------------------------------------------------------+ void OnInit() { bool created; bool button_set; ObjectsDeleteAll(); // オブジェクト全削除 created = ObjectCreate(0,OBJ_TEST_NAME,OBJ_BITMAP_LABEL,0,0,0); // OBJ_BITMAP_LABELオブジェクト作成 if( created == true ) { ObjectSetInteger(0,OBJ_TEST_NAME,OBJPROP_CORNER,CORNER_RIGHT_UPPER); // アンカー設定:チャート右上 ObjectSetInteger(0,OBJ_TEST_NAME,OBJPROP_XDISTANCE,100); // アンカーからのX軸距離:100pixel ObjectSetInteger(0,OBJ_TEST_NAME,OBJPROP_YDISTANCE,50); // アンカーからのY軸距離:50pixel ResetLastError(); // エラーコードクリア // bmp_onで指定した画像ファイルをOBJ_TEST_NAMEオブジェクトの"押下状態"に設定 button_set = ObjectSetString(0,OBJ_TEST_NAME,OBJPROP_BMPFILE,0,bmp_on); if( button_set == false ) { // 画像ファイル設定失敗 PrintFormat("%s の画像ファイルを設定出来ませんでした。 エラーコード: %d",bmp_on ,GetLastError()); } ResetLastError(); // エラーコードクリア // bmp_offで指定した画像ファイルをOBJ_TEST_NAMEオブジェクトの"非押下状態"に設定 button_set = ObjectSetString(0,OBJ_TEST_NAME,OBJPROP_BMPFILE,1,bmp_off); if( button_set == false ) { // 画像ファイル設定失敗 PrintFormat("%s の画像ファイルを設定出来ませんでした。 エラーコード: %d",bmp_on ,GetLastError()); } } }
#resource リソースファイル名(パスを含む)
#resource "<リソースファイルへのパス>"
// このソースファイル(.mq4)のパス:"ターミナルディレクトリ\MQL4\Experts" // リソースの正しい指定方法 #resource "\\Include\\Controls\\res\\CloseOn.bmp" // \MQL4\Include\\Controls\\res\\CloseOn.bmp #resource "CloseOn.bmp" // \MQL4\Experts\CloseOn.bmp #resource "resorce\\CloseOn.bmp" // \MQL4\Experts\resorce\CloseOn.bmp // リソースの間違えた指定方法 #resource ":CloseOn.bmp" // 先頭にコロン(:)がある #resource "..\\CloseOn.bmp" // 先頭にピリオド(.)がある
// このソースファイル(.mq4)のパス:"ターミナルディレクトリ\MQL4\Experts" #resource "CloseOn.bmp" // \MQL4\Experts\CloseOn.bmp #resource "\\resorce\\CloseDisable.bmp" // \MQL4\resorce\CloseDisable.bmp #define OBJ_TEST_NAME "ObjectTest" //+------------------------------------------------------------------+ //| 初期化 //+------------------------------------------------------------------+ void OnInit() { bool created; bool button_set; ObjectsDeleteAll(); // オブジェクト全削除 // OBJ_BITMAP_LABELオブジェクト作成 created = ObjectCreate(0,OBJ_TEST_NAME,OBJ_BITMAP_LABEL,0,0,0); if( created == true ) { ObjectSetInteger(0,OBJ_TEST_NAME,OBJPROP_CORNER,CORNER_RIGHT_UPPER); // アンカー設定:チャート右上 ObjectSetInteger(0,OBJ_TEST_NAME,OBJPROP_XDISTANCE,100); // アンカーからのX軸距離:100pixel ObjectSetInteger(0,OBJ_TEST_NAME,OBJPROP_YDISTANCE,50); // アンカーからのY軸距離:50pixel button_set = ObjectSetString(0,OBJ_TEST_NAME,OBJPROP_BMPFILE,0, "::CloseOn.bmp"); button_set = ObjectSetString(0,OBJ_TEST_NAME,OBJPROP_BMPFILE,1, "::resorce\\CloseDisable.bmp"); } }
// このソースファイル(test_script.mq4)のパス:"ターミナルディレクトリ\MQL4\Scripts" #resource "\\resorce\\CloseDisable.bmp" // \MQL4\resorce\CloseDisable.bmp #define OBJ_TEST_NAME "ObjectTest" //+------------------------------------------------------------------+ //| スクリプト起動 //+------------------------------------------------------------------+ void OnStart() { ObjectsDeleteAll(); // オブジェクト全削除 // OBJ_BITMAP_LABELオブジェクト作成 created = ObjectCreate(0,OBJ_TEST_NAME,OBJ_BITMAP_LABEL,0,0,0); ObjectSetString(0,OBJ_TEST_NAME,OBJPROP_BMPFILE,1, "::resorce\\CloseDisable.bmp"); }
// このソースファイル(.mq4)のパス:"ターミナルディレクトリ\MQL4\Experts" #define OBJ_TEST_NAME "ObjectTest" //+------------------------------------------------------------------+ //| 初期化 //+------------------------------------------------------------------+ void OnInit() { ObjectsDeleteAll(); // オブジェクト全削除 // OBJ_BITMAP_LABELオブジェクト作成 created = ObjectCreate(0,OBJ_TEST_NAME,OBJ_BITMAP_LABEL,0,0,0); // スクリプトファイルの実行可能ファイル(test_script.ex4)に含まれているリソースをEAで使用 ObjectSetString(0,OBJ_TEST_NAME,OBJPROP_BMPFILE, 1, "\\MQL4\Scripts\test_script.ex4::resorce\\CloseDisable.bmp"); }
// このソースファイル(.mq4)のパス:"ターミナルディレクトリ\MQL4\Experts" // スクリプトファイルの実行可能ファイル(test_script.ex4)に含まれているリソースをEAで使用 ObjectSetString(0,OBJ_TEST_NAME,OBJPROP_BMPFILE,1, "test_script.ex4::resorce\\CloseDisable.bmp"); // "ターミナルディレクトリ\MQL4\Experts"フォルダで"test_script.ex4"を検索します。
// このソースファイル(.mq4)のパス:"ターミナルディレクトリ\MQL4\Experts" #resource "\\Indicators\\SampleIndicator.ex4" // \MQL4\Indicators\\SampleIndicator.ex4 //+------------------------------------------------------------------+ //| 初期化 //+------------------------------------------------------------------+ void OnInit() { double value; カスタムインジケータ(SampleIndicator.ex4)の算出値を取得 value = iCustom(Symbol() , Period() , "::Indicators\\SampleIndicator.ex4",0,0); PrintFormat("Indicator: iCustom value=%f",value); }