>From AmiBroker help file: Tomasz Janeczko tj --at-- amibroker.com 2004-07-23 07:07:29 When QuickAFL is ON, the BarIndex() may not be equal with array item index.
Actual array item corresponding to bar index can be found this way: bi = BarIndex(); arrayitem = SelectedValue( bi ) - bi[ 0 ]; "Close at selected bar:" + Close[ arrayitem ]; [EMAIL PROTECTED] 2007-11-03 14:12:22 BarIndex() returns an array and LastValue() returns a number. The API's example compares the two to give the boolean ThisIsLastBar. How could an array be compared with a number? How could it work? Please explain. Tomasz Janeczko tj at amibroker dot com 2007-11-04 09:14:21 That's simple - it compares each array element to a number and produces array as a result. Detailed explanation in User's Guide: Tutorial: Understanding AFL --- In amibroker@yahoogroups.com, "af_1000000" <[EMAIL PROTECTED]> wrote: > > The following simple code works only ones, when I double click on the > indicator (called TEST). The plot is perfect. > > bi = BarIndex(); > dt_array = DateTime(); > Trade_dt=dt_array[SelectedValue(bi)]; > Trade_dt_text = DateTimeToStr(Trade_dt); > > Trade_flag = IIf(dt_array == Trade_dt,1,0); > Plot(Trade_flag,"F",colorRed); > > The moment I click on the chart or indicator (refresh) there is an error: > Error 10 > Substrict out of range. > You must not access array elements outside 0..(Barcount -1) range. > Error is at Trade_dt_text ..... > > I know how to fix it. Just insert in the very beginning > SetBarsRequired(100000,0);, but that's not the point. > > 1.Why does it work the first time , but not the second and the > following refreshes ? > 2.There is a price to pay for it. Execution time increases > dramatically. The SelectedValue is almost in every case at the very > end of the chart. Quick AFL should cover such cases, but it seems that > DateTime() is excluded from quick AFL. Is it true? > > I will appreciate some explanation, so I can write more efficient > software. Thank you in advance. > > AF >