//+------------------------------------------------------------------+ //| Cursor_Time2.mq4 | //| Copyright 2015, Rondo | //| http://fx-dollaryen.seesaa.net/ | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, Rondo" #property link "http://fx-dollaryen.seesaa.net/" #property version "2.0" #property description "【注意】夏時間/冬時間には対応しておりません。" #property strict #property indicator_chart_window input ENUM_BASE_CORNER Corner = CORNER_RIGHT_UPPER; //表示位置 input int Xposition = 150; //X軸 input int Yposition = 20; //Y軸 input int FontSize = 8; //文字の大きさ input color FontColor = clrWhite; //色 string labelName = "Cursor_Time2_Label"; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { objLabelDelete(labelName); return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { return(0); } //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, 0, true); if(id == CHARTEVENT_MOUSE_MOVE){ objLabelDelete(labelName); int xCursor = (int)lparam; int yCursor = (int)dparam; int sub_win = 0; datetime dt = 0; double price = 0; ChartXYToTimePrice(0, xCursor, yCursor+1, sub_win, dt, price); datetime timeCursor; if(dt <= 0) timeCursor = 0; else timeCursor = dt - (TimeHour(TimeCurrent())-TimeHour(TimeLocal()))*60*60; string date, day, time; date = TimeToStr(timeCursor, TIME_DATE); switch(TimeDayOfWeek(timeCursor)){ case SUNDAY: day = "日"; break; case MONDAY: day = "月"; break; case TUESDAY: day = "火"; break; case WEDNESDAY: day = "水"; break; case THURSDAY: day = "木"; break; case FRIDAY: day = "金"; break; case SATURDAY: day = "土"; break; } time = TimeToStr(timeCursor, TIME_MINUTES); if(xCursor>=0 && yCursor>=0 && timeCursor!=0.0){ Label(labelName, date+" ("+day+") "+time, Corner, FontSize, FontColor); } else objLabelDelete(labelName); } } //+------------------------------------------------------------------+ void Label(string name, string text, int labelCorner, int labelSize, color labelColor){ long id = ChartID(); if(ObjectFind(name) != 0){ ObjectCreate(name, OBJ_LABEL, 0, 0, 0); ObjectSetInteger(id, name, OBJPROP_CORNER, labelCorner); ObjectSetString(id, name, OBJPROP_FONT, "Meiryo"); ObjectSetInteger(id, name, OBJPROP_FONTSIZE, labelSize); ObjectSetInteger(id, name, OBJPROP_COLOR, labelColor); ObjectSetInteger(id, name, OBJPROP_XDISTANCE, Xposition); ObjectSetInteger(id, name, OBJPROP_YDISTANCE, Yposition); } ObjectSetString(id, name, OBJPROP_TEXT, text); ChartRedraw(0); } void objLabelDelete(string name){ if(ObjectFind(name)==0){ LabelDelete(0, name); ChartRedraw(); } return; } //+------------------------------------------------------------------+ //| Delete a text label | //+------------------------------------------------------------------+ bool LabelDelete(const long chart_ID=0, // chart's ID const string name="Label") // label name { //--- reset the error value ResetLastError(); //--- delete the label if(!ObjectDelete(chart_ID,name)) { Print(__FUNCTION__, ": failed to delete a text label! Error code = ",GetLastError()); return(false); } //--- successful execution return(true); }