//+------------------------------------------------------------------+ //| DailyData.mq5 | //+------------------------------------------------------------------+ #property copyright "www.forex-station.com" #property link "www.forex-station.com" #property indicator_chart_window #property indicator_buffers 5 #property indicator_plots 1 #property indicator_color1 clrGreen #property indicator_color2 clrCrimson #property indicator_color3 clrOrangeRed #property indicator_color4 clrMediumSeaGreen #property indicator_width3 2 #property indicator_width4 2 #property strict // // // // // input color TextColor = clrWhite; // Text color input color ButtonColor = clrSteelBlue; // Background color input color AreaColor = clrGainsboro; // Area color input color SymbolColor = clrSteelBlue; // Symbol color input color LabelsColor = clrDimGray; // Labels color input color ValuesNeutralColor = clrDimGray; // Color for unchanged values input color ValuesPositiveColor = clrMediumSeaGreen; // Color for positive values input color ValuesNegativeColor = clrPaleVioletRed; // Color for negative values input int XPosition = 10; // Controls x position input int YPosition = 10; // Controls y position input ENUM_BASE_CORNER Corner = CORNER_RIGHT_UPPER; // Corner to use for display input int CandleShift = 5; // Candle shift input int TimeFontSize = 10; // Font size for timer input int TimerShift = 7; // Timer shift input int ZonesCount = 1; // Show zones for (n) days : // // // // // double candleOpen[]; double candleHigh[]; double candleLow[]; double candleClose[]; double candleColor[]; // // // // // #define bnameA "DailyDataShowBasic" #define bnameB "DailyDataShowSwaps" #define bnameC "DailyDataShowCandle" #define bnameD "DailyDataShowArea" #define bnameE "DailyDataShowTimer" #define cnameA "DailyDataArea" #define lnameA "DailyDataSymbol" #define lnameB "DailyDataClock" #define lnameC "DailyDataRange" #define lnameD "DailyDataChange" #define lnameE "DailyDataDistH" #define lnameS "DailyDataSpread" #define snameA "DailyDataSwapShort" #define snameB "DailyDataSwapLong" #define clockName "DailyDataTimer" // // // // // //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int OnInit() { SetIndexBuffer(0,candleHigh ,INDICATOR_DATA); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexShift(0,CandleShift); SetIndexBuffer(1,candleLow ,INDICATOR_DATA); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexShift(1,CandleShift); SetIndexBuffer(2,candleOpen ,INDICATOR_DATA); SetIndexStyle(2,DRAW_HISTOGRAM); SetIndexShift(2,CandleShift); SetIndexBuffer(3,candleClose,INDICATOR_DATA); SetIndexStyle(3,DRAW_HISTOGRAM); SetIndexShift(3,CandleShift); SetIndexBuffer(4,candleColor,INDICATOR_COLOR_INDEX); PlotIndexSetInteger(0,PLOT_SHIFT,CandleShift); createObjects(); setControls(); return(0); } // // // // // void OnDeinit(const int reason) { switch(reason) { case REASON_REMOVE : for (int i=ObjectsTotal(); i>= 0; i--) { string name = ObjectName(ChartID(),i); if (StringSubstr(name,0,9)=="DailyData") ObjectDelete(ChartID(),name); } ChartRedraw(); } if (!getState(bnameE)) EventKillTimer(); } // // // // // void OnTimer( ) { refreshData(); } 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[]) { refreshData(); return(rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // void refreshData() { static bool inRefresh = false; if (inRefresh) return; inRefresh = true; // // // // // int bars = ArraySize(candleClose); ENUM_TIMEFRAMES period = PERIOD_D1; if (Period()>= PERIOD_D1) period=PERIOD_W1; if (Period()>= PERIOD_W1) period=PERIOD_MN1; static datetime times[1]; CopyTime(Symbol(),0,0,1,times); static MqlRates rates[]; if (CopyRates( Symbol(),period,0,ZonesCount,rates)candleOpen[0]) { candleHigh [0] = rates[ZonesCount-1].high; candleLow [0] = rates[ZonesCount-1].low; } else { candleHigh [0] = rates[ZonesCount-1].low; candleLow [0] = rates[ZonesCount-1].high; } for (int k=0; k<4; k++) SetIndexDrawBegin(k,Bars-1); // // // // // for (int i=0; i0) cvalue = ValuesPositiveColor; if (dvalue<0) cvalue = ValuesNegativeColor; if (corner==0 || corner==2) xposition += 190; if (corner==1 || corner==3) xposition -= 190; setBasicLabel(name+"v",value,xposition,yposition,corner,cvalue,fontSize,ANCHOR_RIGHT_UPPER,statusCheck,displacement); } // // // // // void setSwapLabel(string name, string label, int xposition, int yposition, int corner, color labelColor, int fontSize=10) { int heightBasic = !getState(bnameA) ? heightForBasic : 20; setBasicLabel(name,label,xposition,yposition,corner,labelColor,fontSize,ANCHOR_LEFT_UPPER,bnameB,heightBasic); } void setSwapValue(string name, string value, int xposition, int yposition, int corner, int fontSize=12) { int heightBasic = !getState(bnameA) ? heightForBasic : 20; setBasicValue(name,value,xposition,yposition,corner,fontSize,bnameB,heightBasic); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // void ShowClock() { int periodMinutes = _Period; int shift = periodMinutes*TimerShift*60; int currentTime = (int)TimeCurrent(); int localTime = (int)TimeLocal(); int barTime = (int)iTime(); int diff = (int)MathMax(round((currentTime-localTime)/3600.0)*3600,-24*3600); // // // // // color theColor; string time = getTime(barTime+periodMinutes*60-localTime-diff,theColor); time = (TerminalInfoInteger(TERMINAL_CONNECTED)) ? time : time+" x"; // // // // // if(ObjectFind(0,clockName) < 0) ObjectCreate(0,clockName,OBJ_TEXT,0,barTime+shift,0); ObjectSetString(0,clockName,OBJPROP_TEXT,time); ObjectSetString(0,clockName,OBJPROP_FONT,"Arial"); ObjectSetInteger(0,clockName,OBJPROP_FONTSIZE,TimeFontSize); ObjectSetInteger(0,clockName,OBJPROP_COLOR,theColor); ObjectSetInteger(0,clockName,OBJPROP_HIDDEN,true); if (ChartGetInteger(0,CHART_SHIFT,0)==0 && (shift >=0)) ObjectSetInteger(0,clockName,OBJPROP_TIME,barTime-shift*3); else ObjectSetInteger(0,clockName,OBJPROP_TIME,barTime+shift+CandleShift*_Period*60); // // // // // double price = Close[0]; double atr = iATR(NULL,0,10,0); price += 3.0*atr/4.0; // // // // // bool visible = ((ChartGetInteger(0,CHART_VISIBLE_BARS,0)-ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR,0)) > 0); if ( visible && price>=ChartGetDouble(0,CHART_PRICE_MAX,0)) ObjectSetDouble(0,clockName,OBJPROP_PRICE,price-1.5*atr); else ObjectSetDouble(0,clockName,OBJPROP_PRICE,price); } //+------------------------------------------------------------------+ //| //+------------------------------------------------------------------+ // // // // // string getTime(int times, color& theColor) { string stime = ""; int seconds; int minutes; int hours; // // // // // if (times < 0) { theColor = ValuesNegativeColor; times = (int)fabs(times); } else theColor = ValuesPositiveColor; seconds = (times%60); hours = (times-times%3600)/3600; minutes = (times-seconds)/60-hours*60; // // // // // if (hours>0) if (minutes < 10) stime = stime+(string)hours+":0"; else stime = stime+(string)hours+":"; stime = stime+(string)minutes; if (seconds < 10) stime = stime+":0"+(string)seconds; else stime = stime+":" +(string)seconds; return(stime); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // datetime iTime(ENUM_TIMEFRAMES forPeriod=PERIOD_CURRENT) { datetime times[]; if (CopyTime(Symbol(),forPeriod,0,1,times)<=0) return(TimeLocal()); return(times[0]); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int periodToMinutes(int period) { int i; static int _per[]={1,2,3,4,5,6,10,12,15,20,30,0x4001,0x4002,0x4003,0x4004,0x4006,0x4008,0x400c,0x4018,0x8001,0xc001}; static int _min[]={1,2,3,4,5,6,10,12,15,20,30,60,120,180,240,360,480,720,1440,10080,43200}; if (period==PERIOD_CURRENT) period = Period(); for(i=0;i<20;i++) if(period==_per[i]) break; return(_min[i]); }