//+------------------------------------------------------------------+ //| DailyLines.mq4 | //| Copyright © 2014, deVries | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2014, deVries" #property link "" #property version "1.00" #property strict #property indicator_chart_window input int MaxBarsToLookBackForSeparators=0; input string LookToAllBars="Input 0"; //--- Colors each day input color Sunday = Red; input color Monday = Blue; input color Tuesday= Blue; input color Wednesday= Blue; input color Thursday = Blue; input color Friday=Blue; input color Saturday=Blue; //--- input parameters for style the day line input ENUM_LINE_STYLE InpStyle=STYLE_DASHDOTDOT; // Line style input int InpWidth=1; // Line width //--- input distance text from top of the chart input double textplace=30; input string InpFont="Arial"; // Font input int InpFontSize=8; // Font size input ENUM_ANCHOR_POINT InpAnchor=ANCHOR_BOTTOM; // Anchor type double textprice,newtextprice, max_price,min_price; string thisday=""; string daycheck1="",daycheck2=""; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //Set Timer EventSetMillisecondTimer(250); //--- 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 i2; int obj_total=ObjectsTotal(0,-1,-1); for(i2=obj_total; i2>=0; i2--) { string name=ObjectName(0,i2,-1,-1); if(StringSubstr(name,0,14)=="NewTradingDay ") {TrendDelete(0,name);} if(StringSubstr(name,0,8)=="DayText ") {TextDelete(0,name);} } //--- destroy timer EventKillTimer(); } //+------------------------------------------------------------------+ //| 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[]) { //--- int i1; // Bar Index string today=TimeToString(time[0],TIME_DATE); // starting index for number of Separators if(MaxBarsToLookBackForSeparators<=0 || MaxBarsToLookBackForSeparators>rates_total-2) i1=rates_total-2; // starting index for calculation of all bars else i1= MaxBarsToLookBackForSeparators; if((daycheck1 == "NewTradingDay "+today)&&(daycheck2 == "DayText "+today))return(rates_total); //--- find the highest and lowest values of the chart max_price=ChartGetDouble(0,CHART_PRICE_MAX); min_price=ChartGetDouble(0,CHART_PRICE_MIN); //calculation place of the text int heightinpixels=ChartHeightInPixelsGet(0,0); textprice=max_price-((max_price-min_price)*(textplace/heightinpixels)); while(i1>=0) { datetime now=time[i1]; thisday=TimeToString(now,TIME_DATE); color clr = CLR_NONE; string text=""; int weekday=TimeDayOfWeekMQL4(now); text = DaytoStr(weekday); clr = DaytoClr(weekday); if(ObjectFind(0,"NewTradingDay "+thisday)<0) { TrendCreate(0,"NewTradingDay "+thisday,0,now,Point(),now,textprice,clr,InpStyle, InpWidth,true,false,true,false,true,0); } if(ObjectFind(0,"DayText "+thisday)<0) { TextCreate(0,"DayText "+thisday,0,now,textprice,text,InpFont,InpFontSize, clr,90,InpAnchor,false,false,true,0); } i1--; } ChartRedraw(0); if(ObjectFind(0,"NewTradingDay "+today)==0)daycheck1="NewTradingDay "+today; if(ObjectFind(0,"DayText "+today)==0)daycheck2="DayText "+today; //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Checks at timechange if objects has to move | //+------------------------------------------------------------------+ void OnTimer() { //--- 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((textprice>newtextprice+Point()) || (textprice