//--- 説明 #property description "Script creates the button on the chart." //--- スクリプトの起動時に入力パラメータのウィンドウを表示する #property script_show_inputs //--- スクリプト入力パラメータ input string InpName="Button"; // ボタン名 input ENUM_BASE_CORNER InpCorner=CORNER_LEFT_UPPER; // アンカーに使用されるチャートのコーナー input string InpFont="Arial"; // フォント input int InpFontSize=14; // フォントサイズ input color InpColor=clrBlack; // テキストの色 input color InpBackColor=C'236,233,216'; // 背景色 input color InpBorderColor=clrNONE; // 境界線の色 input bool InpState=false; // 押される/放される input bool InpBack=false; // 背景オブジェクト input bool InpSelection=false; // 強調表示して移動 input bool InpHidden=true; // オブジェクトリストに隠す input long InpZOrder=0; // マウスクリックの優先順位 //+------------------------------------------------------------------+ //| ボタンを作成する | //+------------------------------------------------------------------+ bool ButtonCreate(const long chart_ID=0, // チャート識別子 const string name="Button", // ボタン名 const int sub_window=0, // サブウィンドウ番号 const int x=0, // X 座標 const int y=0, // Y 座標 const int width=50, // ボタンの幅 const int height=18, // ボタンの高さ const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // アンカーに使用されるチャートのコーナー const string text="Button", // テキスト const string font="Arial", // フォント const int font_size=10, // フォントサイズ const color clr=clrBlack, // テキストの色 const color back_clr=C'236,233,216', // 背景色 const color border_clr=clrNONE, // 境界線の色 const bool state=false, // 押される/放される const bool back=false, // 背景で表示する const bool selection=false, // 強調表示して移動 const bool hidden=true, // オブジェクトリストに隠す const long z_order=0) // マウスクリックの優先順位 { //--- エラー値をリセットする ResetLastError(); //--- ボタンを作成する if(!ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0)) { Print(__FUNCTION__, ": failed to create the button! Error code = ",GetLastError()); return(false); } //--- ボタン座標を設定する ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); //--- ボタンサイズを設定する ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width); ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height); //--- ポイント座標が相対的に定義されているチャートのコーナーを設定 ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); //--- テキストを設定する ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); //--- テキストフォントを設定する ObjectSetString(chart_ID,name,OBJPROP_FONT,font); //--- フォントサイズを設定する ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); //--- テキストの色を設定する ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); //--- 背景色を設定する ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr); //--- 境界線の色を設定する ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr); //--- 前景(false)または背景(true)に表示 ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); //--- ボタンの状態を設定する ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state); //--- マウスでのボタンを移動させるモードを有効(true)か無効(false)にする ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); //--- オブジェクトリストのグラフィックオブジェクトを非表示(true)か表示(false)にする ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); //--- チャートのマウスクリックのイベントを受信するための優先順位を設定する ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); //--- 実行成功 return(true); } //+------------------------------------------------------------------+ //| ボタンを移動する | //+------------------------------------------------------------------+ bool ButtonMove(const long chart_ID=0, // チャート識別子 const string name="Button", // ボタン名 const int x=0, // X 座標 const int y=0) // Y 座標 { //--- エラー値をリセットする ResetLastError(); //--- ボタンを移動する if(!ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x)) { Print(__FUNCTION__, ": failed to move X coordinate of the button! Error code = ",GetLastError()); return(false); } if(!ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y)) { Print(__FUNCTION__, ": failed to move Y coordinate of the button! Error code = ",GetLastError()); return(false); } //--- 実行成功 return(true); } //+------------------------------------------------------------------+ //| ボタンサイズを変更する | //+------------------------------------------------------------------+ bool ButtonChangeSize(const long chart_ID=0, // チャート識別子 const string name="Button", // ボタン名 const int width=50, // ボタンの幅 const int height=18) // ボタンの高さ { //--- エラー値をリセットする ResetLastError(); //--- ボタンサイズを変更する if(!ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width)) { Print(__FUNCTION__, ": failed to change the button width! Error code = ",GetLastError()); return(false); } if(!ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height)) { Print(__FUNCTION__, ": failed to change the button height! Error code = ",GetLastError()); return(false); } //--- 実行成功 return(true); } //+------------------------------------------------------------------+ //| ボタン結合に使用されるチャートのコーナーを変更する | //+------------------------------------------------------------------+ bool ButtonChangeCorner(const long chart_ID=0, // チャート識別子 const string name="Button", // ボタン名 const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER) // アンカーに使用されるチャートのコーナー { //--- エラー値をリセットする ResetLastError(); //--- アンカーに使用される隅を変更する if(!ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner)) { Print(__FUNCTION__, ": failed to change the anchor corner! Error code = ",GetLastError()); return(false); } //--- 実行成功 return(true); } //+------------------------------------------------------------------+ //| ボタンテキストを変更する | //+------------------------------------------------------------------+ bool ButtonTextChange(const long chart_ID=0, // チャート識別子 const string name="Button", // ボタン名 const string text="Text") // テキスト { //--- エラー値をリセットする ResetLastError(); //--- オブジェクトのテキストを変更する if(!ObjectSetString(chart_ID,name,OBJPROP_TEXT,text)) { Print(__FUNCTION__, ": failed to change the text! Error code = ",GetLastError()); return(false); } //--- 実行成功 return(true); } //+------------------------------------------------------------------+ //| ボタンを削除する | //+------------------------------------------------------------------+ bool ButtonDelete(const long chart_ID=0, // チャート識別子 const string name="Button") // ボタン名 { //--- エラー値をリセットする ResetLastError(); //--- ボタンを削除する if(!ObjectDelete(chart_ID,name)) { Print(__FUNCTION__, ": failed to delete the button! Error code = ",GetLastError()); return(false); } //--- 実行成功 return(true); } //+------------------------------------------------------------------+ //| スクリプトプログラムを開始する関数 | //+------------------------------------------------------------------+ void OnStart() { //--- チャートウィンドウサイズ long x_distance; long y_distance; //--- ウィンドウサイズを設定する if(!ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0,x_distance)) { Print("Failed to get the chart width! Error code = ",GetLastError()); return; } if(!ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0,y_distance)) { Print("Failed to get the chart height! Error code = ",GetLastError()); return; } //--- ボタンサイズ変更のステップを定義する int x_step=(int)x_distance/32; int y_step=(int)y_distance/32; //--- ボタン座標とサイズを設定する int x=(int)x_distance/32; int y=(int)y_distance/32; int x_size=(int)x_distance*15/16; int y_size=(int)y_distance*15/16; //--- ボタンを作成する if(!ButtonCreate(0,InpName,0,x,y,x_size,y_size,InpCorner,"Press",InpFont,InpFontSize, InpColor,InpBackColor,InpBorderColor,InpState,InpBack,InpSelection,InpHidden,InpZOrder)) { return; } //--- チャートを再描画する ChartRedraw(); //--- ループ内でボタンを減らす int i=0; while(i<13) { //--- 半秒の遅れ Sleep(500); //--- ボタンを押された状態に切り替える ObjectSetInteger(0,InpName,OBJPROP_STATE,true); //--- チャートを再描画して 0.2 秒待つ ChartRedraw(); Sleep(200); //--- 座標とボタンサイズを再定義する x+=x_step; y+=y_step; x_size-=x_step*2; y_size-=y_step*2; //--- ボタンを減らす ButtonMove(0,InpName,x,y); ButtonChangeSize(0,InpName,x_size,y_size); //--- ボタンを押されていない状態に返す ObjectSetInteger(0,InpName,OBJPROP_STATE,false); //--- チャートを再描画する ChartRedraw(); //--- スクリプトの動作が強制的に無効にされているかどうかをチェックする if(IsStopped()) return; //--- ループカウンタを増加する i++; } //--- 半秒の遅れ Sleep(500); //--- ボタンを削除する ButtonDelete(0,InpName); ChartRedraw(); //---1 秒待つ Sleep(1000); //--- } |