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

[amibroker] Re: Bar index of last visible bar



PureBytes Links

Trading Reference Links

Yes, and I now have a clarification. If I place just the following 
code in an indiciator and click Apply:


aVisBars = Status("barvisible");
nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));
_TRACE(" - Before -");
_TRACE("Last visible bar: " + nLastVisBar);
_TRACE(" - After - ");


I will see the following debug output:

[3552]  - Before -
[3552] Last visible bar: 0
[3552]  - After - 
[3552]  - Before -
[3552] Last visible bar: 958
[3552]  - After - 
[3552]  - Before -
[3552] Last visible bar: 958
[3552]  - After - 
[3552] Last visible bar: 958

Notice that for the very first instance of output, the value is 0, 
and in subsequent outputs, it has the correct, non-zero value. This 
is all from one click of Apply on one chart from within the AFL 
editor. For whatever reason, the output makes it appear that the code 
is either initialized once and then executed three times, or just 
executed four times. I don't understand the multiple lines of output, 
but it does tell me why I perceive that my code has a bug. The 
variable is used in a loop -- and I get an array out of bounds error. 
Apparently I need to check the value before entering the loop so that 
when whatever initialization is being performed, etc., I don't get 
the error. 

Incidentally, if I scroll to another chart, I then see the following 
new lines in the trace output:

[3552] Last visible bar: 958
[3552] Last visible bar: 958
[3552]  - Before -
[3552] Last visible bar: 962
[3552]  - After - 
[3552]  - Before -
[3552] Last visible bar: 958
[3552]  - After - 
[3552] Last visible bar: 958

Note that after the first execution, which resulted from hitting 
apply and not from scrolling to a new chart -- is this the 
compilation of the code? -- nLastVisBar has the correct value right 
from the get go. There's not illusory 0 value that appears and then 
goes away. 

This may be more detail than most readers are interested in seeing, 
but it does explain the array out of bounds error. If TJ would like 
to shed any light on the trace output, that would be interesting and 
appreciated. Something I really find interesting are the sets of 
output that do not include the pure text output -- only the lines 
that involve a variable. So what represents the true, or official, 
execution of the indicator code? I don't know for sure, but I would 
gather it's the last instance of output.

Gordon
--- In amibroker@xxxxxxxxxxxxxxx, "William Peters" 
<williampeters@xxxx> wrote:
> Gordon,
> 
> This code plots the highest visible barindex. This is a zero based 
array so
> the last bar will be 1 less than the total number of quotes.
> 
> BV = Status("barvisible");
> HVBIndex = LastValue( Highest( ValueWhen(BV,BarIndex()) ), True  );
> Plot(HVBIndex ,"HVBIndex",1,styleLine);
> 
> Regards,
> William Peters
> www.amitools.com
> 
> -----Original Message-----
> From: Gordon [mailto:amibroker@x...]
> Sent: Monday December 8, 2003 3:56 PM
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] Bar index of last visible bar
> 
> 
> I'm writing an indicator. Searching the newsgroup archives, I found
> (posted 3/2/2003) what I thought was my answer to determining the 
bar
> index of the last visible bar:
> 
> "
> Tomasz posted this to the member section a while ago......
> 
> barvisible = Status("barvisible");
> r = RSI( 14 );
> maxr = LastValue( Highest( IIf( barvisible, r, 0 ) ) );
> "
> 
> So it would seem that:
> 
> aVisBars = Status("barvisible");
> nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));
> 
> should work, where nLastVisBar holds the barindex of the last 
visible
> bar. However, nLastVisBar always has a value of 0 when I access it 
in
> code. Also, the help says that Highest returns a NUMBER, but it 
seems
> to be an ARRAY. Without the use of the LastValue() function, I can't
> use nLastVisBar in an IF statement.
> 
> That way I initialize nLastVisBar, btw, is at the top of an
> indicator. The value is then used to control a for loop.
> 
> If anyone can see the error I must be missing, I would appreciate 
it.
> 
> Gordon
> 
> 
> 
> 
> Send BUG REPORTS to bugs@xxxx
> Send SUGGESTIONS to suggest@xxxx
> -----------------------------------------
> Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
> (Web page: http://groups.yahoo.com/group/amiquote/messages/)
> --------------------------------------------
> Check group FAQ at:
> http://groups.yahoo.com/group/amibroker/files/groupfaq.html
> 
> Your use of Yahoo! Groups is subject to 
http://docs.yahoo.com/info/terms/


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/