PureBytes Links
Trading Reference Links
|
Mark,
youre right it is more complicated than it seems.
the formula below works the same as the backtester , but with the
allow same bar exit box "NOT TICKED".
you can run it as a backtest or exploration.
If running as a backtest keep the buy and sell delays in the ami
settings as zero, use the delays in the formula for both
exploration and backtest.
The date after the ticker name is actually the sell date,
if needed for excel, use the BUYDATE and SELLDATE columns as the
reference.
THE LONG HAS THE VALUE 111 IN THE longorshort column.
THE SHORT HAS THE VALUE 222 IN THE longorshort column.
All the imformation of the buy date sell date buyprice sellprice
are in the 1 row, Similar to a backtest.
start of code.
delayy=1;//buydelay,USUALLY SET AT 1 SO THE FILE EXPOTED WILL HAVE
//TOMMOROWS Buy AND Sell VALUES.
sdelayy=1;//selldelay,USUALLY SET AT 1 SO THE FILE EXPOTED WILL HAVE
//TOMMOROWS Buy AND Sell VALUES.
ShortDELAYY=1;//THE Short DELAY
CoverDELAYY=1;//THE CoverDELAY
Buyarray=O;//buyarray, SET AS OPEN IF THE OPEN IS THE ARRAY YOU PLAN
TO
//USE.
Sellarray=C;//sellarray, SET AS CLOSE IF THE CLOSE IS THE ARRAY YOU
//PLAN TO USE.
Shortarray=O;//SHORTARRAY, SET AS OPEN IF THE OPEN IS THE ARRAY YOU
//PLAN TO USE.
Coverarray=C;//COVERARRAY, SET AS CLOSE IF THE CLOSE IS THE ARRAY YOU
//PLAN TO USE.
//FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
//pLACE YOURE BUY SELL SHORT COVER CONDITIONS BETWEEN THE XXX'S
//THEY MUST END WITH THE BUY,SELL, SHORT COVER STATEMENTS.
//SAMPLE FORMULA e.g.
Buy=Cross(C,MA(C,50));
Sell=Cross(MA(C,50),C);
Short=Cross(BBandTop( buyARRAY,10,2),C);
Cover=Cross(L,BBandBot( buyARRAY,10,2));
//FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
//EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
//START OF expLORATION forMULA.
// DO NOT MODIFY FORMULA BETWEEN THE EEEE'S
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Buy=ExRemSpan(Buy ,delayy );
Buy=Ref( Buy,-delayy );
Sell= ExRemSpan(Sell,sdelayy );
Sell=Ref(Sell,-sdelayy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
Short=ExRemSpan(Short ,shortdelayy );
Short=Ref( Short,-shortdelayy );
Cover= ExRemSpan(Cover,coverdelayy );
Cover=Ref(Cover,-coverdelayy);
Buycum=Cum(Buy);
Buycond=IIf(Buy,ValueWhen(Buy,Buyarray,1),0);
Sellcond=IIf(Sell,ValueWhen(Sell,sellarray,1),0);
shortCum=Cum(Short);
Shortcond=IIf(Short,ValueWhen(Short,Shortarray,1),0);
covercond=IIf(Cover,ValueWhen(Cover,coverarray,1),0);
Buy=Buy ;
Sell=Sell AND Buycum>=0;
Short=Short;
Cover=Cover AND Shortcum>=0;
Equity(1);
Filter=Sell AND Buycum>=0 OR Cover AND Shortcum>=0;
AddColumn(IIf(Sell,111, IIf(
Cover,222,0)),"LONGORSHORT",1);
AddColumn(IIf(Sell,ValueWhen(Buy,Buycond,1), IIf(
Cover,ValueWhen(Short,Shortcond,1),0)),"BUYVALUE",1.4);
AddColumn(IIf(Sell,Sellcond, IIf(
Cover,Covercond,0)),"SELLVALUE",1.4);
AddColumn(IIf(Sell,ValueWhen(Buy,DateNum(),1), IIf(
Cover,ValueWhen(Short,DateNum(),1),0)),"BUYDATE",1);
AddColumn(IIf(Sell,ValueWhen(Sell,DateNum(),1), IIf(
Cover,ValueWhen(Cover,DateNum(),1),0)),"SELLDATE",1);
//EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
end of code.
Peter.
--- In amibroker@xxxxxxxxxxxxxxx, "MarkF2" <feierstein@xxxx> wrote:
> Anthony- Thanks, but for some reason WriteIf only returns the last
> value of the exploration as opposed to bar-by-bar values, so I'm
> trying to do this with numbers and then convert them to text once in
> Excel. I've found that this is more complicated than it originally
> seemed. For example, some asymmetric systems may have buy and sell
> signals that overlap for several bars, so it comes down to the order
> of the signals. I'm using all this as a reason to finally learn how
> to code loops. Thanks again for having a go at it.
>
> Mark
>
> --- In amibroker@xxxxxxxxxxxxxxx, "Anthony Faragasso" <ajf1111@xxxx>
> wrote:
> > Mark,
> >
> > Try this in AA....click explore
> >
> > //Sample trading system
> >
> > Buy=Cross(C,MA(C,28));
> > Sell=Cross(MA(C,28),C);
> >
> > /**********************************/
> > islong=Flip(Buy,Sell);
> > x=BarsSince(Buy);
> > y=BarsSince(Sell);
> > Filter=1;
> > AddTextColumn(WriteIf(islong,"LONG","SELL"),"CurrentPosition");
> > AddColumn(IIf(islong,x,y),"Bars");
> >
> > Anthony
> > -------Original Message-------
> >
> > From: amibroker@xxxxxxxxxxxxxxx
> > Date: Monday, May 12, 2003 10:25:52 AM
> > To: amibroker@xxxxxxxxxxxxxxx
> > Subject: [amibroker] Exploration Question
> >
> > Hi Everyone,
> >
> > Is there any way to add a column of text to an exploration that
> > indicates trade status? Specifically, I need to add a column that
> > specifies "Long" or "Short" (depending on which is the case)
beginning
> > with the bar of entry, through and including the bar before the
bar of
> > exit, then "Out" beginning with the exit bar and continuing for
all
> > bars the system's not in the market, etc. I understand I need to
use
> > Filter=1 to ensure no bars are missed. Thanks. Mark
> >
> >
> > 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.
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get A Free Psychic Reading! Your Online Answer To Life's Important Questions.
http://us.click.yahoo.com/Lj3uPC/Me7FAA/uetFAA/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/
|