Unless you specify SetBarsRequired(nnnn,nnnn) where nnnn is larger than the 
number of bars in your database Ami will only load enough bars, into a 
temporary array, so that it can display your charts correctly. When you add 
more bars to a window the temp array is enlarged and the indicator is 
recalculated so that what is plotted will again be correct. So the number you 
get in your test will be the number of bars displayed + the longest period in 
any of your indicators. It gets worse. If you try to manually access data that 
is beyond the scope of the temporary array you will get an access violation 
which will either blow your program up or return invalid data. 

There is another thing you need to know. When you set anything in an array you 
will have to set it every time the indicator is scanned. When the indicator is 
scanned all the indicators plotted are recalculated. In real time trading this 
can be many times a second and since you will be adding data the point you want 
to access may be outside the scope of the bars. If you are using static data it 
will scan your indicator every time you click on a bar or change the number of 
bars displayed or scroll through the bars. Managing data as you plan will get 
very complicated and hell to debug when it works incorrectly. Expect errors.

You will be much better off if you can devise a dynamic way to access data in 
earlier bars using standard AFL logic. Then reference it with the Ref() 
statement. I see some people using for, do and while loops in Ami. Most of the 
time that can be replaced with AFL array logic which is much faster and less 
prone to calculation errors. For example someone sent me a formula the other 
day to debug. It was using all the bars in the ticker. I was testing an auto 
trading formula on a 5 minute chart and when I started his formula Ami ground 
to a crawl. It was processing his loop three times a second, well it was trying 
to and doing badly. Avoid loops wherever possible.

Barry

--- In [email protected], "edwol53" <ed...@...> wrote:
>
> Hello 
> 
> I am trying to access/extract a subscript [i] if an array element a[i].
> 
> The aim is to input a date and extract the bar subscript from that date's bar 
> so that the subscript can be used over-write/modify an associated array 
> element[i] (if I understand how array data is constructed in AFL correctly 
> ???)
> 
> A test code segment and debug outputis shown below. The issue I am having 
> difficulty with is that in the first line the index and barcount are correct 
> if all the data (including bars not displayed on the screen) is taken into 
> account. In line 2 the barcount readjusts to number of bars displayed on the 
> screen. I can accept that as a quirk but works. I then zoom out (as shown by 
> barcount)loading all the bars (data) onto the screen(debug shows zoomout 
> effect in line 9 - 26. But the subscript [i] is now empty from line 20 - as I 
> continue to zoom out on the chart. Why?
> 
> Is this a bug or is there something I am missing?? 
> 
> Can anyone offer an explanation as to what is happening?
> 
> // Array or number ?
> dt = ParamDate("Date of the trend", "2009-05-25" ,0);
> i=0;
> i = ValueWhen(DateNum() == dt, BarIndex(), 1);
> 
> _TRACE(" i = " +  NumToStr(i, 1.0) + " index date = " + NumToStr(dt, 1.0) + " 
> Barcount = " + NumToStr(BarCount, 1.0) );
> 
> 00000000      0.00000000      [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 6,416       
> 00000001      0.03319501      [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 69  
> 00000002      2.32265329      [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 69  
> 00000003      7.29352045      [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 69  
> 00000004      12.29429150     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 69  
> 00000005      17.29241562     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 69  
> 00000006      22.29343414     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 69  
> 00000007      27.29189682     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 69  
> 00000008      32.29233551     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 69  
> 00000009      36.40725327     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 92  
> 00000010      36.77444458     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 127 
> 00000011      37.05470276     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 179 
> 00000012      37.29121780     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 179 
> 00000013      37.30448532     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 257 
> 00000014      37.54277802     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 374 
> 00000015      37.72683716     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 550 
> 00000016      37.91091156     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 814 
> 00000017      38.09486389     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 1,210       
> 00000018      38.33518219     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 1,804       
> 00000019      39.79113770     [2440]  i = 6,413 index date = 1,090,525 
> Barcount = 2,695       
> 00000020      40.27950287     [2440]  i = {EMPTY} index date = 1,090,525 
> Barcount = 4,031     
> 00000021      40.58501816     [2440]  i = {EMPTY} index date = 1,090,525 
> Barcount = 6,035     
> 00000022      40.80830765     [2440]  i = {EMPTY} index date = 1,090,525 
> Barcount = 6,416     
> 00000023      42.29502487     [2440]  i = {EMPTY} index date = 1,090,525 
> Barcount = 6,416     
> 00000024      47.29590988     [2440]  i = {EMPTY} index date = 1,090,525 
> Barcount = 6,416     
> 00000025      52.29293823     [2440]  i = {EMPTY} index date = 1,090,525 
> Barcount = 6,416     
> 00000026      57.29567719     [2440]  i = {EMPTY} index date = 1,090,525 
> Barcount = 6,416
>


Reply via email to