daisuke_gewinn:
MT4のインジケータにて,CButtonクラスを利用します。
その際、定型チャートから、インジケータが呼び出された場合、Pressedメソッドが正しく動作しません。
ボタンをクリックしてもPressedメソッドからの応答が0に固定されてしまいます。
検証コード
チャートにインジケータを挿入して、Testボタンを押した際のエキスパートログ
定型チャートからインジケータを呼び出した場合に、エキスパートログ
//+------------------------------------------------------------------+ //| ButtonTest.mq4 | //| Copyright 2015, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_chart_window #include <Controls/Button.mqh> // テストボタン CButton btnTest; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { ObjectDelete(0, "CTL_BTN_TEST"); btnTest.FontSize(8); btnTest.Text("Test"); btnTest.Create(ChartID(), "CTL_BTN_TEST", 0, 10, 20, 50, 50); if( ChartGetInteger(0, CHART_SHIFT) == false ) { ChartSetInteger(0, CHART_SHIFT, true); ChartSetDouble(0, CHART_SHIFT_SIZE, 12); } return(INIT_SUCCEEDED); } //------------------------------------------------------------------ //終了処理 void OnDeinit( const int reason ) { btnTest.Destroy(); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if(id == CHARTEVENT_OBJECT_CLICK) { if(sparam == btnTest.Name()) { bool pressed = btnTest.Pressed(); PrintFormat("btnTest pressed:%d", pressed); } } } //+------------------------------------------------------------------+
自己解決しました。
初期化処理の中で、インジケータとして作成される可能性のある、オブジェクトをあらかじめ削除する必要があるようです。
ObjectDelete(0, "CTL_BTN_TEST");
今回は、初期化処理の中に上記一文を追加したら、正しく動作するようになりました。
多分、オブジェクトも再現してしまうため、一度綺麗に削除しないといけないということですね。
取引の機会を逃しています。
- 無料取引アプリ
- 8千を超えるシグナルをコピー
- 金融ニュースで金融マーケットを探索
MT4のインジケータにて,CButtonクラスを利用します。
その際、定型チャートから、インジケータが呼び出された場合、Pressedメソッドが正しく動作しません。
ボタンをクリックしてもPressedメソッドからの応答が0に固定されてしまいます。
検証コード
チャートにインジケータを挿入して、Testボタンを押した際のエキスパートログ
定型チャートからインジケータを呼び出した場合に、エキスパートログ