Sebastian,
Hi. A simple function might do the
trick. Below is a function that I created that you can try
out. Copy this into a text file and save it as some good sounding file
name. For example, “CrossHHV.afl”. Save it to the
“..\AmiBroker\Formulas\Systems\” folder. Contents of
CrossHHV.afl (before using include file) should look like:
function
CrossHHV()
{
RetValue
= Cross(Ref(HHV(C, 20), -1)*.95, C);
return
RetValue;
}
Sell = CrossHHV();
Filter = Sell;
AddColumn(HHV(C,
20), "HHV(H, 20)", 1.2);
AddColumn(Ref(HHV(C,
20), -1), "Ref(HHV(H, 20), -1)", 1.2);
AddColumn(Ref(HHV(C,
20), -1)*.95, "Ref(HHV(H, 20), -1)*.95", 1.2);
Open up the AA window, Pick “CrossHHV.afl”,
and click “Explore”. You will see all symbols that meet
that criteria.
Assuming that works, try using an include
file. An include file is nothing more than an AFL file that contains
custom functions and procedures that you create. Typically, you store it
in the folder “..\AmiBroker\Formulas\Include\”. To use
the functions, you would add to chart or exploration\backtest code: “#include”
+ file name. For example, if
your include file was named, “ABFunctions.afl, you would add this to your
charts, explorations, etc:
#include
<ABFunctions.afl>;
So, create a file called “ABFunctions.afl”
in the “..\AmiBroker\Formulas\Include\” folder. Now, move
ONLY the CrossHHV function code ONLY to the “ABFunctions.afl” file.
The contents of the “ABFunctions.afl” file should look like:
function
CrossHHV()
{
RetValue
= Cross(Ref(HHV(C, 20), -1)*.95, C);
return
RetValue;
}
Now make sure that the CrossHHV.afl file
has been modified. It should look like this (after using the include
file):
#include
<ABFunctions.afl>;
Sell = CrossHHV();
Filter = Sell;
AddColumn(HHV(C,
20), "HHV(H, 20)", 1.2);
AddColumn(Ref(HHV(C,
20), -1), "Ref(HHV(H, 20), -1)", 1.2);
AddColumn(Ref(HHV(C,
20), -1)*.95, "Ref(HHV(H, 20), -1)*.95", 1.2);
Now, when you execute the CrossHHV.afl
file, the code in the ABFunctions.afl will be “included” in the CrossHHV.afl
and you can execute the function. This is a convenient way of
reusing code.
I hope this helps.
Regards,
Dan.
From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of sebastiandanconia
Sent: Friday, November 25, 2005
2:59 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Re: How to
refer to a custom formula in a system test?
Dan, I'm not sufficiently
knowledgeable about this to know the
difference between a coded function and a complete
indicator, LOL!
In the custom indicator/index I created, I want to
be able to refer
to it in a system-test just as I would with RSI(),
MACD(),EMA(),
etc. As a specific example, I'd like to know
when the current index
value sells off by 5% from its 20-day HHV,
referring to it along the
line of this:
Sell=Cross(Ref(HHV("My Custom
Index",20),-1)*.95,"My Custom Index");
I didn't use AddtoComposite because I didn't think
it would give me
the weighting method I wanted (equal dollar
amounts in each security
instead of simply adding the stock price of each
security). (Maybe
I've got that wrong, too?)
I don't really "get" #include yet (like anyone
else, some concepts
come easy and some come hard). Is #include
what I should concentrate
on to get what I want, do you think?
Luck,
Sebastian
--- In amibroker@xxxxxxxxxxxxxxx,
"Dan Clark" <dan_public@xxxx> wrote:
>
> Sebastian,
>
>
>
> When you said ".when I created a custom
indicator, I could refer to
it and
> use it.", are you referring to a coded
function or a complete
indicator
> (like an MA)?
>
>
>
> If the former, you can create functions and
add them to an include
file.
> Then you would use "#Include" with
the file name in a chart of
> scan/exploration. For example, if
you stored your functions in
the file
> "ABFunctions.afl", this is text you
would add to the top of your
chart AFL
> to refer to the indicator:
>
>
>
> #include <ABFunctions.afl>
>
>
>
> If to the latter, you can create an
indicator, save it to an AFL
text file
> and then add it to a chart. Typically,
these custom indicator
files are
> saved to
".\Amibroker\Formulas\Custom\". They would then appear
in the
> "Charts\Custom" list ("View
--> Charts").
>
>
>
> Regards,
>
>
>
> Dan.
>
>
>
>
>
>
>
> _____
>
> From: amibroker@xxxxxxxxxxxxxxx
[mailto:amibroker@xxxxxxxxxxxxxxx]
On Behalf
> Of sebastiandanconia
> Sent: Friday, November 25, 2005 10:44 AM
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] How to refer to a custom
formula in a system
test?
>
>
>
> I created the index referred to in this post:
>
> http://finance.groups.yahoo.com/group/amibroker/message/90273
>
> ...as a custom indicator so that I could
refer to it in a system
> test. (AddtoComposite couldn't get me
where I wanted to go.) In my
> old Metastock software, when I created a
custom indicator I could
> simply refer to it and use it, but I haven't
found a way to do this
> with Amibroker. I did a search on the
Amibroker.com discussion
boards
> site and there have been inquiries about
this, but with no answers.
>
> Does this capability exist, or if not, is
there a relatively easy
> workaround? TIA.
>
>
> Luck to all,
>
> Sebastian
>
>
>
>
>
>
>
> Please note that this group is for discussion
between users only.
>
> To get support from AmiBroker please send an
e-mail directly to
> SUPPORT {at} amibroker.com
>
> For other support material please check also:
> http://www.amibroker.com/support.html
>
>
>
>
>
>
> _____
>
> YAHOO! GROUPS LINKS
>
>
>
> * Visit your
group "amibroker
> <http://groups.yahoo.com/group/amibroker>
" on the web.
>
> * To
unsubscribe from this group, send an email to:
> amibroker-unsubscribe@xxxxxxxxxxxxxxx
>
<mailto:amibroker-unsubscribe@xxxxxxxxxxxxxxx?subject=Unsubscribe>
>
> * Your use of
Yahoo! Groups is subject to the Yahoo!
> <http://docs.yahoo.com/info/terms/>
Terms of Service.
>
>
>
> _____
>
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For other support material please check also:
http://www.amibroker.com/support.html
SPONSORED LINKS
YAHOO! GROUPS LINKS