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

Inaccuray of calculated data with AFL code of AmiBroker



PureBytes Links

Trading Reference Links

Although AmiBroker has an extensive library of functions and indicators available, care should be taken when computing sophisticated formulas with AmiBroker:

Fairly recently, a member of this group - CS - provided me with the AFL code for the calculation of the TRIX Indicator. However, a comparison of the triple exponential functions using AmiBroker produced an inaccuracy as of the 5th digit to the right of the decimal point in comparison with the pre-programmed TRIX Indicator being in the AFL library!
Presumably, I think that the rationale this deviation derives from the factthat AmiBroker only utilizes floating-type numbers of the type name doubleinstead of long double to be absolutely required for such kind of computations.
In order to avoid those variations henceforth, maybe we should ask for having long double data types to achieve higher accuracies for tedious and cumbersome calculations?

For your convenience, I would like to encourage you to test this little code sample with TRIX(9), for example and compare your result in the AA window:

// Our data array uses the closing prices for the entire computation:
quote = close;

// The period is set to 9 just like the pre-programmed default value:
period = 9;

// Calculating the triple exponentially smoothed function:
y = EMA(EMA(EMA(quote, period), period), period);

// Finally, we calculate this indicator by virtue of AFL code:
TRX = 1000 * (y - Ref(y, -1)) / Ref(y, -1);

// We want to see all the data (stocks) in our current database:
filter = 1;

// Here are the calculates data in the listed columns of the AA window:
numColumns = 2;

column0 = TRX;
column1 = TRIX(9); // This is the pre-programmed TRIX Indicator having 9 bars as the default period!

column0Format = column1Format = 1.7;

column0Name = "TRX";
column1Name = "TRIX(9)";

// Displaying the computes results of this little program with the pre-programmed TRIX(9) Indicator:
maxGraph = 1;

graph0 = TRX;
graph0Name = "TRX";
graph0Color = 25; // We want to display the graph in light red color.
graph0Style = 1;

graphxSpace = 2;


Thank you for providing me with your comments in this matter!

Regards,

Udo


------=_NextPart_001_0020_01C1EC85.6476D740
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE id=ridTitle>Schlicht</TITLE><BASE 
href="file://C:\Programme\Gemeinsame Dateien\Microsoft Shared\Stationery\">
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<STYLE>BODY {
MARGIN-TOP: 25px; FONT-SIZE: 10pt; MARGIN-LEFT: 25px; COLOR: #000000; FONT-FAMILY: Arial, Helvetica
}
P.msoNormal {
MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-LEFT: 0px; COLOR: #ffffcc; FONT-FAMILY: Helvetica, "Times New Roman"
}
LI.msoNormal {
MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-LEFT: 0px; COLOR: #ffffcc; FONT-FAMILY: Helvetica, "Times New Roman"
}
</STYLE>

<META content="MSHTML 6.00.2715.400" name=GENERATOR></HEAD>
<BODY id=ridBody bgColor=#ffffff 
background=cid:001e01c1ec74$a0dd3e60$0100007f@x...>
<DIV><FONT face="Courier New"></FONT>&nbsp;</DIV>
<DIV>Hi,</DIV>
<DIV>&nbsp;</DIV>
<DIV>Although <EM>AmiBroker</EM> has an extensive library of functions and 
indicators available, care should be taken when computing sophisticated formulas 
with <EM>AmiBroker</EM>:</DIV>
<DIV>&nbsp;</DIV>
<DIV>Fairly recently, a member of this group - <EM>CS</EM>&nbsp;- provided me 
with the AFL code for the calculation of the <FONT color=#0000ff>TRIX</FONT> 
Indicator. However, a comparison of the triple exponential functions using 
AmiBroker produced an inaccuracy as of the 5th digit to the right of the decimal 
point in comparison with the pre-programmed <FONT color=#0000ff>TRIX</FONT> 
Indicator being in the AFL library!</DIV>
<DIV>Presumably, I think that the rationale this deviation derives from thefact 
that AmiBroker only utilizes floating-type numbers of the type name <FONT 
face=Verdana color=#0000ff>double</FONT> instead of <FONT face=Verdana 
color=#0000ff>long double</FONT> to be absolutely required for such kind of 
computations.</DIV>
<DIV>In order to avoid those variations henceforth, maybe we should ask for 
having <FONT face=Verdana color=#0000ff>long double</FONT> data types to achieve 
higher accuracies for&nbsp;tedious and cumbersome calculations?</DIV>
<DIV>&nbsp;</DIV>
<DIV>For your convenience, I would like to encourage you to test this little 
code sample with <FONT face=Verdana color=#0000ff>TRIX(9)</FONT>, for example 
and compare your result in the AA window:</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Verdana color=#000080 size=1>// Our data array uses the closing 
prices for the entire computation:</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1>quote&nbsp;= close;</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana color=#000080 size=1>// The period is set to 9 just like 
the pre-programmed default value:<BR>period&nbsp;= 9;</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana color=#000080 size=1>// Calculating the triple 
exponentially smoothed function:<BR>y = EMA(EMA(EMA(quote, period), period), 
period);</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana color=#000080 size=1>// Finally, we calculatethis 
indicator by virtue of AFL code:</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1>TRX = 1000 * (y - Ref(y, -1)) / 
Ref(y, -1);</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana color=#000080 size=1>// We want to see all the data 
(stocks) in our current database:</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1>filter = 1;</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana color=#000080 size=1>// Here are the calculates data in 
the listed columns of the AA window:</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1>numColumns = 2;</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana color=#000080 size=1>column0 = TRX;</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1>column1 = TRIX(9); // This is the 
pre-programmed TRIX Indicator having 9 bars as the default period!</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana color=#000080 size=1>column0Format = column1Format = 
1.7;</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana color=#000080 size=1>column0Name = "TRX";</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1>column1Name = 
"TRIX(9)";</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana color=#000080 size=1>// Displaying the computes results 
of this little program with the pre-programmed TRIX(9) Indicator:</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1>maxGraph = 1;</FONT></DIV>
<DIV><BR><FONT face=Verdana color=#000080 size=1>graph0 = TRX;</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1>graph0Name = "TRX";</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1>graph0Color = 25; // We want to 
display the graph in light red color.</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1>graph0Style = 1;</FONT></DIV>
<DIV><FONT face=Verdana color=#000080 size=1></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana color=#000080 size=1>graphxSpace = 2;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thank you for providing me with your comments in this matter!</DIV>
<DIV>&nbsp;</DIV>
<DIV>Regards,</DIV>
<DIV>&nbsp;</DIV>
<DIV>Udo</DIV>
<DIV>&nbsp;</DIV></BODY></HTML>

------=_NextPart_001_0020_01C1EC85.6476D740--

Attachment: Description: ""