Number of bars since specific time?

How to create strategies and indicators
Message
Author
swannyfx
Posts: 35
Joined: Fri Jun 18, 2010 12:35 am

Number of bars since specific time?

#1 Postby swannyfx » Fri Jul 16, 2010 10:05 pm

Hi,

I'm using the GetHighestValue and GetLowestValue functions from the TechnicalFunctions.pas file to calculate the highest/lowest prices for the previous day (starting at 0300 hours), which is working well during the week as the number of 60 min bars per day is obviously constant.

The issue I'm having is that my calculations on Mondays can be incorrect as my Monday data starts at 0100 (instead of 0000) and the previous Friday closes at either 2000, 2200 or 2300, so the number of bars since Friday 0300 is variable.

I think the solution to my problem is to calculate how many bars ago the 0300 bar formed, but I'm not sure how I can determine this? Any ideas?

Could I achieve this functionality a different way?

Thanks,
Swannyfx.

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#2 Postby FT Support » Sun Jul 18, 2010 7:33 am

Hello,

you can try the folowing functions:

1 iBarShift - returns index of a bar by its time
2. iHighest - returns index of a bar with the highest value
3. iLowest - returns index of a bar with the lowest value

you can define bar shift and then call iHighest (iLowest) to find price value

i hope it will help

P.S. these fnctions are available in Forex Tester 2.5. or above.
Check our other product here:
http://www.forexcopier.com

swannyfx
Posts: 35
Joined: Fri Jun 18, 2010 12:35 am

#3 Postby swannyfx » Mon Jul 19, 2010 6:00 am

Thanks for the response FT Support.

What format does the time need to be in the iBarShift function? I'm using the EncodeTime function to generate the time value but the iBarShift function is returning the barindex of the very first bar (the earliest historically), so my time value must be formatted incorrectly. Here's the relevant lines of my code:

var
SessionStartHour: integer = 3;
myTime: TDateTime;
LookBack: integer;

myTime := EncodeTime(SessionStartHour, 00, 00, 00);
LookBack := iBarShift(Currency, 60, myTime, false);


Am I using the function correctly? How should I format the time for the iBarShift function?

Thanks for your help,
swannyfx

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#4 Postby FT Support » Mon Jul 19, 2010 6:17 am

Please use EncodeDateTime instead of EncodeTime function. Please see more information here:
http://www.delphibasics.co.uk/RTL.asp?N ... deDateTime
Check our other product here:
http://www.forexcopier.com

swannyfx
Posts: 35
Joined: Fri Jun 18, 2010 12:35 am

#5 Postby swannyfx » Mon Jul 19, 2010 6:37 am

FT Support wrote:Please use EncodeDateTime instead of EncodeTime function. Please see more information here:
http://www.delphibasics.co.uk/RTL.asp?N ... deDateTime


Thanks, I'll give that a go.

swannyfx
Posts: 35
Joined: Fri Jun 18, 2010 12:35 am

#6 Postby swannyfx » Mon Jul 19, 2010 7:49 am

Thanks, EncodeDatetime worked great with iBarShift.

For anyone thats interested, here's the code I used:

- - - - - - - - - -

var
SessionStartHour: integer = 2;
myTime, yesterdaytime: TDateTime;
myYear, myMonth, myDay : Word;
.
.
.
// Get date of the previous daily bar
yesterdaytime := iTime(Symbol, PERIOD_D1, 1);
DecodeDate(yesterdaytime, myYear, myMonth, myDay);

// Find number of bars since start of previous session (sometimes varies over the weekend)
myTime := EncodeDateTime(myYear, myMonth, myDay, SessionStartHour, 00, 00, 00);
LookBack := iBarShift(Currency, 60, myTime, false);

// Get previous days high and low
YestHigh := GetHighestValue(vt_High,1,LookBack);
YestLow := GetLowestValue(vt_Low,1,LookBack);

- - - - - - -

There's probably a more elegant way to achieve this but it works fine for me.

Thanks for your help FT.

Regards,
swannyfx


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 22 guests