//+------------------------------------------------------------------+ //| DailyLines.mq5 | //| Copyright © 2014, deVries | //| http://www.mql5.com/en/job/new?prefered=deVries | //+------------------------------------------------------------------+ #property copyright "Copyright © 2014, deVries" #property link "http://www.mql5.com/en/job/new?prefered=deVries" #property version "1.00" #property strict #property description "This indicator draws daily period separators" #property description "With telling what tradingday starts at each" #property description "Every day you can color like you want" #property description "what makes also the option to see weekly separator" //--- drawing the indicator in the main window #property indicator_chart_window //--- buffers are not used for indicator calculation and drawing #property indicator_buffers 0 //--- no plot graphical constructions #property indicator_plots 0 input int MaxBarsToLookBackForSeparators = 0; input string MaximumBars = "Input 0"; //--- Colors each day input color Sunday = Blue; input color Monday = Yellow; input color Tuesday = Aqua; input color Wednesday = Aqua; input color Thursday = Aqua; input color Friday = Aqua; input color Saturday = Aqua; //--- input parameters for style day line input ENUM_LINE_STYLE InpStyle=STYLE_DASHDOTDOT; // Line style input uchar InpWidth=1; // Line width //--- input distance text from top of the chart input double textplace = 30; input string InpFont="Arial"; // Font input uchar InpFontSize=8; // Font size input ENUM_ANCHOR_POINT InpAnchor=ANCHOR_BOTTOM; // Anchor type double textprice,newtextprice, max_price,min_price; string thisday = "",daycheck1 = "",daycheck2 = ""; //---- int limit;//, uchar min_rates_total=1; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- find the highest and lowest values of the chart then calculate textposition max_price=ChartGetDouble(0,CHART_PRICE_MAX); min_price=ChartGetDouble(0,CHART_PRICE_MIN); int heightinpixels = ChartHeightInPixelsGet(0,0); textprice = max_price-((max_price-min_price)*(textplace/heightinpixels)); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { int i; int obj_total= ObjectsTotal(0,0,-1); for (i= obj_total; i>=0; i--) { string name= ObjectName(0,i,0,-1); if (StringSubstr(name,0,14)=="NewTradingDay ") {TrendDelete(0,name);} if (StringSubstr(name,0,8)=="DayText ") {TextDelete(0,name);} } } //+------------------------------------------------------------------+ //| 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(rates_total rates_total-1) limit = 0; // starting index for calculation of all bars else limit = rates_total-1-MaxBarsToLookBackForSeparators; } //--- check for new day(s) string today = TimeToString(time[rates_total-1],TIME_DATE); if(thisday == "NewTradingDay "+today)return(rates_total); else if(ObjectFind(0,"NewTradingDay "+today) == 0) { thisday = "NewTradingDay "+today; return(rates_total); } //---- main indicator calculation loop if new day daycheck1 = ""; daycheck2 = ""; for(k=limit; k<=rates_total-1 && !IsStopped(); k++) { datetime now = time[k]; thisday = TimeToString(now,TIME_DATE); int weekday = TimeDayOfWeekMQL4(now); color clr = DaytoClr(weekday); if(daycheck1 != "NewTradingDay "+thisday) { if(ObjectFind(0,"NewTradingDay "+thisday) == 0)daycheck1 = "NewTradingDay "+thisday; else { if(!TrendCreate(0,"NewTradingDay "+thisday,0,now,Point(),now,textprice,clr,InpStyle, InpWidth,true,false,true,false,true,0))daycheck1 = ""; else daycheck1 = "NewTradingDay "+thisday; } } if(daycheck2 != "DayText "+thisday) { if(ObjectFind(0,"DayText "+thisday) == 0)daycheck2 = "DayText "+thisday; else { string text = DaytoStr(weekday); if(!TextCreate(0,"DayText "+thisday,0,now,textprice,text,InpFont,InpFontSize, clr,90,InpAnchor,false,false,true,0))daycheck2 = ""; else daycheck2 = "DayText "+thisday; } } } ChartRedraw(); //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- if(id==CHARTEVENT_CHART_CHANGE) { //--- find the highest and lowest values of the chart max_price=ChartGetDouble(0,CHART_PRICE_MAX); min_price=ChartGetDouble(0,CHART_PRICE_MIN); int heightinpixels = ChartHeightInPixelsGet(0,0); textprice = max_price-((max_price-min_price)*(textplace/heightinpixels)); if((newtextprice>textprice+Point())||(newtextprice