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

AmiBroker Tips - Weekly Newsletter - Issue 06/2000


  • To: "AmiBroker Mailing List" <amibroker@xxxx>
  • Subject: AmiBroker Tips - Weekly Newsletter - Issue 06/2000
  • From: "Tomasz Janeczko" <tjaneczk@xxxx>
  • Date: 11 Dec 2000 18:09:56 -0000

PureBytes Links

Trading Reference Links

Issue 6/2000 AmiBroker Tips weekly newsletter.
Issue 6/2000.
Copyright (C)2000 Tomasz Janeczko. 
All back issues available from:
http://www.amibroker.com/newsletter/ 

IN THIS ISSUE
1 Welcome
2 AmiBroker 3.41 available
3 Tip of the week: How to write your own chart commentary
1 Welcome
Welcome to the 6th issue of AmiBroker Tips newsletter. 

This issue is a little bit shorter than usual because I was busy preparing a new version. The main topic of this issue is a tutorial on understanding sector and industry assignments.


By the way: Do you find this newsletter useful? Have any comments/suggestions or article ideas. Please don't hesitate to drop a line to newsletter@xxxxxxxxxxxxxx

2 AmiBroker 3.41 available
A new version (3.41) is available now for download from AmiBroker web site.There are two important issues connected with this release. First: all format definition files are now moved to \Formats subdirectory! If you have written your own files please move them to that directory. And the second thing - setup now includes new script for Sharenet downloader. It is installedby default along with proper Custom Tools item setup. I think that all Sharenet customers will welcome this feature. 

Among other new features worthe mentioning are: Automatic analysis, Indicator Builder and Commentary windows are now resizable (see the sizing gripperin the bottom right corner of these dialogs) and could be also minimized; ASCII importer now warns that errors occurred during import process and displays the log on your request; "Rename" button added to Indicator Builder window for easier change of custom indicator names.

Also completely new setup has much better look&feel and is now self-extracting so you won't need unzipping tool anymore. 

3 Tip of the week: How to write your own chart commentary

One of the interesting aspects of using AmiBroker Formula Language is writing automatic chart commentaries. The idea behind this technique is as follows: 

1.. You write the commentary formula that consists of two basic elements:static texts and AFL expressions
2.. AmiBroker evaluates expressions using currently selected stock data and generates dynamic content
3.. The mixture of static text and evaluated formulas are displayed in commentary output window
4.. Additionally buy/sell arrows are plotted on the chart
Commentaries are available from Analysis->Commentary menu. When you open commentary window you will see two tabs: Commentary and Formula. In the Formula tab you can type the AFL statements which will be evaluated by AmiBrokerresulting in dynamic commentary that appears in Commentary tab. The following sections will guide you through the steps needed to write your very owncommentary formulas.

3.1 Writing static texts 

Static text elements written in the formula should be enclosed in the quotation marks and terminated by semicolon sign as shown below:

"This is sample static text statement";

You can write several statements and each statement will be placed in a newline in the commentary output window:

"This is first line of text";
"This is second line of text";

Please type these examples into edit field in the Formula tab and switch toCommentary tab. You will see the texts displayed in the output area but without any quotation marks or semicolons. This is because AmiBroker has evaluated this simple text statements into strings and it displayed the stringsin the output window. 

To write several lines of text you can use a couple of statements as shown above or you can do this using single statement and line break sequence ('\n'):

"This is first line of text\nThis is second line of text\nThis is third line of text";

You can also concatenate the string constants which will result in single line text:

"This" +
" is" +
" single"+
" line" + " of text";

I guess that you are quite bored with these simple examples, let's start with some dynamic content.

3.2 Dynamic content

To enable dynamic commentaries AFL has a couple of special functions available, but two of them are the most important: WriteVal() and WriteIF(). WriteIF() function is used for conditional text display and will be described later in this article, now let us see what we can do using WriteVal() function. 

The AFL reference manual says:

SYNTAX writeval( NUMBER );
writeval( ARRAY ); 
RETURNS STRING 
FUNCTION This function can only be used within an Guru commentary. It is used to display the numeric value of NUMBER or ARRAY. 

So, if you want to display a value of a number or currently selected bar ofthe array you should use writeval() function. But... wait a minute - what does it mean "currently selected bar of the array"? Let me explain this using simple formula (please type it in the Formula tab):

writeval( close );

When you switch to Commentary tab you will see the value of closing price (the same one which is displayed at the top of main price chart). But when you click on the chart in another place, selecting different date and then you click "Refresh" button you will see different value - the closing price at day you have selected. So writeval( close ) function displays the value of currently selected bar of close array. And it works exactly the same waywith other arrays. If you write

writeval( macd() );

you will see the exact value of MACD indicator at the day you have selectedin the main chart. Having our current know-how we are able to write some statistics:

"Closing price = " + WriteVal( close );
"Change since yesterday = " + WriteVal( close - ref( close, -1 ) );
"Percent chg. since yesterday = " + WriteVal( roc( close, 1 ) ) + " %";
"MACD =" + WriteVal( macd() ) + " , Signal line =" + WriteVal( signal() );

When you switch to Commentary tab you will see output similiar to this one:

Closing price = 17.940
Change since yesterday = -0.180
Percent chg. since yesterday = -0.993 %
MACD = -0.001 , Signal line = 0.063

Quite nice, isn't it? You can also write current stock ticker and selected date using name() and date() functions as shown below:

"Statistics of " + name() + " as of " + date();

But what we miss here is an ability to write something if some condition ismet and write something different otherwise...

3.3 Conditional text output

AFL is equipped with very nice function called WriteIF() that can output different texts depending on the condition. Let us look what documentation says:

SYNTAX writeif( EXPRESSION, "TRUE TEXT", "FALSE TEXT" ) 
RETURNS STRING 
FUNCTION This function can only be used within an Guru commentary. If EXPRESSION evaluates to "true", then the TRUE TEXT string is displayed within the commentary. If EXPRESSION evaluates to "false", then the FALSE TEXT string is displayed. 

So we can easily output different text depending on expession, for example:

writeif( macd() > signal(), "The MACD is bullish because is is above it'ssignal line", "The MACD is bearish because it is below its signal line" );

You can also combine several WriteIf() function calls in order to handle more possibilities:

"The current market condition for "+ name() + " is: ";

avgcond1 = ( c > ema( close, 200) ) + 0.1 * ( close > ema( close, 90) )+ 0.1 * ( close > ema( close , 30 ) );
avgcond2 = -( c < ema( close, 200) ) - 0.1 * ( close < ema( close, 90) ) - 0.1 * ( close < ema( close , 30 ) );

WriteIf( avgcond1 == 1.2,
"Very Bullish",
WriteIf( avgcond1 == 1.1,
"Bullish",
WriteIf( avgcond1 == 1.0,
"Mildly Bullish", "") ) ) +

WriteIf( avgcond2 == -1.2,
"Very Bearish",
WriteIf( avgcond2 == -1.1,
"Bearish",
WriteIf( avgcond2 == -1.0,
"Mildly Bearish", "") ) );

The formula above will return the text "The current market condition for {your ticker here} is: Very Bullish" if 30 day average is above 90 day average and 90 day average is above 200 day average. In other cases the formula will give you Bullish, Mildly Bullish, Mildly Bearish, Bearish or Very Bearish ratings.

For more examples on AFL commentaries please check AFL formula library especially MACD commentary formula which demonstrates all techniques presented here.

Now you are ready to start with your own commentaries... Good luck! 

.... and that's all for this week - hope you enjoyed reading 


--------------------------------------------------------------------------------

AmiBroker Tips weekly newsletter. Issue 6/2000. Copyright (C)2000 Tomasz Janeczko. All back issues available from: http://www.amibroker.com/newsletter/

 


------=_NextPart_001_000F_01C063A5.DC848580
Content-Type: text/html;
charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-2" http-equiv=Content-Type>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV>
<TABLE border=0 cellPadding=0 cellSpacing=0 width="100%">
<TBODY>
<TR>
<TD>
<DIV align=center><B><IMG alt="" border=0 hspace=0 
src="cid:000d01c0639d$7a9e8bc0$a31aa0d4@xxxx";><BR>Issue 6/2000</B></DIV></TD>
<TD width="15%"><FONT size=-2>AmiBroker Tips weekly newsletter.<BR>Issue 
6/2000.<BR>Copyright&nbsp;(C)2000&nbsp;Tomasz&nbsp;Janeczko. <BR>All back 
issues available from:<BR><A 
href="http://www.amibroker.com/newsletter/";>http://www.amibroker.com/newsletter/</A></FONT></TD></TR></TBODY></TABLE>
<H5>IN THIS ISSUE</H5>
<H5>1 Welcome<BR>2 AmiBroker 3.41 available<BR>3 Tip of the week: How to write 
your own chart commentary</H5>
<H5>1 Welcome</H5>
<P>Welcome to the 6th issue of AmiBroker Tips newsletter. </P>
<P>This issue is a little bit shorter than usual because I was busy preparing a 
new version. The main topic of this issue is a tutorial on understanding sector 
and industry assignments.<BR></P>
<P>By the way: Do you find this newsletter useful? Have any comments/suggestions 
or article ideas. Please don't hesitate to drop a line to <A 
href="mailto:newsletter@xxxx";>newsletter@xxxx</A></P>
<H5>2 AmiBroker 3.41 available</H5>
<P>A new version (3.41) is available now for download from AmiBroker web site. 
There are two important issues connected with this release. First: all format 
definition files are now moved to \Formats subdirectory! If you have written 
your own files please move them to that directory. And the second thing - setup 
now includes new script for Sharenet downloader. It is installed by default 
along with proper Custom Tools item setup. I think that all <A 
href="http://www.sharenet.co.za/amibroker";>Sharenet</A> customers will welcome 
this feature. </P>
<P>Among other new features worthe mentioning are: Automatic analysis, Indicator 
Builder and Commentary windows are now resizable (see the sizing gripper inthe 
bottom right corner of these dialogs) and could be also minimized; ASCII 
importer now warns that errors occurred during import process and displays the 
log on your request; "Rename" button added to Indicator Builder window for 
easier change of custom indicator names.</P>
<P>Also completely new setup has much better look&amp;feel and is now 
self-extracting so you won't need unzipping tool anymore. </P>
<P><B>3 Tip of the week: How to write your own chart commentary</B></P>
<P>One of the interesting aspects of using AmiBroker Formula Language is writing 
automatic chart commentaries. The idea behind this technique is as follows:</P>
<OL>
<LI>You write the commentary formula that consists of two basic elements: 
static texts and AFL expressions</LI>
<LI>AmiBroker evaluates expressions using currently selected stock data and 
generates dynamic content</LI>
<LI>The mixture of static text and evaluated formulas are displayed in 
commentary output window</LI>
<LI>Additionally buy/sell arrows are plotted on the chart</LI></OL>
<P>Commentaries are available from <I>Analysis-&gt;Commentary</I> menu. When you 
open commentary window you will see two tabs: <I>Commentary </I>and<I> Formula. 
</I>In the <I>Formula</I> tab you can type the AFL statements which will be 
evaluated by AmiBroker resulting in dynamic commentary that appears in 
<I>Commentary</I> tab. The following sections will guide you through the steps 
needed to write your very own commentary formulas.</P>
<P>3.1 Writing static texts </P>
<P>Static text elements written in the formula should be enclosed in the 
quotation marks and terminated by semicolon sign as shown below:</P>
<BLOCKQUOTE>
<P><CODE>"This is sample static text statement";</CODE></P></BLOCKQUOTE>
<P>You can write several statements and each statement will be placed in a new 
line in the commentary output window:</P>
<BLOCKQUOTE>
<P><CODE>"This is first line of text";<BR>"This is second line of 
text";</CODE></P></BLOCKQUOTE>
<P>Please type these examples into edit field in the <I>Formula</I> tab and 
switch to <I>Commentary</I> tab. You will see the texts displayed in the output 
area but without any quotation marks or semicolons. This is because AmiBroker 
has evaluated this simple text statements into strings and it displayed the 
strings in the output window. </P>
<P>To write several lines of text you can use a couple of statements as shown 
above or you can do this using single statement and line break sequence 
('\n'):</P>
<BLOCKQUOTE>
<P><CODE>"This is first line of text\nThis is second line of text\nThis is 
third line of text";</CODE></P></BLOCKQUOTE>
<P>You can also concatenate the string constants which will result in single 
line text:</P>
<BLOCKQUOTE>
<P><CODE>"This" +<BR>" is" +<BR>" single"+<BR>" line" + " of 
text";</CODE></P></BLOCKQUOTE>
<P>I guess that you are quite bored with these simple examples, let's startwith 
some dynamic content.</P>
<P>3.2 Dynamic content</P>
<P>To enable dynamic commentaries AFL has a couple of special functions 
available, but two of them are the most important: WriteVal() and WriteIF(). 
WriteIF() function is used for conditional text display and will be described 
later in this article, now let us see what we can do using WriteVal() function. 
</P>
<P>The AFL reference manual says:</P>
<TABLE border=0 width="90%">
<TBODY>
<TR>
<TD width="20%"><B>SYNTAX </B></TD>
<TD width="80%">writeval( NUMBER );<BR>writeval( ARRAY );</TD></TR>
<TR>
<TD><B>RETURNS</B></TD>
<TD>STRING</TD></TR>
<TR>
<TD vAlign=top><B>FUNCTION </B></TD>
<TD width="80%">This function can only be used within an Guru commentary. 
It is used to display the numeric value of NUMBER or 
ARRAY.</TD></TR></TBODY></TABLE>
<P>So, if you want to display a value of a number or currently selected barof 
the array you should use writeval() function. But... wait a minute - what does 
it mean "currently selected bar of the array"? Let me explain this using simple 
formula (please type it in the <I>Formula</I> tab):</P>
<BLOCKQUOTE>
<P><CODE>writeval( close );</CODE></P></BLOCKQUOTE>
<P>When you switch to <I>Commentary</I> tab you will see the value of closing 
price (the same one which is displayed at the top of main price chart). Butwhen 
you click on the chart in another place, selecting different date and then you 
click "Refresh" button you will see different value - the closing price at day 
you have selected. So writeval( close ) function displays the value of currently 
selected bar of close array. And it works exactly the same way with other 
arrays. If you write</P>
<BLOCKQUOTE>
<P><CODE>writeval( macd() );</CODE></P></BLOCKQUOTE>
<P>you will see the exact value of MACD indicator at the day you have selected 
in the main chart. Having our current know-how we are able to write some 
statistics:</P>
<BLOCKQUOTE>
<P><CODE>"Closing price = " + WriteVal( close );<BR>"Change since yesterday = 
" + WriteVal( close - ref( close, -1 ) );<BR>"Percent chg. since yesterday = " 
+ WriteVal( roc( close, 1 ) ) + " %";<BR>"MACD =" + WriteVal( macd() ) + " , 
Signal line =" + WriteVal( signal() );</CODE></P></BLOCKQUOTE>
<P>When you switch to <I>Commentary</I> tab you will see output similiar tothis 
one:</P>
<BLOCKQUOTE>
<P>Closing price = 17.940<BR>Change since yesterday = -0.180<BR>Percent chg. 
since yesterday = -0.993 %<BR>MACD = -0.001 , Signal line = 
0.063</P></BLOCKQUOTE>
<P>Quite nice, isn't it? You can also write current stock ticker and selected 
date using name() and date() functions as shown below:</P>
<BLOCKQUOTE>
<P><CODE>"Statistics of " + name() + " as of " + date();</CODE></P></BLOCKQUOTE>
<P>But what we miss here is an ability to write something if some conditionis 
met and write something different otherwise...</P>
<P>3.3 Conditional text output</P>
<P>AFL is equipped with very nice function called WriteIF() that can output 
different texts depending on the condition. Let us look what documentation 
says:</P>
<TABLE border=0 width="90%">
<TBODY>
<TR>
<TD width="20%"><B>SYNTAX </B></TD>
<TD width="80%">writeif( EXPRESSION, "TRUE TEXT", "FALSE TEXT" )</TD></TR>
<TR>
<TD><B>RETURNS</B></TD>
<TD>STRING</TD></TR>
<TR>
<TD vAlign=top><B>FUNCTION </B></TD>
<TD width="80%">This function can only be used within an Guru commentary. 
If EXPRESSION evaluates to "true", then the TRUE TEXT string is displayed 
within the commentary. If EXPRESSION evaluates to "false", then the FALSE 
TEXT string is displayed.</TD></TR></TBODY></TABLE>
<P>So we can easily output different text depending on expession, for 
example:</P>
<BLOCKQUOTE>
<P><CODE>writeif( macd() &gt; signal(), "The MACD is bullish because is is 
above it's signal line", "The MACD is bearish because it is below its signal 
line" );</CODE></P></BLOCKQUOTE>
<P>You can also combine several WriteIf() function calls in order to handlemore 
possibilities:</P>
<BLOCKQUOTE>
<P><CODE>"The current market condition for "+ name() + " is: ";</CODE></P>
<P><CODE>avgcond1 = ( c &gt; ema( close, 200) ) + 0.1 * ( close &gt; ema( 
close, 90) ) + 0.1 * ( close &gt; ema( close , 30 ) );<BR>avgcond2 = -(c &lt; 
ema( close, 200) ) - 0.1 * ( close &lt; ema( close, 90) ) - 0.1 * ( close&lt; 
ema( close , 30 ) );</CODE></P>
<P><CODE>WriteIf( avgcond1 == 1.2,<BR>"Very Bullish",<BR>WriteIf( avgcond1 == 
1.1,<BR>"Bullish",<BR>WriteIf( avgcond1 == 1.0,<BR>"Mildly Bullish", "") ) ) 
+</CODE></P>
<P><CODE>WriteIf( avgcond2 == -1.2,<BR>"Very Bearish",<BR>WriteIf( avgcond2 == 
-1.1,<BR>"Bearish",<BR>WriteIf( avgcond2 == -1.0,<BR>"Mildly Bearish", "") ) 
);</CODE></P></BLOCKQUOTE>
<P>The formula above will return the text "The current market condition for 
{your ticker here} is: Very Bullish" if 30 day average is above 90 day average 
and 90 day average is above 200 day average. In other cases the formula will 
give you Bullish, Mildly Bullish, Mildly Bearish, Bearish or Very Bearish 
ratings.</P>
<P>For more examples on AFL commentaries please check <A 
href="http://www.amibroker.com/library.html";>AFL formula library</A> especially 
MACD commentary formula 
which demonstrates all techniques presented here.</P>
<P>Now you are ready to start with your own commentaries... Good luck! </P>
<P><I>.... and that's all for this week - hope you enjoyed reading</I> </P>
<HR>

<P><FONT size=-2>AmiBroker Tips weekly newsletter. Issue 6/2000. 
Copyright&nbsp;(C)2000&nbsp;Tomasz&nbsp;Janeczko. All back issues available 
from: <A 
href="http://www.amibroker.com/newsletter/";>http://www.amibroker.com/newsletter/</A></FONT></P>
<P> </P></DIV><FONT face=Tahoma></FONT><FONT size=1></FONT></BODY></HTML>

------=_NextPart_001_000F_01C063A5.DC848580--

Attachment: Description: ""