//+------------------------------------------------------------------+ //| MTF_CandleStick3.mq4 | //| Rondo | //| http://fx-dollaryen.seesaa.net | //+------------------------------------------------------------------+ #property copyright "Rondo" #property link "http://fx-dollaryen.seesaa.net/" #property version "1.3" #property description "" #property strict #property indicator_chart_window enum enumTimeFrames{ m1 = PERIOD_M1, //1分足 m2 = PERIOD_M2, //2分足 m3 = PERIOD_M3, //3分足 m4 = PERIOD_M4, //4分足 m5 = PERIOD_M5, //5分足 m6 = PERIOD_M6, //6分足 m10 = PERIOD_M10, //10分足 m12 = PERIOD_M12, //12分足 m15 = PERIOD_M15, //15分足 m20 = PERIOD_M20, //20分足 m30 = PERIOD_M30, //30分足 h1 = PERIOD_H1, //1時間足 h2 = PERIOD_H2, //2時間足 h3 = PERIOD_H3, //3時間足 h4 = PERIOD_H4, //4時間足 h6 = PERIOD_H6, //6時間足 h8 = PERIOD_H8, //8時間足 h12 = PERIOD_H12, //12時間足 d1 = PERIOD_D1, //日足 w1 = PERIOD_W1, //週足 mn1 = PERIOD_MN1 //月足 }; //input ENUM_TIMEFRAMES MTF_Period = PERIOD_H1; //時間 input enumTimeFrames MTF_Period = PERIOD_H1; //時間 input color UpColor = clrBlue; //陽線の色 input color DownColor = clrOrange; //陰線の色 input bool LineType = false; //ラインタイプ input ENUM_LINE_STYLE LineStyle = STYLE_DOT; //スタイル input int LineWidth = 1; //ラインの太さ input bool timer = true; //残り時間表示 input ENUM_BASE_CORNER timerConer = CORNER_LEFT_UPPER; //表示位置 input int Xposition = 20; //X軸 input int Yposition = 20; //Y軸 input color timerColor = clrWhite; //色 input int timerFontSize = 8; //大きさ string indiName = "MTF_CandleStick"; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit(){ //--- indicator buffers mapping //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason){ objDelete(indiName+IntegerToString(MTF_Period)); } //+------------------------------------------------------------------+ //| 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[]) { //--- if(MTF_Period <= _Period) return(0); int limit = rates_total - prev_calculated; int counts = 0; if(limit > 0){ objDelete(indiName+IntegerToString(MTF_Period)); limit = rates_total-1; } else{ if(MTF_Period < 1440) limit = MTF_Period/_Period; else limit = 1; } for(int i=0; i=0; t--){ if(time[i]+MTF_Period*60 <= time[t]){ last = t+1; break; } } mtfOpen = open[first]; mtfClose = close[last]; mtfHigh = high[iHighest(NULL, 0, MODE_HIGH, first-last+1, last)]; mtfLow = low[iLowest(NULL, 0, MODE_LOW, first-last+1, last)]; } else{ if(time[Bars-1] > iTime(NULL, MTF_Period, i)) break; mtfOpen = iOpen(NULL, MTF_Period, i); mtfClose = iClose(NULL, MTF_Period, i); mtfHigh = iHigh(NULL, MTF_Period, i); mtfLow = iLow(NULL, MTF_Period, i); first = iBarShift(NULL, 0, iTime(NULL, MTF_Period, i), false); if(TimeHour(time[first]) != 0) first--; if(i > 0){ last = iBarShift(NULL, 0, iTime(NULL, MTF_Period, i-1), false); if(TimeHour(time[last]) == 0) last++; } /* if(MTF_Period == 1440){ first = iBarShift(NULL, 0, iTime(NULL, MTF_Period, i), false); if(i > 0) last = iBarShift(NULL, 0, iTime(NULL, MTF_Period, i-1), false)+1; } else{ first = iBarShift(NULL, 0, iTime(NULL, MTF_Period, i), false)-1; if(i > 0) last = iBarShift(NULL, 0, iTime(NULL, MTF_Period, i-1), false); } */ } if(timer && MTF_Period<1440 && counts==0){ int min, sec, hour; sec = (int)(time[i] + MTF_Period*60 - TimeCurrent()); hour = sec/(60*60); min = sec/60%60; sec %= 60; string timerName = indiName+IntegerToString(MTF_Period)+"_timer"; if(MTF_Period <= 60) Label(timerName, IntegerToString(min)+"分"+IntegerToString(sec)+"秒", timerConer, timerFontSize, timerColor); else Label(timerName, IntegerToString(hour)+"時間"+IntegerToString(min)+"分"+IntegerToString(sec)+"秒", timerConer, timerFontSize, timerColor); counts++; } if(mtfOpen <= mtfClose){ Rectangle(indiName+IntegerToString(MTF_Period)+"_body"+IntegerToString(i), first, mtfOpen, last, mtfClose, UpColor, LineStyle, LineWidth); TrendLine(indiName+IntegerToString(MTF_Period)+"_shadow"+IntegerToString(i), (first+last)/2, mtfClose, mtfHigh, UpColor, LineWidth); TrendLine(indiName+IntegerToString(MTF_Period)+"_tail"+IntegerToString(i), (first+last)/2, mtfOpen, mtfLow, UpColor, LineWidth); } else{ Rectangle(indiName+IntegerToString(MTF_Period)+"_body"+IntegerToString(i), first, mtfOpen, last, mtfClose, DownColor, LineStyle, LineWidth); TrendLine(indiName+IntegerToString(MTF_Period)+"_shadow"+IntegerToString(i), (first+last)/2, mtfOpen, mtfHigh, DownColor, LineWidth); TrendLine(indiName+IntegerToString(MTF_Period)+"_tail"+IntegerToString(i), (first+last)/2, mtfClose, mtfLow, DownColor, LineWidth); } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ void Rectangle(string name, int index1, double price1, int index2, double price2, color Rcolor, int Rstyle, int Rwidth){ long id = ChartID(); if (ObjectFind(name) != 0) { ObjectCreate(id, name, OBJ_RECTANGLE, 0, Time[index1], price1, Time[index2], price2); ObjectSetInteger(id, name, OBJPROP_COLOR, Rcolor); if(LineType) ObjectSetInteger(id, name, OBJPROP_STYLE, Rstyle); ObjectSetInteger(id, name, OBJPROP_WIDTH, Rwidth); ObjectSetInteger(id, name, OBJPROP_BACK, !LineType); //ObjectSetInteger(id, name, OBJPROP_RAY_RIGHT, false); ObjectSetInteger(id, name, OBJPROP_SELECTABLE, false); ObjectSetInteger(id, name, OBJPROP_HIDDEN, true); } else{ ObjectMove(name, 0, Time[index1], price1); ObjectMove(name, 1, Time[index2], price2); } ChartRedraw(id); } void TrendLine(string name, int position, double price1, double price2, color Tcolor, int Twidth){ long id = ChartID(); if (ObjectFind(name) != 0) { ObjectCreate(id, name, OBJ_TREND, 0, Time[position], price1, Time[position], price2); ObjectSetInteger(id, name, OBJPROP_COLOR, Tcolor); ObjectSetInteger(id, name, OBJPROP_STYLE, STYLE_SOLID); ObjectSetInteger(id, name, OBJPROP_WIDTH, Twidth); ObjectSetInteger(id, name, OBJPROP_BACK, true); ObjectSetInteger(id, name, OBJPROP_RAY_RIGHT, false); ObjectSetInteger(id, name, OBJPROP_SELECTABLE, false); ObjectSetInteger(id, name, OBJPROP_HIDDEN, true); } else{ ObjectMove(name, 0, Time[position], price1); ObjectMove(name, 1, Time[position], price2); } ChartRedraw(id); } 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 objDelete(string basicName){ for(int i=ObjectsTotal();i>=0;i--){ string ObjName = ObjectName(i); if(StringFind(ObjName, basicName) >=0) ObjectDelete(ObjName); } }