English

## Date Arithmetic

 55 strontiumDog 2016.09.16 18:29   HelloI have a fn which calcs missed daily, weekly and monthly pivots, and plots lines.Due to the lines being triggered by buttons, the calc is done in an EA, not an indicator.  I need to plot the lines to start level with the first bar of the day (daily), week (weekly, i.e. Monday 0000) and month (1st of the month).When the daily button is hit, I use`string lineStart = TimeToString(TimeCurrent(),TIME_DATE);`to plot the daily - easy.  For the weekly, I'm struggling with working out the most efficient way to do this.  My man will be changing the timeframe, so the line will be redrawn for the selected period() on next tick.  Worse, for the 1st day of the month, this may be a saturday, so I may need to then adjust to the Sunday evening first bar of the week.I've not found anything really useful on the web so far, I'd appreciate advice on the matter.  Thanks
 736 honest_knave 2016.09.16 20:05 #   strontiumDog:Due to the lines being triggered by buttons, the calc is done in an EA, not an indicator. FYI: buttons work fine in an indicator the same as an EA.I'm not entirely sure what you need, but if you're working off the broker (server) times the easiest way to retrieve the start of the day / week / month is using iTimeOnce you have the time, you can use iBarShift to figure out which bar that is on your current chart timeframe... But if you're drawing a line, you won't need to know the shift because the parameters are price and time.Maybe this will help, based on the thread title? It just illustrates how you can add to (or subtract from) datetimes to get what you need (e.g. add offsets to broker time in order to get local time etc)```   #define WEEK 604800 // seconds in a week    datetime StartWk=iTime(NULL,PERIOD_W1,0),             EndWk  =StartWk+WEEK-1;      string name="MyLine";    ObjectCreate(0,name,OBJ_TREND,0,StartWk,High[0],EndWk,High[0]);    ObjectSetInteger(0,name,OBJPROP_RAY,false); ```