[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: How To Get HHV( High, between 09:30 and 10:30 )



PureBytes Links

Trading Reference Links

hi Lester,

tt = IIf(TimeNum() >= startTime AND TimeNum() <= endTime,1,0); 

tt will be 1 within the time interval and 0 outside this interval

dtt = tt - Ref(tt,-1); 

dtt or delta t will be 1 at the first bar of the interval and -1 at the end bar of the interval + 1 bar

example:

tt:   0000000111111100000
dtt: 00000001000000-10000


!tt returns a 0 at places where tt is 1 and a 1 at place where tt is 0.

so the formula below will fill an array C_Plot at bars where tt  is equal to 0   (!tt or tt == 0) with the value of the Close at the bar where dtt == -1.  Since dtt is -1 one bar outside the time interval I shift the array dtt 1 bar to the left using Ref(dtt,1). Now we use the value of the Close that coincides with the end bar of the interval.

C_Plot = IIf(!tt,ValueWhen(Ref(dtt,1) == -1,C),Null);

this can also be written as:

C_Plot = IIf(tt == 0,ValueWhen(Ref(dtt,1) == -1,C),Null); 
 

regards, Ed



  ----- Original Message ----- 
  From: Lester Vanhoff 
  To: amibroker@xxxxxxxxxxxxxxx 
  Sent: Tuesday, February 13, 2007 11:09 AM
  Subject: [amibroker] Re: How To Get HHV( High, between 09:30 and 10:30 )


  Ed, I have finally got some time to look over your code and can't really figure out the following line:

  C_Plot = IIf(!tt, ValueWhen(Ref(dtt,1) == -1, C), Null);

  Can you explain it in plain English, when you have a minute.

  I plotted "tt" and "dtt" so I can see how those variables work but I still have two questions.

  http://img396.imageshack.us/img396/8725/02132007045238fe6.png

  1) What does the exclamation mark mean here:

  !tt

  I guess that's some "c" language shortcut that I don't know.

  2) How to interpret the section with ValueWhen(). Is this the right translation:

  "when dtt one bar into the future equals minus one, then return the value of Close".

  Tnx, Lester

  --- In amibroker@xxxxxxxxxxxxxxx, "Edward Pottasch" <empottasch@xxx> wrote:
  >
  > yes Lester your code using the plugin looks good except for the fact that the Close price line disappears when you switch away from the 1-minute time frame or when the close price at endTime does not exist, since
  > 
  > cls = deValueWhenTime(C, endTime); 
  > 
  > looks at the value for C at a specific bar. The only way to avoid this (in my opinion ofcourse ..) is using code that does not look within a specific bar labelled by time. 
  > 
  > 
  > // High and Low in a specified time frame 
  > startTime = 153000; 
  > endTime = 163000; 
  > 
  > tt = IIf(TimeNum() >= startTime AND TimeNum() <= endTime,1,0); 
  > dtt = tt - Ref(tt,-1); 
  > 
  > // add-on plugin functions 
  > hgh = deTimeRangeHHV (H, startTime, endTime); 
  > lwl = deTimeRangeLLV (L, startTime, endTime); 
  > //cls = deValueWhenTime(C, endTime); 
  > 
  > H_plot = IIf(TimeNum()>=endTime, hgh, Null); 
  > L_plot = IIf(TimeNum()>=endTime, lwl, Null); 
  > //C_plot = IIf(TimeNum()>=endTime, cls, Null); 
  > C_Plot = IIf(!tt,ValueWhen(Ref(dtt,1) == -1,C),Null); 
  > 
  > Plot(H_plot, "", colorLightBlue, styleLine); 
  > Plot(L_plot, "", colorOrange, styleLine); 
  > Plot(C_plot, "", colorDarkYellow, styleLine); 
  > 
  > SetChartOptions(0, chartShowDates); 
  > Plot(C,"",26,64); 
  > 
  > Title = "\\c11"+Interval(2)+" "+ 
  > Date()+"\\c-1 H="+H+" L="+L+" C="+C; 
  > 
  > 
  > 
  > 
  > 
  > 
  > 
  > ----- Original Message ----- 
  > From: Lester Vanhoff 
  > To: amibroker@xxxxxxxxxxxxxxx 
  > Sent: Monday, February 12, 2007 5:32 PM
  > Subject: [amibroker] Re: How To Get HHV( High, between 09:30 and 10:30 )
  > 
  > 
  > Ed: I coded it using the plugin. However again if you change the timeframe from 1-minute to 5-minute it seems to give problem,
  > 
  > My code from message 106471 (using plugin's functions) seems to be working ok with different periodicities (1, 2, 3, 5, 10 ,15, 30 and 60 min charts).
  > 
  > Lester
  > 
  > --- In amibroker@xxxxxxxxxxxxxxx, "Edward Pottasch" <empottasch@> wrote:
  > >
  > > i didn't know about this plugin.
  > > 
  > > I coded it using the plugin. However again if you change the timeframe from 1-minute to 5-minute it seems to give problem,
  > > 
  > > Ed
  > > 
  > > 
  > > 
  > > startTime = 153000; 
  > > EndTime = 163000; 
  > > 
  > > hgh = deTimeRangeHHV( H, startTime, endTime); 
  > > lwl = deTimeRangeLLV( L, startTime, endTime); 
  > > 
  > > phgh = deValueWhenTime( hgh, endTime); phgh = IIf(TimeNum() >= startTime AND TimeNum() <= endTime,Null,phgh); 
  > > plwl = deValueWhenTime( lwl, endTime); plwl = IIf(TimeNum() >= startTime AND TimeNum() <= endTime,Null,plwl); 
  > > pcls = deValueWhenTime ( C, endTime); pcls = IIf(TimeNum() >= startTime AND TimeNum() <= endTime,Null,pcls); 
  > > 
  > > SetChartOptions(0, chartShowDates); 
  > > Plot(C,"",1,64); 
  > > Plot(phgh,"high",colorGold,styleLine); 
  > > Plot(plwl,"high",colorBrightGreen,styleLine); 
  > > Plot(pcls,"close",colorLightBlue,styleLine); 
  > > 
  > > 
  > > 
  > > 
  > > 
  > > 
  > > ----- Original Message ----- 
  > > From: Lester Vanhoff 
  > > To: amibroker@xxxxxxxxxxxxxxx 
  > > Sent: Monday, February 12, 2007 1:50 PM
  > > Subject: [amibroker] Re: How To Get HHV( High, between 09:30 and 10:30 )
  > > 
  > > 
  > > Thanks, Anthony. This looks like the easiest solution. I'll check that later:
  > > 
  > > deTimeRangeHHV( array, starttime, endtime);
  > > deTimeRangeLLV( array, starttime, endtime);
  > > deValueWhenTime ( array, time);
  > > 
  > > Lester
  > > 
  > > --- In amibroker@xxxxxxxxxxxxxxx, "Anthony Faragasso" <ajf1111@> wrote:
  > > >
  > > > Lester,
  > > > 
  > > > Using the deDateTime.dll plugin from the 3rd party area...I have never had any problems accessing the data at certain times...
  > > > 
  > > > Anthony
  > > > ----- Original Message ----- 
  > > > From: Lester Vanhoff 
  > > > To: amibroker@xxxxxxxxxxxxxxx 
  > > > Sent: Monday, February 12, 2007 7:11 AM
  > > > 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.37/682 - Release Date: 2/12/2007 1:23 PM