PureBytes Links
Trading Reference Links
|
I am trying to translate something from TradeStation in order get get my head around the way Amibroker does things. It ain't helping that it is about 20 years ago since I last use C.
The following is a function in TradeStation:
{---------------------------------------------------}
{Gaussian Filter}
{Ported to EasyLanguage by: atavachron}
{Original author: DrKoch}
Inputs: Price(Numeric), Period(NumericSimple), poles(NumericSimple);
variables: aa(0), b(0), w(0), x(0), y(0), y1(0), y2(0), y3(0), y4(0),
a_1(0), a_12(0), a_13(0), a_14(0), a2(0), a3(0), a4(0), Pi(3.141592654),
sqrtOf2(1.414213562),count(0);
{If number of poles is < 0 or > 4 then return 0.}
{Number of filter poles must be between 1 and 4, inclusive}
If (poles >= 1) and (poles <= 4) then
begin
{initialization - performed only for first bar}
if Count = 0 then
begin
count = 1;
w = 2 * Pi / Period; {omega}
w = 180 * w / Pi; {in degrees}
b = (1 - cosine(w)) / (power(sqrtOf2, 2.0/poles) - 1.0);
aa = -b + squareroot(b*b + 2*b);
a_1 = 1.0 - aa;
a_12 = a_1 * a_1;
a_13 = a_1 * a_1 * a_1;
a_14 = a_12 * a_12;
a2 = aa * aa;
a3 = aa * aa * aa;
a4 = a2 * a2;
y1 = Price;
y2 = y1;
y3 = y2;
y4 = y3;
end; {end initialisation}
{main part}
{Calculate your indicator value here}
x = Price;
if (poles = 1) then
y = aa * x + a_1 * y1
else if (poles = 2) then
y = a2 * x + 2 * a_1 * y1 - a_12 * y2
else if (poles = 3) then
y = a3 * x + 3 * a_1 * y1 - 3 * a_12 * y2 + a_13 * y3
else if (poles = 4) then
y = a4 * x + 4 * a_1 * y1 - 6 * a_12 * y2 + 4 * a_13 * y3 - a_14 * y4;
y4 = y3; {delayed by four bars}
y3 = y2; {delayed by three bars}
y2 = y1; {delayed by two bars}
y1 = y; {delayed by one bar}
Gauss = y;
end
else
Gauss = 0.0;
{end main part}
Sofar I have come up with the following but am getting an error 29 and am stuck as to what I am doing wrong.
======>
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
function Gauss(input, Length, poles)
{
// no need to test if poles >= 1 and <= 4 since this is defined in the params
if (Count = 0)
// initialise
{
Count = 1;
Omega = 6.283185308 / Length;
// 6.283185308 = 2 * Pi, better to refer in this way than use a calculation
OmegaDegrees = 180 * Omega / 3.141592654;
b = (1 - cos(OmegaDegrees)) / (1.414213562^(2/poles) - 1);
aa = -b + sqrt( b*b + 2*b);
a_1 = 1 - aa;
a_12 = a_1 * a_1;
a_13 = a_1 * a_1 * a_1;
a_14 = a_12 * a_12;
a_2 = aa * aa;
a_3 = aa * aa * aa;
a_4 = a_2 * a_2;
y1 = input;
y2 = y1;
y3 = y2;
y4 = y3;
}
// end initialise
x = input;
// can use "if... else..." but often this finishes up in a logic error. I know this has extra processing but at least it is correct....
if (poles = 1) y = aa * x + a_1 * y1;
if (poles = 2) y = a2 * x + 2 * a_1 * y1 - a_12 * y2;
if (poles = 3) y = a3 * x + 3 * a_1 * y1 - 3 * a_12 * y2 + a_13 * y3;
if (poles = 4) y = a4 * x + 4 * a_1 * y1 - 6 * a_12 * y2 + 4 * a_13 * y3 - a_14 * y4;
y4 = y3;
y3 = y2;
y2 = y1;
y1 = y;
result = y;
return result;
}
_SECTION_BEGIN("Gaussian Average");
Length = Param("Length",18,2,400,1);
Poles = Param("Poles",2,1,4,1);
price = (H+L) * 0.5;
Plot(Gauss(price, 18, 2 ),"Gaussian Avg", colorRed);
_SECTION_END();
======<
Yes, I know I can just use EMA(EMA... etc but the above is an educational piece trying to work out some other logic I have to implement.
Many thanks in advance,
Marinus
------------------------------------
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|