//+------------------------------------------------------------------+ //| tick_chart2.mq4 | //| Rondo | //| http://fx-dollaryen.seesaa.net | //+------------------------------------------------------------------+ #property copyright "Rondo" #property link "http://fx-dollaryen.seesaa.net/" #property version "2.0" #property strict #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 clrYellow input int ticks = 70; //tick数 input color UpColor = clrGreen; //陽線の色 input color DownColor = clrRed; //陰線の色 input bool boolMA = false; //移動平均線表示 input int MAPeriod = 20; //期間 input ENUM_MA_METHOD MAMetod = MODE_EMA; //計算式 input bool scale = true; //スケール自動調整 input int numbers = 300; //表示するバーの数 input bool LineType = false; //ラインタイプ input ENUM_LINE_STYLE LineStyle = STYLE_SOLID; //スタイル input bool counter = true; //カウンター表示 input ENUM_BASE_CORNER counterConer = CORNER_RIGHT_LOWER; //表示位置 input int Xposition = 150; //X軸 input int Yposition = 20; //Y軸 input color counterColor = clrWhite; //色 input int counterFontSize = 8; //大きさ string indiName = "tick_chart"; int limit; double tOpen, tHigh, tLow, tClose; double tHighest, tLowest; datetime startTime, lastTime; double TickPrice[]; double MA[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit(){ if(Bars <= numbers*3) limit = Bars/3-3; else limit = numbers-1; ArrayResize(TickPrice, Bars); ArraySetAsSeries(TickPrice, true); IndicatorBuffers(1); SetIndexStyle(0, DRAW_LINE); SetIndexBuffer(0, MA); ArraySetAsSeries(MA, true); SetIndexLabel(0, "tick chart MA"); startTime = TimeCurrent(); if(ChartGetInteger(0, CHART_MODE, 0) != CHART_LINE) ChartSetInteger(0, CHART_MODE, CHART_LINE); if(scale) ChartSetInteger(0, CHART_COLOR_CHART_LINE, clrNONE); else ChartSetInteger(0, CHART_COLOR_CHART_LINE, clrLime); int position = 0; tHighest = High[1]; tLowest = Low[1]; for(int i=0; i tLow) tLowest = tLow; double bufOpen=tOpen, bufHigh, bufLow, bufClose; for(int k= 0; k<=vol/ticks; k++){ if(k == 0){ //bufOpen = tOpen; bufHigh = tHigh; bufLow = tLow; bufClose = tClose; } else if(00; i--){ if(ObjectFind(0, indiName+"_body"+IntegerToString(i-1)) != 0) continue; ObjectSetInteger(0, indiName+"_body"+IntegerToString(i-1), OBJPROP_TIME, 0, time[i*3+2]); ObjectSetInteger(0, indiName+"_body"+IntegerToString(i-1), OBJPROP_TIME, 1, time[i*3]); ObjectSetInteger(0, indiName+"_shadow"+IntegerToString(i-1), OBJPROP_TIME, 0, time[i*3+1]); ObjectSetInteger(0, indiName+"_shadow"+IntegerToString(i-1), OBJPROP_TIME, 1, time[i*3+1]); ObjectSetInteger(0, indiName+"_tail"+IntegerToString(i-1), OBJPROP_TIME, 0, time[i*3+1]); ObjectSetInteger(0, indiName+"_tail"+IntegerToString(i-1), OBJPROP_TIME, 1, time[i*3+1]); ObjectSetString(0, indiName+"_body"+IntegerToString(i-1), OBJPROP_NAME, indiName+"_body"+IntegerToString(i)); ObjectSetString(0, indiName+"_shadow"+IntegerToString(i-1), OBJPROP_NAME, indiName+"_shadow"+IntegerToString(i)); ObjectSetString(0, indiName+"_tail"+IntegerToString(i-1), OBJPROP_NAME, indiName+"_tail"+IntegerToString(i)); if(boolMA) TickPrice[i] = ObjectGetDouble(0, indiName+"_body"+IntegerToString(i), OBJPROP_PRICE, 1); } ChartRedraw(0); tOpen = close[0]; tHigh = close[0]; tLow = close[0]; lastTime = startTime; startTime = TimeCurrent(); counts = 0; } else{ if(tHigh < close[0]) tHigh = close[0]; if(tLow > close[0]) tLow = close[0]; } //if(ObjectFind(0, indiName+"_body"+IntegerToString(0))==0) ObjectDelete(0, indiName+"_body"+IntegerToString(0)); if(tOpen == close[0]){ if(ObjectGetInteger(0, indiName+"_body"+IntegerToString(0), OBJPROP_TYPE) == OBJ_RECTANGLE) ObjectDelete(0, indiName+"_body"+IntegerToString(0)); TrendLine(indiName+"_body"+IntegerToString(0), 2, tOpen, 0, close[0], UpColor, 1); TrendLine(indiName+"_shadow"+IntegerToString(0), 1, close[0], 1, tHigh, UpColor, 1); TrendLine(indiName+"_tail"+IntegerToString(0), 1, tOpen, 1, tLow, UpColor, 1); } else if(tOpen < close[0]){ if(ObjectGetInteger(0, indiName+"_body"+IntegerToString(0), OBJPROP_TYPE) == OBJ_TREND) ObjectDelete(0, indiName+"_body"+IntegerToString(0)); Rectangle(indiName+"_body"+IntegerToString(0), 2, tOpen, 0, close[0], UpColor, LineStyle, 1); TrendLine(indiName+"_shadow"+IntegerToString(0), 1, close[0], 1, tHigh, UpColor, 1); TrendLine(indiName+"_tail"+IntegerToString(0), 1, tOpen, 1, tLow, UpColor, 1); } else{ if(ObjectGetInteger(0, indiName+"_body"+IntegerToString(0), OBJPROP_TYPE) == OBJ_TREND) ObjectDelete(0, indiName+"_body"+IntegerToString(0)); Rectangle(indiName+"_body"+IntegerToString(0), 2, tOpen, 0, close[0], DownColor, LineStyle, 1); TrendLine(indiName+"_shadow"+IntegerToString(0), 1, tOpen, 1, tHigh, DownColor, 1); TrendLine(indiName+"_tail"+IntegerToString(0), 1, close[0], 1, tLow, DownColor, 1); } if(tHighest < close[0]) tHighest = close[0]; if(tLowest > close[0]) tLowest = close[0]; if(boolMA){ TickPrice[0] = close[0]; for(int i=0; i=1) ma1 = iMAOnArray(TickPrice, 0, MAPeriod, 0, MAMetod, i-1); double ma2 = iMAOnArray(TickPrice, 0, MAPeriod, 0, MAMetod, i); double ma3 = iMAOnArray(TickPrice, 0, MAPeriod, 0, MAMetod, i+1); if(i == 0) MA[0] = EMPTY_VALUE; else MA[i*3] = (ma2*2 + ma1)/3; MA[i*3+1] = ma2; MA[i*3+2] = (ma2*2 + ma3)/3; } } if(counter) Label(indiName+"_counter", IntegerToString(counts)+"/"+IntegerToString(ticks)+" ["+IntegerToString(startTime-lastTime)+"秒/本]", counterConer, counterFontSize, counterColor); counts++; //--- 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(id, 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_SELECTABLE, false); ObjectSetInteger(id, name, OBJPROP_HIDDEN, true); } else{ ObjectSetInteger(id, name, OBJPROP_COLOR, Rcolor); ObjectMove(name, 0, Time[index1], price1); ObjectMove(name, 1, Time[index2], price2); } ChartRedraw(id); } void TrendLine(string name, int index1, double price1, int index2, double price2, color Tcolor, int Twidth){ long id = ChartID(); if (ObjectFind(id, name) != 0) { ObjectCreate(id, name, OBJ_TREND, 0, Time[index1], price1, Time[index2], 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{ ObjectSetInteger(id, name, OBJPROP_COLOR, Tcolor); ObjectMove(name, 0, Time[index1], price1); ObjectMove(name, 1, Time[index2], price2); } ChartRedraw(id); } void Label(string name, string text, int labelCorner, int labelSize, color labelColor){ long id = ChartID(); if(ObjectFind(id, name) != 0){ ObjectCreate(id, 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); ObjectSetInteger(id, name, OBJPROP_SELECTABLE, false); ObjectSetInteger(id, name, OBJPROP_HIDDEN, true); } 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); } } double GetRandom(double min, double max){ return NormalizeDouble(min+MathRand()%100/100.0*(max-min), Digits()); }