logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
mohamedmostfa  
#1 Posted : Wednesday, December 25, 2024 5:37:13 PM(UTC)
mohamedmostfa

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/5/2023(UTC)
Posts: 14
Location: cairo

How to use in the expert the difference between two dates 
Example I have 4-14-2003 and 3-21-2003

How do I write the dates 3-21-2003 and 4-14-2003 in the expert as an equation?

MS Support  
#2 Posted : Thursday, January 2, 2025 4:21:52 PM(UTC)
MS Support

Rank: Advanced Member

Groups: Moderators, Registered, Registered Users, Subscribers
Joined: 10/8/2010(UTC)
Posts: 1,962

Thanks: 92 times
Was thanked: 155 time(s) in 150 post(s)
Originally Posted by: mohamedmostfa Go to Quoted Post

How to use in the expert the difference between two dates 
Example I have 4-14-2003 and 3-21-2003

How do I write the dates 3-21-2003 and 4-14-2003 in the expert as an equation?

Hello,

I might need a bit more detail on the intended use, but generally speaking there are date/time functions that can be used to reference dates. These would be:

DayOfWeek()

DayOfMonth()

Month()

Year()

Hour()

Minute()

There are likely a few ways you could calculate a difference, although this would be based on a number of bars between the dates as opposed to a Calendar based day count.

A simple way would be to use the BarsSince() function along with identifying the date. Do this for both dates, then subtract the difference between the two values.

For example:

Code:
X1:=Month()=4;
X2:=DayOfMonth()=14;
X3:=Year()=2003;
Y1:=Month()=3;
Y2:=DayOfMonth()=21;
Y3:=Year()=2003;
BarsSince(Y1 AND Y2 AND Y3) - BarsSince(X1 AND X2 AND X3);

mohamedmostfa  
#3 Posted : Thursday, January 2, 2025 8:16:24 PM(UTC)
mohamedmostfa

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/5/2023(UTC)
Posts: 14
Location: cairo

Thank you 
I need an expert, not an indicator

MS Support  
#4 Posted : Friday, January 3, 2025 4:48:05 PM(UTC)
MS Support

Rank: Advanced Member

Groups: Moderators, Registered, Registered Users, Subscribers
Joined: 10/8/2010(UTC)
Posts: 1,962

Thanks: 92 times
Was thanked: 155 time(s) in 150 post(s)
Originally Posted by: mohamedmostfa Go to Quoted Post

Thank you 
I need an expert, not an indicator

Hello again,

There are several components to an Expert, but if you are wanting something to display in the Commentary area, then you would need to use the WriteVal() function. For example:

Code:
The number of bars between 3/21/2003 and 4/14/2003 is WriteVal(BarsSince(Month()=3 AND DayOfMonth()=21 AND Year()=2003) - BarsSince(Month()=4 AND DayOfMonth()=14 AND Year()=2003))

mohamedmostfa  
#5 Posted : Saturday, January 4, 2025 8:10:15 AM(UTC)
mohamedmostfa

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/5/2023(UTC)
Posts: 14
Location: cairo

First: Thank you for your interest 
Second: When adding the equation as an expert, an error occurs

Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.