Tricky programming: projecting date and time ...

Questions about MultiCharts and user contributed studies.
User avatar
furytrader
Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 215 times

Tricky programming: projecting date and time ...

Postby furytrader » 21 Sep 2011

I am working on an indicator and I was hoping to tap into the collective wisdom of this group.

This indicator involves drawing a series of trendlines that have to be of a specific bar length. Depending on where the trend line starts, there could be instances where the terminal points of the trendline actually go off the right side of the chart (in other words, they terminate at a date and time that has not yet occurred, and so doesn't yet appear on the chart).

Consequently, I am looking for a way to take a bar number (for example, bar number #2031) and, based on adding a specified number of bars to that bar number (for example, 50), calculate what the date and time of that new bar number would be.

I know ... it's a weird question. The reason this is coming up is because, from what I understand, the only way to draw trendlines using EasyLanguage is to specify a begin date, begin time, price, end date, end time, price. You can't use the number of bars to specify length.

As long as the end date and end time already appear on the chart, it's pretty easy. However, when it goes off the right side of the chart, we don't have actual time and date data to work, and so there needs to be some kind of "projected" time and date, based on the number of bars being added and the bar interval type.

Maybe I'm looking at this all wrong, but I was wondering if anyone had any suggestions on how to do this. While I have tons of experience in programming other aspects of EasyLanguage, this is my first foray into programming trendlines.

Thanks for any help you can provide!

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

Re: Tricky programming: projecting date and time ...

Postby TJ » 21 Sep 2011

furytrader wrote:I am working on an indicator and I was hoping to tap into the collective wisdom of this group.

This indicator involves drawing a series of trendlines that have to be of a specific bar length. Depending on where the trend line starts, there could be instances where the terminal points of the trendline actually go off the right side of the chart (in other words, they terminate at a date and time that has not yet occurred, and so doesn't yet appear on the chart).

Consequently, I am looking for a way to take a bar number (for example, bar number #2031) and, based on adding a specified number of bars to that bar number (for example, 50), calculate what the date and time of that new bar number would be.

I know ... it's a weird question. The reason this is coming up is because, from what I understand, the only way to draw trendlines using EasyLanguage is to specify a begin date, begin time, price, end date, end time, price. You can't use the number of bars to specify length.

As long as the end date and end time already appear on the chart, it's pretty easy. However, when it goes off the right side of the chart, we don't have actual time and date data to work, and so there needs to be some kind of "projected" time and date, based on the number of bars being added and the bar interval type.

Maybe I'm looking at this all wrong, but I was wondering if anyone had any suggestions on how to do this. While I have tons of experience in programming other aspects of EasyLanguage, this is my first foray into programming trendlines.

Thanks for any help you can provide!


if you are not fussy...
you can find the slope... plot the end point in the current bar,
then use TL_SETEXTRIGHT to extend the line into the future.
These users thanked the author TJ for the post:
furytrader

User avatar
furytrader
Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 215 times

Re: Tricky programming: projecting date and time ...

Postby furytrader » 21 Sep 2011

Thanks for the idea, TJ. If anyone has any other suggestions, please share.

Thanks!

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

Re: Tricky programming: projecting date and time ...

Postby TJ » 21 Sep 2011

depending on what bar type and resolution you use...

trendlines work the best in minute charts.

if you want to project into a specific data/time in the future,
you can find the future date and time by multiplying the barinterval with the # of bars you want to go into the future.

You will need to convert the time into serial date/time,
do the required arithmetic, then convert back to ELtime.

It is not difficult, just tedious.
These users thanked the author TJ for the post:
furytrader

User avatar
furytrader
Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 215 times

Re: Tricky programming: projecting date and time ...

Postby furytrader » 21 Sep 2011

TJ - thanks again for the tip. One thing that can be problematic about multiplying the # of bars by the interval is that I think you need to take into account that some calendar days aren't trading days (and some times of day aren't trading times), so you can't include those periods when you're counting your bars.

If I come up with something that works, I'll be sure to post it here.

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

Re: Tricky programming: projecting date and time ...

Postby TJ » 21 Sep 2011

furytrader wrote:TJ - thanks again for the tip. One thing that can be problematic about multiplying the # of bars by the interval is that I think you need to take into account that some calendar days aren't trading days (and some times of day aren't trading times), so you can't include those periods when you're counting your bars.

If I come up with something that works, I'll be sure to post it here.

There is no one solution that fits all;
without telling what chart type and resolution you are using,
there is not much more I can offer.

trendlines work best in minute charts... one of the reason is you don't have to deal with non-business days.

you can use DayOfWeek to filter out Saturday and Sunday.

for time, you have to convert to serial time to avoid the non-real times.

Beyond that, if you want to filter for specific days and times,
you have no choice but to build specific filters for those date/times.

It is not difficult, just tedious.
These users thanked the author TJ for the post:
furytrader


Return to “MultiCharts”