Help with Date format

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
User avatar
arnie
Posts: 1589
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 478 times
Been thanked: 509 times

Help with Date format

Postby arnie » 12 Jun 2009

Hi.

Let's see if someone can help me here with the following formula since rarely we see formulas being discussed here :?


My problem with it is drawing the trendlines from the beginning to the end of the selected input days.

How can I tranform the SessHi and SessLo variables into recognizable Date format, assuming that this is the only problem



Code: Select all

Inputs:
   StDay         (21),
   StMnth         (11),
   StYear         (108),
   EnDay         (28),
   EnMnth         (11),
   EnYear         (108),
   PlotLines      (True);
   
Variables:   
   SessST         (true),
   SessEN         (true),
   Hi         (-999999),
   Lo         (+999999),
   SessHi         (0),
   SessLo         (0),
   HiTL         (-1),
   LoTL         (-1);

// Start time period   
SessST = Year(Date) > StYear
   or (Year(Date) = StYear and (Month(Date) > StMnth
   or Month(Date) = StMnth and DayOfMonth(Date) >= StDay));

// End time period
SessEN = Year(Date) < EnYear
   or (Year(Date) = EnYear and (Month(Date) < EnMnth
   or Month(Date) = EnMnth and DayOfMonth(Date) <= EnDay));

// Highest High and Lowest Low inside time period
if SessST and SessEN then begin
   If High > Hi then
      Hi = High;
   If Low < Lo then
      Lo = Low;
      SessHi = Hi;
      SessLo = Lo;
   
   // Plot TrendLines   
   if PlotLines = false then begin   
      HiTL = TL_New(date, Time, SessHi, Date, Time, SessHi);                                    
      LoTL = TL_New(date, Time, SessLo, Date, Time, SessLo);                  
   end;
      
   if PlotLines = false then begin
      TL_SetBegin(HiTL, date, Time, SessHi);      
      TL_SetEnd(HiTL, Date, Time, SessHi);
      TL_SetBegin(LoTL, date, Time, SessLo);            
      TL_SetEnd(LoTL, Date, Time, SessLo);
   end;   

end;



if PlotLines  = true then begin
   if SessHi <> 0 then
      Plot1(SessHi);
   if SessLo <> 0 then
      Plot2(SessLo);
end;

gregorio123456
Posts: 117
Joined: 08 Nov 2005
Been thanked: 3 times

Postby gregorio123456 » 13 Jun 2009

well I don´t try you code but where you get value of SessHi and SessLo you put one line..... dateSessHi=date;timeSessHi=time;==> you have date and time of SessHi

Jo

User avatar
TJ
Posts: 6584
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 970 times
Been thanked: 1907 times

Re: Help with formula

Postby TJ » 14 Jun 2009

Hi.

Let's see if someone can help me here with the following formula since rarely we see formulas being discussed here :?


My problem with it is drawing the trendlines from the beginning to the end of the selected input days.



can you post a mock up chart with arrows pointing to where you want your trendline and notes on how its done?

User avatar
arnie
Posts: 1589
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 478 times
Been thanked: 509 times

Postby arnie » 15 Jun 2009

OK.

See the images attached.

During the weekend I've been trying gregorio's way but with no success.
Attachments
ES image 01.png
ES image 01.png (58.38 KiB) Viewed 698 times
ES image 02.png
ES image 02.png (58.65 KiB) Viewed 717 times

SUPER
Posts: 624
Joined: 03 Mar 2007
Has thanked: 99 times
Been thanked: 80 times

Postby SUPER » 15 Jun 2009

arnie,

I am not sure if you want to plot line from the end date, but this may plot lines similar to what you are looking for.

The last bit of your code will be written as follows:

if SessEN=false and PlotLines = true then begin
if SessHi <> 0 then
Plot1(SessHi);
if SessLo <> 0 then
Plot2(SessLo);
end;

User avatar
TJ
Posts: 6584
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 970 times
Been thanked: 1907 times

Postby TJ » 15 Jun 2009

simplify your input

change from

Code: Select all

Inputs:
   StDay         (21),
   StMnth         (11),
   StYear         (108),


to

Inputs:
StDate (1081121),


then your code can be:

if PlotLines = false then begin
TL_SetBegin(HiTL, stdate, Time, SessHi);


.

User avatar
TJ
Posts: 6584
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 970 times
Been thanked: 1907 times

Postby TJ » 15 Jun 2009

or a more intuitive way of entering date:

input:
start.date(20081121);

var:
stdate(0);

stdate = start.date -19000000;




edit: corrected -19000000 order
sorry for the inconvenience.
Last edited by TJ on 15 Jun 2009, edited 2 times in total.

SUPER
Posts: 624
Joined: 03 Mar 2007
Has thanked: 99 times
Been thanked: 80 times

Postby SUPER » 15 Jun 2009

or a more intuitive way of entering date:

input:
start.date(20081121);

var:
stdate(0);

stdate = start.date -19000000;


TJ,

Thats very clever/interesting :idea: :wink:

2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

Postby 2haerim » 15 Jun 2009

Can you explain a bit more detail how this works?

HR

gregorio123456
Posts: 117
Joined: 08 Nov 2005
Been thanked: 3 times

Postby gregorio123456 » 15 Jun 2009

Can you explain a bit more detail how this works?

HR

try this


Code: Select all

Inputs:
   StDay         (1081121),
 //  StMnth         (11),
 //  StYear         (108),
   EnDay         (1081228);
 //  EnMnth         (11),
 //  EnYear         (108);
   
   
Variables:   
 //  SessST         (true),
 //  SessEN         (true),
   Hi         (-999999),
   Lo         (+999999),
   SessHi         (0),
   SessLo         (0),
   HiTL         (-1),
   LoTL         (-1),
PlotLines      (True);
// Start time period   
//SessST = Year(Date) > StYear
//   or (Year(Date) = StYear and (Month(Date) > StMnth
//   or Month(Date) = StMnth and DayOfMonth(Date) >= StDay));

// End time period
//SessEN = Year(Date) < EnYear
//   or (Year(Date) = EnYear and (Month(Date) < EnMnth
//   or Month(Date) = EnMnth and DayOfMonth(Date) <= EnDay));

// Highest High and Lowest Low inside time period
if StDay < date and EnDay>date then begin
   If High > Hi then
      Hi = High;
   If Low < Lo then
      Lo = Low;
      SessHi = Hi;
      SessLo = Lo;
   
   // Plot TrendLines   
   if PlotLines = true then begin   
      HiTL = TL_New(StDay, Time, SessHi, Date, Time, SessHi);                                   
      LoTL = TL_New(StDay , Time, SessLo, Date, Time, SessLo);
      plotlines=false;                 
   end;
     
   if PlotLines = false then begin
      TL_SetBegin(HiTL, StDay , Time, SessHi);     
      TL_SetEnd(HiTL, date , Time, SessHi);
      TL_SetBegin(LoTL, StDay , Time, SessLo);           
      TL_SetEnd(LoTL, date , Time, SessLo);
   end;   

end;



//if PlotLines  = true then begin
//   if SessHi <> 0 then
//      Plot1(SessHi);
//   if SessLo <> 0 then
//      Plot2(SessLo);
//end;


I post before but w error

jo

User avatar
RobotMan
Posts: 375
Joined: 12 Jul 2006
Location: Los Altos, California, USA
Has thanked: 31 times
Been thanked: 12 times
Contact:

Postby RobotMan » 16 Jun 2009

Back before the turn of the century, back when my gran'pappy was still alive, back in the '80s. The 1980's. The Cruz brothers commissioned a small group of programmers to write a program called "SystemWriter". It was back in a time when phones had cords and email didn't have an "e" and was delivered to your house in small white envelopes called, well, envelopes.

No one thought much about the future because it was so far off. The only thing that mattered was right now, The Present. And right now, The Present always began with 19.
1980-Reagan as elected (yaa!), 1984-Apple Mac (wow, pricey), and 1987-Market Crash (lookout belowwwww). Who needs 20? We got 19 and that's all we will ever need.

But a long came the Y2k and elevators ceased to work, electricity went off in hospitals during surgery and ATMs zeroed out your accounts and planes fell from the sky. Remember? (10 years from now we will be looking back on Global Warming the same way).

"Time" for computers all started in the split second between 1899 and 1900. The month is known as "Month 00" and the day is known as "day 00" and the hour and minute is, well, you get the picture.

Computers also only had so many bits and bytes to play with so, everyone agreed time started, not at the big bang, but at 1900 and was represented as YYYMMDD past this magical demarcation.

Ie. Today is 20090616 (June, 16, 2009), but to Systemwriter, then Supercharts, then TS it would only look like:
20090616 - 19000000 = 1090616. Even to this day. The End.
Attachments
EL Date.jpg
EL Date.jpg (22.36 KiB) Viewed 695 times

User avatar
arnie
Posts: 1589
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 478 times
Been thanked: 509 times

Postby arnie » 18 Jun 2009

I want to apologise to you all for my late reply :oops:

I've been busy on family affairs and my free time has been shortened.

Thank you for all the answers given.

I'll test them this weekend.

Regards,
Fernando

User avatar
arnie
Posts: 1589
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 478 times
Been thanked: 509 times

Postby arnie » 19 Jun 2009

I've been testing the formula and I must say that TJ's way to input date is very "user friendly" :wink: Thanks for the tip

Gregorio, thanks for compiling it.

Just made 2 little modifications and now is 100% as I wanted.

Again, thank you all

Code: Select all

Inputs:
   StDay      (20090507), 
   EnDay      (20090518);

Variables:
   stDate      (StDay - 19000000),
   enDate      (EnDay - 19000000),
   Hi      (-999999),
   Lo      (+999999),
   SessHi      (0),
   SessLo      (0),
   HiTL      (-1),
   LoTL      (-1),
   PlotLines   (True);


// Highest High and Lowest Low inside time period
If stDate <= date and enDate >= date then begin
   If High > Hi then
      Hi = High;
   If Low < Lo then
      Lo = Low;
      SessHi = Hi;
      SessLo = Lo;

// Plot TrendLines
   if PlotLines = true then begin
      HiTL = TL_New(stDate, Time, SessHi, Date, Time, SessHi);
      LoTL = TL_New(stDate , Time, SessLo, Date, Time, SessLo);
      plotlines=false;
   end;

   if PlotLines = false then begin
      TL_SetBegin(HiTL, stDate , Time, SessHi);
      TL_SetEnd(HiTL, currentdate , Time, SessHi);
      TL_SetBegin(LoTL, stDate , Time, SessLo);
      TL_SetEnd(LoTL, currentdate , Time, SessLo);
   end;
end;



User avatar
TJ
Posts: 6584
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 970 times
Been thanked: 1907 times

Postby TJ » 19 Jun 2009

glad you like the tip...



but this is not done yet.
see you soon.

;-)

gregorio123456
Posts: 117
Joined: 08 Nov 2005
Been thanked: 3 times

Postby gregorio123456 » 20 Jun 2009

welcome :-)

jo


Return to “User Contributed Studies and Indicator Library”