# Future Date

Converting a chart point in the future into a date or time is indeed difficult because of all the variations of when markets are open or closed, holidays, and weekends.   We can visually show you the distance and you can drag the chart leftward so more margin shows on the right side, but what I feel you are wanting it a date.

This script gives an estimated date on a daily bar chart for some point in the future.

procedure FutureDate;
var
bs,bs2,x1,x2,x3,x4,i: integer;
y,m,d,w: word;
l: longint;
s: string;
t: TDateTime;
begin
SetPen(clWhite);
MoveToLineTo(Pt1X,Pt1Y,Pt2X,Pt1Y);
MoveToLineTo(Pt1X,Pt1Y,Pt1X+8,Pt1Y-8);
MoveToLineTo(Pt1X,Pt1Y,Pt1X+8,Pt1Y+8);
MoveToLineTo(Pt2X,Pt1Y,Pt2X-8,Pt1Y-8);
MoveToLineTo(Pt2X,Pt1Y,Pt2X-8,Pt1Y+8);

x1:=XtoIndex(Pt1X);
x2:=XtoIndex(Pt2X);
x4:=IndexToX(BarEnd);
if Pt2X<=x4 then begin
d:=Bar(eDate,x2); s:=Copy(DateToString(d),1,5);
end
else begin
l:=Bar(eDate,BarEnd);
d:=l mod 100; l:=l div 100;
m:=l mod 100; y:=l div 100 + 1900;
t:=EncodeDate(y,m,d);
bs:=GetVariable(eBarSpace); bs2:=bs shr 1;
x3:=Pt2X;
while x3>=(x4+bs2) do begin
x3:=x3-bs; inc(t); inc(x2);
w:=DayOfWeek(t);
if w=7 then t:=t+2;  {skip Saturday}
if w=1 then t:=t+1;  {skip Sunday}
end;
s:=FormatDateTime('mm-dd',t);
end;
x3:=(Pt1X+Pt2X) shr 1;
TextOut(x3-30,Pt1Y-6,'  '+inttostr(x2-x1)+'  '+s+'  ');
end;

{----- MAIN PROGRAM -----}
begin
if Who=11 then FutureDate;
end;

Cut the script and paste it into the script editor.  You may want to save it as a tool under a name like  "FutureDate".   After saving, click on the RUN button to compile the script and be sure its syntax is correct.    To use, display a daily chart and click on the draw tools panel.  Click on the #1 button which has a hint of  Who=11.    Go to the chart, and click down at the start point and drag rightward to a future point in the right margin.   The line that is drawn will be labeled with the number of bars between the two points and an estimated date of the 2nd point.