PureBytes Links
Trading Reference Links
|
hi Lester,
as for lwl see my code below. You need to fill in some large number. I used 100000.
The reason that Bill's code give problems (i believe) is because the code uses statements like: start = BarsSince(TimeNum()==startTime); If TimeNum() does not contain the exact startTime then you have a problem. Usually when working with 1 minute data and a liquid stock there is no problem but when using another timeframe there is no value for 093000 inside TimeNum();
Concerning my code I do not like the fact that I need to shift backward the array dtt to get it right (inside: cls = IIf(!tt,ValueWhen(Ref(dtt,1) == -1,C),Null); ). I have to try to work around that.
rgds, Ed
startTime = 153000;
EndTime = 163000;
// assign an array tt having a value 1 inside the interval
tt = IIf(TimeNum() >= startTime AND TimeNum() <= endTime,1,0);
// high within interval
htt = IIf(TimeNum() >= startTime AND TimeNum() <= endTime,H,0);
// low within interval
ltt = IIf(TimeNum() >= startTime AND TimeNum() <= endTime,L,100000);
// start bar of interval is 1, end bar is -1
dtt = tt - Ref(tt,-1);
// calculate the cumulative number of bars inside the interval
bs = BarsSince( dtt == 1 ) + 1;
// find number of bars at the end of interval
bs2 = IIf(dtt == -1,bs,Null);
// assign highest high within the interval assigned to rest of day
hgh = IIf(!tt,HHV(htt,bs2),Null);
// assign highest high within the interval assigned to rest of day
lwl = IIf(!tt,LLV(ltt,bs2),Null);
// close price at end of interval assigned to rest of day
cls = IIf(!tt,ValueWhen(Ref(dtt,1) == -1,C),Null);
SetChartOptions(0, chartShowDates);
Plot(C,"",1,64);
Plot(hgh,"high",colorGold,styleLine);
Plot(lwl,"high",colorBrightGreen,styleLine);
Plot(cls,"close",colorLightBlue,styleLine);
----- Original Message -----
From: Lester Vanhoff
To: amibroker@xxxxxxxxxxxxxxx
Sent: Monday, February 12, 2007 1:11 PM
Subject: [amibroker] Re: How To Get HHV( High, between 09:30 and 10:30 )
Thanks for help. There are two issues here.
1) Bill's formula is shorter but on some days it somehow excludes the first bar (09:30:00 one) from calculations. For example on NQ-H7 five minute chart:
- 2006-12-13: incorrect High
- 2007-01-19: incorrect Low
- 2007-01-26: incorrect High
I double checked my one-minute data and there is nothing missing there. It would be interesting to find out why this is happening.
http://img227.imageshack.us/img227/1142/02122007062358ca3.png
2) Edward's formula is the hell of a code. I tried to add Lowest Low plot but adding the following line simply wouldn't work:
// assign lowest low within the interval assigned to rest of day
lwl = IIf(!tt,LLV(ltt,bs2),Null);
Plot(lwl,"",colorOrange,styleLine);
Here is what I get:
http://img225.imageshack.us/img225/530/02122007063634gx1.png
After marking out Plot(lwl, ... ) statement everything is back to normal.
Also, there are no problems with Highs or Lows on days when Bill's code generates incorrect values.
http://img243.imageshack.us/img243/8375/02122007064123bq7.png
Both formulas, with lines for Lowest Low added and a few minor cosmetic changes, are posted below.
/*** Bill's code ***/
// High and Low in a specified time frame
startTime = 093000;
endTime = 103000;
start = BarsSince(TimeNum()==startTime);
end = BarsSince(TimeNum()==endTime);
per = (start - end);
hgh = ValueWhen(TimeNum()==endTime, HHV(H, per));
lwl = ValueWhen(TimeNum()==endTime, LLV(L, per));
cls = ValueWhen(TimeNum()==endTime, C);
H_plot = IIf(TimeNum()>=endTime, hgh, Null);
L_plot = IIf(TimeNum()>=endTime, lwl, Null);
C_plot = IIf(TimeNum()>=endTime, cls, Null);
Plot(H_plot, "", colorLightBlue, styleLine);
Plot(L_plot, "", colorOrange, styleLine);
Plot(C_plot, "", colorDarkYellow, styleLine);
Plot(C,"",26,64);
SetChartOptions(0, chartShowDates);
Title = "\\c11"+Interval(2)+" "+
Date()+"\\c-1 H="+H+" L="+L;
/*** END ***/
// +++++++++++++++++++++++++++++++ //
/*** Edward's code ***/
// High and Low in a specified time frame
startTime = 093000;
endTime = 103000;
// assign an array tt having a value 1 inside the interval
tt = IIf(TimeNum() >= startTime AND TimeNum() <= endTime,1,0);
// high within interval
htt = IIf(TimeNum() >= startTime AND TimeNum() <= endTime,H,0);
// low within interval
ltt = IIf(TimeNum() >= startTime AND TimeNum() <= endTime,L,0);
// start bar of interval is 1, end bar is -1
dtt = tt - Ref(tt,-1);
// calculate the cumulative number of bars inside the interval
bs = BarsSince( dtt == 1 ) + 1;
// find number of bars at the end of interval
bs2 = IIf(dtt == -1,bs,Null);
// assign highest high within the interval assigned to rest of day
hgh = IIf(!tt,HHV(htt,bs2),Null);
// assign lowest low within the interval assigned to rest of day
lwl = IIf(!tt,LLV(ltt,bs2),Null);
// close price at end of interval assigned to rest of day
// old code: cls = IIf(!tt,ValueWhen(dtt == -1,C),Null);
cls = IIf(!tt,ValueWhen(Ref(dtt,1) == -1,C),Null);
Plot(hgh,"",colorLightBlue,styleLine);
// Plot(lwl,"",colorOrange,styleLine); // this must be fixed
Plot(cls,"",colorDarkYellow,styleLine);
Plot(C,"",26,64);
Title = "\\c11"+Interval(2)+" "+
Date()+"\\c-1 H="+H+" L="+L;
SetChartOptions(0, chartShowDates);
/*** END ***/
Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.35/680 - Release Date: 2/10/2007 9:15 PM
|