CAppDialog にそれぞれの時間を表示させてみます
Time
MQL4で扱う時刻はトレード用の特殊な時間です
TimeCurrent:サーバー時間、いわゆるMT4時間でNY17:00を日足終わりとしての時間
TimeLocal:コンピュータのローカル時間
TimeGMT:GMT時間、コンピュータのローカル時間のDST(夏時間) スイッチを考慮
NewYorkは夏時間があるので、1時間のずれが生じます
MT4の時間がGMTそのものでなく+2時間や+3時間(夏時間)というのはどう言うことでしょうか?
結論としては、NewYo...
TimeCurrent
TimeCurrent()を使ってMT4時間をCAppDialogのClabelに表示させてみましょう
1 2 3 4 5 6 7 8 9 10 11 12 13 |
... void UpdateTime(){ labelTime.Text("TimeCurrent: " + TimeToString(TimeCurrent(), TIME_SECONDS)); } ... // 1秒ごとに更新 EventSetTimer(1); ... // タイマーイベントで時間更新 void OnTimer(){ TestPanel.UpdateTime(); } ... |
まとめてみると、
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
#include <Controls\Dialog.mqh> #include <Controls\Label.mqh> class CTestPanel : public CAppDialog{ private: CLabel labelTime; public: CTestPanel(void){}; ~CTestPanel(void){}; virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2); void UpdateTime(){ labelTime.Text("TimeCurrent: " + TimeToString(TimeCurrent(), TIME_SECONDS)); } protected: bool CreateLabel(void); }; bool CTestPanel::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2){ if(!CAppDialog::Create(chart, name, subwin, x1, y1, x2, y2)){ return(false); } if(!CreateLabel()) return(false); return(true); } bool CTestPanel::CreateLabel(void){ if(!labelTime.Create(m_chart_id, "Label", m_subwin, 25, 26, 145, 46)) return(false); labelTime.Text("TimeCurrent: " + TimeToString(TimeCurrent(), TIME_SECONDS)); labelTime.Color(clrBlue); if(!Add(labelTime)) return(false); return(true); } CTestPanel TestPanel; int OnInit(){ // Creat TestPanel if(!TestPanel.Create( ChartID(), "TestPanel", 0, 160, 40, 400, 210 )){ return(INIT_FAILED); } EventSetTimer(1); // Run TestPanel TestPanel.Run(); return(INIT_SUCCEEDED); } void OnDeinit(const int reason){ EventKillTimer(); TestPanel.Destroy(reason); } void OnTimer(){ TestPanel.UpdateTime(); } // Get the object event void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam){ TestPanel.ChartEvent(id, lparam, dparam, sparam); } |
時間が表示されました
TimeLocal
上のTimeCurrentをTimeLocalに置き換えると
現在の時間が表示されます
TimeGMT
上のTimeCurrentをTimeGMTに置き換えると
GMT時間が表示されます
3つまとめてみると
日付
日付も表示させたいときは、日付のラベルを以下のような設定で追加するとできます
1 |
abeldate.Text("Date: " + TimeToString(TimeCurrent(), TIME_DATE)); |