This is read-only version of AFL library entry. Ability to add user formulas
and comment is only available from members-only area.
Details:
Formula name:
Trend Following System
Author/Uploader:
marcus - marcusdavidsson
Date/Time added:
2009-09-20 05:58:13
Origin:
Keywords:
Level:
basic
Flags:
system
DISCLAIMER: Most formulas present in AFL on-line library are submitted
by the users and are provided here on an "as is" and "as available" basis.
AmiBroker.com
makes no representations or warranties of any kind to the contents or the operation
of material presented here. We do not maintain nor provide technical support
for 3rd party formulas. Description:
This is a simple long only trend following system. Just load it into the \"Automatic Analysis\" window and push \"Scan\", \"Back test\" and \"Report\" to view the result.
Formula:
SetTradeDelays(0,0,0,0);
SetPositionSize(10, spsPercentOfEquity );
SetOption("AllowSameBarExit" , True );
// If this option is not set true positions that are exited at the same bar
remains open
SetOption("PriceBoundChecking", False);
// This option must be set false in order to exit at specified stop price and
not bar close
//LK=Optimize("Trend", 50, 30, 60, 10 ) ;
//FF=Optimize("Trend", 20, 10, 40, 10 ) ;
//StopLevel=Optimize("Stop",0.1,0.05,0.5,0.05 ) ;
StopLevel = 0.2;
LK=50;
FF=10;
A1= IIf( L> Ref(HHV( Close,LK),-5), 1, 0);
A2= Sum( A1, LK ) ;
A3= IIf(C>0, FF, 0);
Buy = Cross(A2,A3);
Sell = 0;
trailARRAY = Null;
trailstop = 0;
for( i = 1; i < BarCount; i++ )
{
if( trailstop == 0 AND Buy[ i ] )
{
trailstop = High[ i ] * (1-stoplevel);
}
else Buy[ i ] = 0; // remove excess buy signals
if( trailstop > 0 )
{
trailstop = Max( High[ i ] * (1-stoplevel), trailstop );
trailARRAY[ i ] = trailstop;
}
if( trailstop > 0 AND Low[ i ] < trailstop )
{
Sell[ i ] = 1;
SellPrice[ i ] = trailstop;
trailstop=0;
}
}
PlotShapes(Buy*shapeUpArrow,colorBlue,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);
Plot( Close,"Price",colorBlack,styleBar);
Plot( trailARRAY,"trailing stop level", colorRed );
Comments:
Wynand wduv [at] live.co.za 2009-10-20 10:22:14
Very nice.
Are you planning to add short signals as well?
Wynand wduv [at] live.co.za 2009-10-21 03:18:31
Very nice.
Are you planning to add short signals as well?
marcus davidsson_marcus [at] hotmail.com 2009-11-12 15:47:52
I tried to add short as well but I did not get a very nice result! Maybe I did something wrong. If I come up with an nice solution I will post it :-)
Mike burningfocus [at] yahoo.com.au 2010-02-12 21:40:20
I noted you have trailing stops in your trend system. I am trying to write formula so I can use the 3-bar net line as a trailing stop, but having trouble. Can you put me in touch with someone who could write this code for me? Details of 3-bar net line are;
1. Find HIGHEST HIGH for the current UPSWING Label it BAR 1
2. Look to the LEFT, find the MOST RECENT LOW that is LOWER than the LOW of BAR 1,Label it BAR 2
3. Look LEFT again, FIND the MOST RECENT LOW that is LOWER than the LOW of BAR 2, Label it BAR 3
4. The THREE-BAR NET LINE is a HORIZONTAL LINE extending RIGHT from Bar 3 LOW