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

Re: [amibroker] Re: Code Question: buy best performing ticker of last 15 days



PureBytes Links

Trading Reference Links

hello Sam,
 
I am always happy to try to code an interesting idea. And your idea might be simple but it interesting and it works also. Like kar_avi suggests i also tried to code it more simple like:
 
Buy = DayOfWeek() == 5;
BuyPrice = C;
 
Sell = barssince(Buy) > 22 and DayOfWeek() == 5;
SellPrice = C;
 
but this does not work. I did not succeed using Barssince() to do the job (yet) therefor I use a loop inside a procedure to do it. Maybe someone else sees how to use barssince on this one.  It is not very hard to understand loops if you study it a little.
 
Your idea works. You can backtest my code on for instance on a stock list Nasdaq 100 and you will see it will give positive results. The results get even better if you divide your money in smaller portions like for instance:
 
SetBarsRequired(10000,10000);
SetOption("MaxOpenPositions", 10 );
PositionSize = -10;
SetTradeDelays(0,0,0,0);
 
However, since it is a long only system you will see that in a down market it will give bad results. So you can add additional constraints only to buy when the market is trending upwards, like:
 
Cf = Foreign("!COMP","C");
Buy = DayOfWeek() == 5 and Cf > MA(Cf,100);
 
Just adding some ideas. In an upmarket the system makes around 25% per year without slippage. But slippage for such a system will be very small to negligable and can easily be avoided. The idea needs to be fine tuned so it will make money in any market. Also 25% per year is too little in my opinion. Need systems > 60% before they get interesting in my opinion.
 
rgds, ed 
 
 
 
----- Original Message -----
Sent: Sunday, October 14, 2007 9:50 PM
Subject: [amibroker] Re: Code Question: buy best performing ticker of last 15 days

Ed,

Thanks so much for your help to the programming illiterate. I would
have never thought it's so complicated, just thought I miss
something really simple. Well, thanks even more.

Sam

--- In amibroker@xxxxxxxxxps.com, "Edward Pottasch" <empottasch@...>
wrote:
>
> hi
>
> I fabricated something that doesn't make use of the barssince
function since I didn't get it to work in a hurry. Code below does
the following:
>
> I calculates the positionScore on the close at a thursday then it
enters a trade at the open on a friday and closes this trade on the
open on a thrursday at least 22 bars after entry,
>
> (you will need the latest version of Amibroker for this because of
the break function).
>
> rgds, ed
>
>
>
> SetBarsRequired(10000,10000);
> SetOption("MaxOpenPositions", 1 );
> PositionSize = -100;
> SetTradeDelays(0,0,0,0);
> PositionScore = IIf( Ref(ROC(C,15),-1) > 0, Ref(ROC(C,15),-1), 0);
>
> procedure sell_proc(Buy,Sellday) {
>
> global Sell;
> global SellPrice;
> SellPrice = 0;
> Sell = 0;
>
> // sell delay in bars
> selldelay = 22;
>
> for (i = 1; i < BarCount; i++)
> {
>
> if (Buy[ i ])
> {
>
> for (j = i + selldelay; j < BarCount; j++)
> {
>
> if (Sellday[ j ])
> {
>
> Sell[ j ] = 1;
>
> i = j;
> break;
>
> }
>
> }
>
> }
>
> }
>
> }
>
>
> Buy = DayOfWeek() == 5;
> BuyPrice = O;
>
> sell_proc(Buy,DayOfWeek() == 4);
> SellPrice = O;
>
> SetChartOptions(0, chartShowDates);
> GraphXSpace = 5;
> Plot(C,"C",1,64);
>
> PlotShapes(IIf(Buy,shapeUpArrow,0),colorWhite, layer = 0,
yposition = BuyPrice, offset = 0 );
>
>
>
>
>
> ----- Original Message -----
> From: samu_trading
> To: amibroker@xxxxxxxxxps.com
> Sent: Sunday, October 14, 2007 7:44 AM
> Subject: [amibroker] Code Question: buy best performing ticker
of last 15 days
>
>
> How could I code this for backtesting in AB?
>
> Buy on Friday the ticker symbol with the best performance of the
last
> 15 trading days.
>
> Sell 5 weeks later
>
> Thanks, Samantha
>

__._,_.___

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 NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html





SPONSORED LINKS
Investment management software Investment property software Investment software
Investment tracking software Return on investment software

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___