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

[amibroker] Understanding _Trace output; first and last visible bars



PureBytes Links

Trading Reference Links

I am cutting my teeth on creating a custom price chart. I'm in 
reality creating an indicator to find certain fibonacci 
relationships, and draw lines and dots based on what it finds. Unless 
I'm missing something, if I use PlotShapes in an indicator, it only 
draws the shapes around prices in the same window. Since I don't want 
to modify the price indicator, I'm simply creating another one.

BTW, the first thing I set out to do was find the first and last 
visible bars. That code may come in handy for a few people. The gist 
of my question is understanding the debug output in the code below. 
First I paste the code, then the debug output. The calls to _Trace 
are just meant to show if my formulas for finding the first and last 
visible bars are working.

Question no #1: The output below was created by clicking "Apply" in 
the indicator builder window. In the output, you'll see three 
complete sets of the calls to the _Trace() function, with {EMPTY} 
showing for the date values in the first one. I'm gussing the {EMPTY} 
has to do with the use of Ref() in the second two statements, and 
that the -1 and +1 offsets yield invalid results on the very first 
pass through this indicator. This made me a little nervous -- and 
only a little -- why are there three calls, and could I ever wind up 
getting unexpected results if I were using the return value from one 
of those calls in other code vs. just printing it to debug?

Question no #2: I tried putting the 

//--Indicator-End--

comment above the calls to _Trace() to prevent AB from having to 
execute the code for every bar -- which it didn't anyway, apparently, 
since there were only the three calls to it. AB seems to be "smart" 
about how often it has to execute indicator code. However, is 
there "layman" use for "//--Indicator-End--" ?

THE CODE:

PlotOHLC(Open, High, Low, Close, "Custom price chart", colorBlack, 
styleCandle); 
GraphXSpace=10;

// -- Arbitrary code to test drawing of shapes in this indicator
PlotShapes(IIf(DayOfWeek()==1, shapeUpArrow, shapeNone), colorGreen, 
0, Low, Offset=-15);

// -- Let's calculate the first and last visible bars, and output
//    the results using _Trace()
_TRACE("The lowest low of the visible bars is: " +
WriteVal(LastValue( Lowest( IIf(Status("barvisible"), L, 99999))))); 

_TRACE("The first visible date is: " + WriteVal(ValueWhen(Status
("barvisible") AND NOT Ref(Status("barvisible"), -1), DateTime(), 1), 
formatDateTime ));

_TRACE("The last visible date is: " + 
WriteVal(
IIf(Status("barvisible") AND BarIndex()==LastValue(BarIndex()),
ValueWhen(BarIndex()==LastValue(BarIndex()), DateTime(), 1),
ValueWhen(Status("barvisible") AND NOT Ref(Status("barvisible"), 1), 
DateTime(), 1)), formatDateTime )
); 

Output (3 sets of calls):

[2360] The lowest low of the visible bars is: 99,999.000
[2360] The first visible date is: {EMPTY}
[2360] The last visible date is: {EMPTY}
[2360] The lowest low of the visible bars is:   31.370
[2360] The first visible date is: 5/14/2003
[2360] The last visible date is: 11/14/2003
[2360] The lowest low of the visible bars is:   31.370
[2360] The first visible date is: 5/14/2003
[2360] The last visible date is: 11/14/2003

Gordon



------------------------ 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/