質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
MQL4

MQL4とは、MT4(MetaTrader4)で用いられるプログラム言語です。MT4は無料で使えるチャートソフトあり、MQL4を使うことで分析ツールのオリジナルスクリプトの作成ができます。

Q&A

解決済

1回答

2411閲覧

MT4インディケータで、ダイアログシートを開いて数値を入力したい。

yu-ima

総合スコア249

MQL4

MQL4とは、MT4(MetaTrader4)で用いられるプログラム言語です。MT4は無料で使えるチャートソフトあり、MQL4を使うことで分析ツールのオリジナルスクリプトの作成ができます。

0グッド

0クリップ

投稿2021/09/04 15:05

前提・実現したいこと

メタエディターで、MT4インディケータ作成し その動作としてダイアログシートを開いて数値を入力し、インディケータの中で参照する方法をお教えください。
(EAで利用している例は見たのですが、インディケータでは確認していません。)

インディケータのチャートへの導入時にパラメータとして数値を指定できることは知っているのですが、
動作中に数値入力する方法が分かりません。

発生している問題・エラーメッセージ

なし

該当のソースコード

MQL4

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

MT4のダイアログボックスは、ObjectCreate関数とマウスイベントを駆使してダイアログのように見えるものを描画しているだけです。
それだと作るのが大変なので、標準ライブラリにダイアログ用のクラスがあります。
MT4をインストールしたディレクトリのMQL4\Include\Controlsにソースがあります。

MT4ではなくMT5のリファレンスを見るのが早いと思います。

インジケータの動作中に移動平均の期間を変更するサンプル

cpp

1#property strict 2#property indicator_chart_window 3 4#property indicator_buffers 3 5#property indicator_plots 3 6 7#property indicator_color1 clrDodgerBlue 8#property indicator_color2 clrGreen 9#property indicator_color3 clrCrimson 10 11#property indicator_width1 1 12#property indicator_width2 2 13#property indicator_width3 3 14 15#include <Controls\Dialog.mqh> 16#include <Controls\Button.mqh> 17#include <Controls\Edit.mqh> 18#include <MovingAverages.mqh> 19 20input int InpPeriod1 = 62; 21input int InpPeriod2 = 200; 22input int InpPeriod3 = 800; 23 24double ExtMa1[]; 25double ExtMa2[]; 26double ExtMa3[]; 27 28int Period1; 29int Period2; 30int Period3; 31 32class CTestDialog : public CAppDialog 33{ 34 CEdit m_edit1; 35 CEdit m_edit2; 36 CEdit m_edit3; 37 CButton m_button; 38 39public: 40 virtual bool Create(const long chart, const string name, const int subwin, const int x1, const int y1,const int x2,const int y2); 41 virtual bool OnEvent(const int id, const long &lparam, const double &dparam,const string &sparam); 42 void OnClickButton(void); 43}; 44 45EVENT_MAP_BEGIN(CTestDialog) 46ON_EVENT(ON_CLICK, m_button, OnClickButton) 47EVENT_MAP_END(CAppDialog) 48 49bool CTestDialog::Create(const long chart, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2) 50{ 51 CAppDialog::Create(chart, name, subwin, x1, y1, x2, y2); 52 53 int x = 5; 54 int y = 5; 55 int w = 60; 56 int h = 20; 57 int margin = 5; 58 59 m_edit1.Create(m_chart_id, m_name + "Edit1", m_subwin, x, y, x + w, y + h); 60 m_edit1.Text(IntegerToString(Period1)); 61 Add(m_edit1); 62 63 y += h + margin; 64 65 m_edit2.Create(m_chart_id, m_name + "Edit2", m_subwin, x, y, x + w, y + h); 66 m_edit2.Text(IntegerToString(Period2)); 67 Add(m_edit2); 68 69 y += h + margin; 70 71 m_edit3.Create(m_chart_id, m_name + "Edit3", m_subwin, x, y, x + w, y + h); 72 m_edit3.Text(IntegerToString(Period3)); 73 Add(m_edit3); 74 75 y += h + margin; 76 77 m_button.Create(m_chart_id, m_name + "Button", m_subwin, x, y, x + w, y + h); 78 m_button.Text("Update"); 79 Add(m_button); 80 81 return true; 82} 83 84void CTestDialog::OnClickButton(void) 85{ 86 int period1 = StrToInteger(m_edit1.Text()); 87 int period2 = StrToInteger(m_edit2.Text()); 88 int period3 = StrToInteger(m_edit3.Text()); 89 90 if (period1 <= 0 || period2 <= 0 || period3 <= 3) 91 { 92 return; 93 } 94 95 Period1 = period1; 96 Period2 = period2; 97 Period3 = period3; 98 99 PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, Period1 - 1); 100 PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, Period2 - 1); 101 PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, Period3 - 1); 102 103 ChartSetSymbolPeriod(0, NULL, PERIOD_CURRENT); 104} 105 106CTestDialog ExtDialog; 107 108int OnInit() 109{ 110 Period1 = InpPeriod1; 111 Period2 = InpPeriod2; 112 Period3 = InpPeriod3; 113 114 SetIndexBuffer(0, ExtMa1); 115 SetIndexBuffer(1, ExtMa2); 116 SetIndexBuffer(2, ExtMa3); 117 118 PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, Period1 - 1); 119 PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, Period2 - 1); 120 PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, Period3 - 1); 121 122 if(!ExtDialog.Create(0, "MA3", 0, 20, 20, 100, 160)) 123 { 124 return INIT_FAILED; 125 } 126 127 ExtDialog.Run(); 128 129 return INIT_SUCCEEDED; 130} 131 132void OnDeinit(const int reason) 133{ 134 ExtDialog.Destroy(reason); 135} 136 137int OnCalculate(const int rates_total, 138 const int prev_calculated, 139 const datetime &time[], 140 const double &open[], 141 const double &high[], 142 const double &low[], 143 const double &close[], 144 const long &tick_volume[], 145 const long &volume[], 146 const int &spread[]) 147{ 148 ArraySetAsSeries(ExtMa1, false); 149 ArraySetAsSeries(ExtMa2, false); 150 ArraySetAsSeries(ExtMa3, false); 151 ArraySetAsSeries(close, false); 152 153 int minPeriod = MathMin(Period1, MathMin(Period2, Period3)); 154 int first = MathMax(minPeriod - 1, prev_calculated - 1); 155 156 for (int i = first; i < rates_total; i++) 157 { 158 if (i == (Period1 - 1)) 159 ExtMa1[i] = SimpleMA(i, Period1, close); 160 else if (i >= (Period1 - 1)) 161 ExtMa1[i] = ExponentialMA(i, Period1, ExtMa1[i - 1], close); 162 163 if (i >= (Period2 - 1)) 164 ExtMa2[i] = SimpleMA(i, Period2, close); 165 166 if (i >= (Period3 - 1)) 167 ExtMa3[i] = SimpleMA(i, Period3, close); 168 } 169 170 return rates_total; 171} 172 173void OnChartEvent(const int id, 174 const long &lparam, 175 const double &dparam, 176 const string &sparam) 177{ 178 ExtDialog.ChartEvent(id,lparam,dparam,sparam); 179} 180

投稿2021/09/05 00:45

編集2024/04/30 11:54
mah

総合スコア591

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yu-ima

2021/09/05 08:25

mah様 ビンゴです。 有難うございました。 組み込みたい機能そのものです。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問