PureBytes Links
Trading Reference Links
|
bz=Cross(EMA(C,5),MA(C,20));
sz=Cross(MA(C,20),EMA(C,5));
Buy=bz AND Year()==1998;
Short = sz AND Year() == 1998 AND DateNum() < 981231;
Sell=sz OR DateNum() == 981231;
Cover=bz OR DateNum() == 981231;
--- In amibroker@xxxxxxxxxxxxxxx, "Keith Bennett" <kbennett@xxxx>
wrote:
> Hi,
>
> I appreciate all the helpful suggestions but I still don't have a
> solution to this - what appeared to be - a simple problem. I am
> puzzled as to why I am not able to do in code what I can do
perfectly
> well using the AA RAnge Control.
>
> I am using the Optimize function and the setting No Trade List to
> scan through a number of years. This displays the % gain/loss for
> each individual year in the backtest and this is why I need to do
> this in code rather than use the Range Control.
>
> The following afl is for illustrative purposes only:
>
> bz=Cross(EMA(C,5),MA(C,20));
> sz=Cross(MA(C,20),EMA(C,5));
> Buy=bz; Sell=sz;
> Short=Sell; Cover=Buy;
>
> Using QQQ and setting the Range Control from 1/1/1998 to 12/31/1998
> generates 20 trades, the last one of which shows an exit date of
> 12/31/98 for the open trade, and the gain is correctly calculated
for
> 1998 only.
>
> The following is my attempt to duplicate the action of the Range
> Control in code:
>
> bz=Cross(EMA(C,5),MA(C,20));
> sz=Cross(MA(C,20),EMA(C,5));
> Buy=bz AND Year()==1998;
> Sell=sz AND Year()==1998;
> Short=Sell; Cover=Buy;
>
> Running this code with All Quotations selected for the range
displays
> the same 20 trades, but the last open trade has the exit date
> 5/23/2003 and the % Gain/Loss for 1998 is no longer shown correctly.
>
> My code is clearly incorrect, but how should this be coded so that
> it produces then same result as the Range Control.
>
> Keith
>
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "Bob Jagow" <bjagow@xxxx> wrote:
> > Keith,
> > I don't see a problem with Sell=Cond AND Year()==1998 giving
(Open
> Long) 10/23/98 to 5/23/03.
> >
> > Cond was clearly not met per your range result [(Open Long)
> 10/23/98 to 12/31/98].
> >
> > If you don't close open positions via range, you will need an
> additional sell statement.
> > I'd try Sell = dateNum() > 981231;
> >
> >
> > Bob
> >
> >
> >
> > -----Original Message-----
> > From: Keith Bennett [mailto:kbennett@x...]
> > Sent: Sunday, May 25, 2003 9:05 AM
> > To: amibroker@xxxxxxxxxxxxxxx
> > Subject: [amibroker] Re: Date range problem....
> >
> >
> > Mike: No luck with that either. Also tried to use Datenum but
that
> > doesn't work either.
> >
> > What I am trying to backtest are Buys and Sells, but only if they
> > occur (for example) in 1998.
> >
> > This is achieved without problem using the range control, but I
> can't
> > get it to work using a date function in the afl.
> >
> > Keith
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, walt <WSCHWARZ@xxxx> wrote:
> > > Kieth,
> > >
> > > In general if you refer to a date (without time) it assumes
time
> of
> > 12 am.
> > >
> > > Try to use 1/1/99...
> > >
> > > Walt
> > > -----Original Message-----
> > > From: Keith Bennett [mailto:kbennett@x...]
> > > Sent: Sunday, May 25, 2003 6:50 AM
> > > To: amibroker@xxxxxxxxxxxxxxx
> > > Subject: [amibroker] Re: Date range problem....
> > >
> > >
> > > Thanks Mike, but that doesn't do the trick.
> > >
> > > Keith
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "Mike Lucero"
<m.lucero@xxxx>
> > wrote:
> > > > I'm not sure of the syntax, but you want your sell
condition
> to
> > be
> > > >
> > > > Sell=Cond OR Date=12/31/98
> > > > ----- Original Message -----
> > > > From: "Keith Bennett" <kbennett@xxxx>
> > > > To: <amibroker@xxxxxxxxxxxxxxx>
> > > > Sent: Sunday, May 25, 2003 2:14 AM
> > > > Subject: [amibroker] Date range problem....
> > > >
> > > >
> > > > Can anyone see my error:
> > > >
> > > > I set the range in AA to 1/1/1998 to 12/31/1998.
> > > >
> > > > Buy = Cond;Sell = Cond;
> > > > Short = Sell;Cover = Buy;
> > > >
> > > > This correctly produces 13 trades. The first is 1/2/98 to
> > 1/8/98 and
> > > > the last is (Open Long) 10/23/98 to 12/31/98. No problem.
> > > >
> > > > I set the range in AA to All Quotations:
> > > >
> > > > Buy=Cond AND Year()==1998;
> > > > Sell=Cond and Year()==1998;
> > > > Short=Sell;Cover=Buy;
> > > >
> > > > The first trade is still 1/2/98 but the last is (Open Long)
> > 10/23/98
> > > > to 5/23/03 and for this reason % profit is not correct for
> 1998.
> > > >
> > > > How do I get the afl to respect the Year() function after
the
> > Sell
> > > > statement?
> > > >
> > > > Keith
> > > >
> > > >
> > > >
> > > > Send BUG REPORTS to bugs@xxxx
> > > > Send SUGGESTIONS to suggest@xxxx
> > > > -----------------------------------------
> > > > 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/
> > >
> > >
> > > Yahoo! Groups Sponsor
> > >
> > >
> > >
> > > Send BUG REPORTS to bugs@xxxx
> > > Send SUGGESTIONS to suggest@xxxx
> > > -----------------------------------------
> > > 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 the Yahoo! Terms of
> > Service.
> >
> >
> >
> > Send BUG REPORTS to bugs@xxxx
> > Send SUGGESTIONS to suggest@xxxx
> > -----------------------------------------
> > 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/
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get A Free Psychic Reading! Your Online Answer To Life's Important Questions.
http://us.click.yahoo.com/Lj3uPC/Me7FAA/CNxFAA/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/
|