| View previous topic :: View next topic |
| Author |
Message |
swannyfx
Joined: 18 Jun 2010 Posts: 35
|
Posted: Sat Jul 17, 2010 3:05 am Post subject: Number of bars since specific time? |
|
|
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. |
|
| Back to top |
|
 |
FT Support
Joined: 11 Jul 2009 Posts: 901
|
Posted: Sun Jul 18, 2010 12:33 pm Post subject: |
|
|
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 products here:
www.fx-metropolis.com
www.forexcopier.com |
|
| Back to top |
|
 |
swannyfx
Joined: 18 Jun 2010 Posts: 35
|
Posted: Mon Jul 19, 2010 11:00 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
FT Support
Joined: 11 Jul 2009 Posts: 901
|
|
| Back to top |
|
 |
swannyfx
Joined: 18 Jun 2010 Posts: 35
|
Posted: Mon Jul 19, 2010 11:37 am Post subject: |
|
|
Thanks, I'll give that a go. |
|
| Back to top |
|
 |
swannyfx
Joined: 18 Jun 2010 Posts: 35
|
Posted: Mon Jul 19, 2010 12:49 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|