compare current Time/time_s

Questions about MultiCharts and user contributed studies.
vking
Posts: 235
Joined: 21 May 2009
Has thanked: 51 times
Been thanked: 41 times

compare current Time/time_s

Postby vking » 23 May 2012

Hello - I am trying to port some code from TS to MC. Running into a strange issue with time comparision.

Example:
TS Code:

Code: Select all

Vars: TimeRef(1112);  // representing 11(Hours):12(Minutes)

if Time[1] <= TimeRef and Time[0] > TimeRef then begin
 print("Reference Time: ",Date:0:0," ",Time:0:0);
end;


Above code works fine as is in MC.

However when I try the below code ( after adding seconds timestamp ) it doesn't work as expected:

Code: Select all

Vars: TimeRef(111200);  // Assuming this would represent 11(Hours):12(Minutes):00 Seconds

if Time_s[1] <= TimeRef and Time_s[0] > TimeRef then begin
  print("Reference Time: ",Date:0:0," ",Time_s:0:0);
end;


The second code doesn't capture the time expected but instead captures the time 00h:11m:12s. Looked at the function - DateTime2ELTime_s but help available on this function is not much and wondering how to handle this situation.

Thanks.

vking
Posts: 235
Joined: 21 May 2009
Has thanked: 51 times
Been thanked: 41 times

Re: compare current Time/time_s

Postby vking » 23 May 2012

Looks like encodeTime would get me the result that I need.. experimenting..

vking
Posts: 235
Joined: 21 May 2009
Has thanked: 51 times
Been thanked: 41 times

Re: compare current Time/time_s

Postby vking » 23 May 2012

Thanks TJ. If you look at the code in second box - it already has trailing "00"s at the end but doesn't work as expected in MC as is. Looks like there is a trick to get it done.. exploring options..

Thanks.

User avatar
TJ
Posts: 6523
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: compare current Time/time_s

Postby TJ » 23 May 2012

vking wrote:Thanks TJ. If you look at the code in second box - it already has trailing "00"s at the end but doesn't work as expected in MC as is. Looks like there is a trick to get it done.. exploring options..

Thanks.

Silly me... I overlooked that. I am deleting my prev post to avoid confusion.


ps. what is the chart resolution you used for this indicator? tick chart? seconds chart?

vking
Posts: 235
Joined: 21 May 2009
Has thanked: 51 times
Been thanked: 41 times

Re: compare current Time/time_s

Postby vking » 23 May 2012

Thanks TJ. I am using seconds based chart. Actually the code "does" work fine as expected. I overlooked something..

There is no issue as such with the code posted in second box.

Sorry for the confusion..

Thanks

Code: Select all

Vars: TimeRef(111200);  // Assuming this would represent 11(Hours):12(Minutes):00 Seconds

if time_s[1] < TimeRef and time_s > TimeRef then begin
  plotpaintbar(h,l,o,c,"a");
end;
These users thanked the author vking for the post:
TJ


Return to “MultiCharts”