arithmetical datetime operations

Questions about MultiCharts and user contributed studies.
ts2mc
Posts: 122
Joined: 12 Jan 2009
Been thanked: 1 time

arithmetical datetime operations

Postby ts2mc » 27 Jan 2009

hello,
i found nothing about in the help.

i need a function that allows me to add an hour or minute, etc, to
a given datetime and that returns a valid date.

any idea other than using an external DLL in order to solve this,
is welcome.

thank you

User avatar
TJ
Posts: 6598
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1909 times

Postby TJ » 27 Jan 2009

get the Easylanguage manual
http://www.tssupport.com/support/tutorials/


look under:

Manipulating Date and Time.

there are examples and explanations.

key concepts to understand:
-- Julian time
-- EL time
-- real time
-- computer time
Last edited by TJ on 27 Jan 2009, edited 1 time in total.

ts2mc
Posts: 122
Joined: 12 Jan 2009
Been thanked: 1 time

Postby ts2mc » 27 Jan 2009

hello tj,
thank you for reply. these docs are useful in any case.

however, i found nothing in the documents about i am looking for.
perhaps i have tomatos on my eyes.
if you know a document and/or chaptor i would appreciate
to know them.

User avatar
TJ
Posts: 6598
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1909 times

Postby TJ » 27 Jan 2009

hello tj,
thank you for reply. these docs are useful in any case.

however, i found nothing in the documents about i am looking for.
perhaps i have tomatos on my eyes.
if you know a document and/or chaptor i would appreciate
to know them.


look under:

Manipulating Date and Time.

Tresor
Posts: 1104
Joined: 29 Mar 2008
Has thanked: 12 times
Been thanked: 51 times

Postby Tresor » 27 Jan 2009

TJ,

Is there any way to get or write a function that returns the most recent price field update with a high precision (not minute but second).

I know there is such a thing like TradeTime (with minute precision) but a need something like TradeTime_s (second precision) or TradeTime_ms (milisecond precision).

Would it be possible with EL?

Regards

User avatar
TJ
Posts: 6598
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1909 times

Postby TJ » 27 Jan 2009

TJ,

Is there any way to get or write a function that returns the most recent price field update with a high precision (not minute but second).

I know there is such a thing like TradeTime (with minute precision) but a need something like TradeTime_s (second precision) or TradeTime_ms (milisecond precision).

Would it be possible with EL?

Regards


you are talking about Time & Sales.

I don't think MC has that.

Tresor
Posts: 1104
Joined: 29 Mar 2008
Has thanked: 12 times
Been thanked: 51 times

Postby Tresor » 27 Jan 2009

TJ,

Is there any way to get or write a function that returns the most recent price field update with a high precision (not minute but second).

I know there is such a thing like TradeTime (with minute precision) but a need something like TradeTime_s (second precision) or TradeTime_ms (milisecond precision).

Would it be possible with EL?

Regards


you are talking about Time & Sales.

I don't think MC has that.


Marina,

Is it possible in MC?

Regards

ts2mc
Posts: 122
Joined: 12 Jan 2009
Been thanked: 1 time

Postby ts2mc » 27 Jan 2009

Hello TJ,
finally got it, thank you:

inputs: ELTime(NumericSimple),GMTOffset(NumericSimple);

variables: NewTime(0);

NewTime = ELTimeToDateTime(ELTime) + GMTOffset / 24.0;
TimeShiftGmt = DateTime2ElTime(NewTime );



(to MC team, allow me to mention:
ELTimeToDateTime
and
DateTime2ElTime

(2 <-> to)

is no good style in order to provide intuitive programming.)

bowlesj3
Posts: 2028
Joined: 21 Jul 2007
Has thanked: 174 times
Been thanked: 405 times

Postby bowlesj3 » 27 Jan 2009

This may help. It works for time only. However for time it does not work from one day to the next. It does work over the midnight however. You can extract whatever you want from it or use the function as is to make it easier to remember if you need a lot of time calculations.


Code: Select all

{A_TimeAddSub_s}
{
Result_s = A_TimeAddSub_s(Time_s, "A", 1, "S");
Result_s = A_TimeAddSub_s(Time_s, "A", 5, "M");
Result_s = A_TimeAddSub_s(Time_s, "A", 3, "H");
Result_s = A_TimeAddSub_s(Time_s, "A", 3, "H");
Result_s = A_TimeAddSub_s(Time_s, "S", 1, "H");
}

inputs:
   TimeIn(NumericSimple),
   AddSub(StringSimple),
   UnitsIn(NumericSimple),
   UnitsToAdd(StringSimple);
   
variables:
   AddSubAmt(0),
   OneHour(1/24), {1 divided by the number of hours in a day}
   OneMinute(1/1440), {1 divided by the number of minutes in a day}
   OneSecond(1/86400); {1 divided by the number of seconds in a day}
   
if AddSub = "A" then
   AddSubAmt = 1;
if AddSub = "S" then
   AddSubAmt = -1;
 
if AddSubAmt = 0 then
   A_TimeAddSub_s = 0
else
   begin
   if UnitsToAdd = "S" then
      A_TimeAddSub_s = DateTime2ELTime_s(ELTimeToDateTime_s(TimeIn) + ((UnitsIn * OneSecond) * AddSubAmt));
   if UnitsToAdd = "M" then
      A_TimeAddSub_s = DateTime2ELTime_s(ELTimeToDateTime_s(TimeIn) + ((UnitsIn * OneMinute) * AddSubAmt));
   if UnitsToAdd = "H" then
      A_TimeAddSub_s = DateTime2ELTime_s(ELTimeToDateTime_s(TimeIn) + ((UnitsIn * OneHour) * AddSubAmt));
   end;
     
   


Here is the caller test.

Code: Select all




Print( File("C:\Access\A_DateTimeLearningTests1.txt"),
        " Time_s", " " ,
       Time_s, " --- " ,

    " add 1Sec", " " ,
       A_TimeAddSub_s(Time_s,"A", 1, "S") , " " ,
 
       " add 1min", " " ,
       A_TimeAddSub_s(Time_s,"A", 1, "M") , " " ,

       " add 1hour", " " ,
        A_TimeAddSub_s(Time_s,"A", 1, "H") , " " ,
 
     " subtract 1Sec", " " ,
        A_TimeAddSub_s(Time_s,"S", 1, "S") , " " ,
 
       " subtract 1min", " " ,
        A_TimeAddSub_s(Time_s,"S", 1, "M") , " " ,
 
       " subtact 1hour", " " ,
       A_TimeAddSub_s(Time_s,"S", 1, "H") , " " ,
 
                  " ");


ts2mc
Posts: 122
Joined: 12 Jan 2009
Been thanked: 1 time

Postby ts2mc » 27 Jan 2009

thank a lot for this more general function

it would be a good idea to provide something like libraries
where you can group functions of a specific subject (to my dear MC).

bowlesj3
Posts: 2028
Joined: 21 Jul 2007
Has thanked: 174 times
Been thanked: 405 times

Postby bowlesj3 » 28 Jan 2009

Your Welcome. Yah, it should be included in the functions you get with MC actually. (It should have been, way back before I wrote it).
John.


Return to “MultiCharts”