hi
just search for Graham kavanagh
adjust parameters as needed
//------------------------------------------------------------------------------
//
// Formula Name: AFL Example
// Author/Uploader: Graham Kavanagh
// E-mail: gkavanagh@xxxxxxxxxxxxx
// Date/Time Added: 2005-08-12 03:45:59
// Origin:
// Keywords: AFL Example
// Level: basic
// Flags: exploration,indicator
// Formula URL: http://www.amibroker.com/library/formula.php?id=545
// Details URL: http://www.amibroker.com/library/detail.php?id=545
//
//------------------------------------------------------------------------------
//
// There are many questions from beginners. I have tried to create a sample
// system that incorporates basic and useful items.
//
// This is an AFL for Chart, Scan, Backtest and Explore
//
// The system for Buy/Sell is just off the top of the head as an example only.
//
//------------------------------------------------------------------------------
_SECTION_BEGIN("AFL Example");
/*
This is an attempt to provide a basic trading system AFL. The system is purely imaginary
AND NOT provided as one that would make money. This is just to provide a guide to learners
on the common components of writing AFL.
Prepared by Graham Kavanagh 12 Aug 2005
AB Write http://e-wire.net.au/~eb_kavan/ab_write.htm
When you copy/paste ensure the existing continuous lines have not been wrapped. This wrapping
can create error signals when you try to use the code. Click on the check afl button in the
editor before trying to apply or scan.
I have used slash-asterisk /* */ /* for my comments to get around the problem of wrapping,
which could happen if you used double slash //
I hope this helps the beginners in creating AFL code
*/
/*firstly some basics common*/
SetBarsRequired(10000,10000); /* this ensures that the charts include all bars AND NOT just those on screen */
SetFormulaName("Sample System"); /*name it for backtest report identification */
SetTradeDelays( 1, 1, 1, 1 ); /* delay entry/exit by one bar */
SetOption( "initialequity", 100000 ); /* starting capital */
PositionSize = -10; /* trade size will be 10% of available equty */
SetOption( "MaxOpenPositions", 6 ); /* I don't want to comit more than 60% of Equity at any one time */
SetOption( "PriceBoundChecking", 1 ); /* trade only within the chart bar's price range */
SetOption( "CommissionMode", 2 ); /* set commissions AND costs as $ per trade */
SetOption( "CommissionAmount", 32.95 ); /* commissions AND cost */
SetOption( "UsePrevBarEquityForPosSizing", 1 ); /*set the use of last bars equity for trade size*/
PositionScore = 100/C; /*Set the order for which stock trades when get mulitple signals in one bar in backtesting */
//Trade system
/*
Buy when exp mov avg crosses and the high is highest for 50 bars
Sell when exp mov avg crosses back
Cross is first variable moves to above the second variable
*/
LongPer = Param("Long Period", 65, 30, 100, 5 ); /* select periods with parameter window */
ShortPer = Param("Short Period", 20, 3, 30, 1 );
LongMA = EMA( C, LongPer );
ShortMA = EMA( C, ShortPer );
LastHigh = HHV( H, LongPer );
LastLow =LLV(L,ShortPer);
Buy = Cross( ShortMA, LongMA ) AND H > Ref( LastHigh, -1 );
/* ref,-1 is used for the high to have todays high greater than the previous 50 bar high.
To just use H==LastHigh couold mean a previous high was equal to current high */
Sell = Cross( LongMA, ShortMA );
/* exrem is one method to remove surplus strade signals*/
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
/* Now for exploration results.
Will restrict results of exploration to when the Buy AND Sell signals occur
You can use Filter=1; to display every bar result */
Filter = Buy OR Sell;
AddTextColumn( FullName(), "Company Name" );
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );
AddColumn( C, "Close", 1.3 );
AddColumn( H, "High", 1.3 );
AddColumn( LastHigh, "HHV", 1.3 );
AddColumn( LongMA, "Long MA", 1,3 );
AddColumn( ShortMA, "Short MA", 1,3 );
/* Now to show this on a chart */
/* I use WriteVal to limit the values to the wanted number of decimal places,
seeing a value of 5 decimal places can be frustrating.
I have included additional information in the plot title sections to add some
information to the title block */
GraphXSpace = 10; /* create empty space of 10% top and bottom of chart */
Plot( C, " Close Price", colorGrey50, styleBar );
Plot( LongMA, " EMA(C,"+WriteVal(LongPer,1)+")", colorRed, styleLine|styleNoRescale );
Plot( ShortMA, " EMA(C,"+WriteVal(ShortPer,1)+")", colorGreen, styleLine|styleNoRescale );
Plot( Ref(Lasthigh,-1), " HHV(H,"+WriteVal(LongPer,1)+")", colorBlue, styleNoLine|styleDots|styleNoRescale );
Plot( Ref(LastLow,-1), " LLV(L,"+WriteVal(LongPer,1)+")", colorRed, styleNoLine|styleDots|styleNoRescale );
/* styleNoRescale in the plots stops the added plots from compressing the original bar chart to the middle of the pane */
PlotShapes( shapeUpArrow*Buy, colorGreen, 0, L, -10 );
PlotShapes( shapeDownArrow*Sell, colorRed, 0, H, -10 );
Title = " {{NAME}} {{DATE}} {{INTERVAL}} "+_DEFAULT_NAME()+" Chart values : {{VALUES}} ";
/* _DEFAULT_NAME() shows the section name or, if not present, the file name
the items in {{}} are short cuts for the title block. It can be done long hand
Title = Name() +" "+ Date() +" "+ "{{INTERVAL}}"+_DEFAULT_NAME()+" Chart values : " +
" Close Price = " + C +
" EMA(C,"+WriteVal(LongPer,1)+") = "+WriteVal(LongMA,1.3) +
" EMA(C,"+WriteVal(ShortPer,1)+") = "+WriteVal(ShortMA,1.3) +
" HHV(H,"+WriteVal(LongPer,1)+") = "+WriteVal(Ref(LastHigh,-1),1.3) ;
*/
_SECTION_END();
--- On Mon, 11/9/09, original_nightstalker <nightstalker@xxxxxxxxxxx> wrote:
From: original_nightstalker <nightstalker@xxxxxxxxxxx> Subject: [amibroker] Re: Turtle Trading rules for AmiBroker To: amibroker@xxxxxxxxxxxxxxx Date: Monday, November 9, 2009, 1:59 AM
Thanks for the reply :) If it's the Graham I remember from here (?kaveman?) then the code would be very good. Any pointers as to where I may find it? I've tried searching the AmiBroker AFL Library with no success. Many thanks. -- NS --- In amibroker@xxxxxxxxx ps.com, ram vel <rvlv@xxx> wrote: > > > Hi > Graham,AFL PROGRAMME WRITER, has made afl exampleS, 2 OF THEM  which has easy convertibility to turtle systems 1 and 2 > just apply HHV20,LLV10, AND HHV55 AND LLV20 > IT WORKS > rvlv > --- On Sun, 11/8/09, Rob <sidhartha70@ ...> wrote: > > > From: Rob <sidhartha70@ ...> > Subject: [amibroker] Re: Turtle Trading rules for AmiBroker > To: amibroker@xxxxxxxxx ps.com> Date: Sunday, November 8, 2009, 5:50 PM > > >  > > > > I don't know about the AFL... but I know they don't work anymore. > > --- In amibroker@xxxxxxxxx ps.com, "original_nightstal ker" <nightstalker@ ...> wrote: > > > > Hi all :) > > > > Just finished reading Michael Covel's book on the Turtles, and no matter how long and hard I search both this forum and Google generally, I can't seem to find an AFL formula for the Turtle Trading system to download for AmiBroker. > > > > I'm talking about both their S1 and S2 systems for breakouts (both upwards and downwards) plus the ATR (or as they called it - 'N') system for determining the
volatility and for setting stops using '2N' > > > > Those who have read the book will know what I mean. > > > > Does anyone in here know of either the components of the system, or preferably, the complete system, that would be available as AFL code for pasting into Ami and saving? > > > > Any help much appreciated :) > > > > Thankee muchly. > > >
|