Visit our COVID-19 site for latest information regarding how we can support you. For up to date information about the pandemic visit www.sacoronavirus.co.za.

bs-regular
bs-extra-light
bs-light
bs-light
bs-cond-light-webfont
bs-medium
bs-bold
bs-black

Community


Share knowledge. Ask questions. Find answers.

Online Share Trading

Engage and learn about markets and trading online

Simons Lazy (Ass) Trading System

Reply
kr_pto
Super Contributor
;) Hey guys, thought some of you Amibroker users out there may be interested in this one. Have been playing around with building Simon's system into Amibroker, to see how well it works and to tinker at will. Am happy to share this with the forum, since the model is in the public domain anyhow (thanks Simon!)
The program is still a work in progress, but seems to be pretty close. Can be used to view on charts or to run analysis and backtesting. Was going to simply paste it in here, but as you all know, this forum doesnt handle line feeds so well! so have had to quickly try add the line feeds at the end, so if this the layour is screwed up at all, probably cos of that.
Remember, this model is supposed to only work well on low volatility such as index (like TOPI). Apparently not so good on stocks. So for what it's worth, here goes. Oh, and NOTE: I obviously take no liability whatsoever as to whether it works on not, dont use it to make your trade decisions. :)

just copy and past into Amibroker formula editor.

0 Kudos
12 REPLIES 12
kr_pto
Super Contributor
_SECTION_BEGIN("Simons Lazy System Model");
/*
Author: kr!pto
Date: 06 April 2007
Premise: This model is as developed by Simon Pateman-Brown, and discussed in his presentation. Aim here is to
represent this in Amibroker, both from a charting perspective, showing buy and sell indicators, and a
analysis perspective (using Automatic Analysis)
Basis: Originally a copy of the detailed analysis example provided by Amibroker on their website.
*/

/*-------------------------------------
Initialize
-------------------------------------*/
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.

Alternatively, use:
Title = Name() + " " + Date() + " " + "{{INTERVAL}}" + _DEFAULT_NAME() + " Chart values : " +
" Close Price = " + C
*/

PositionScore = 100 / C; /* Set the order for which stock trades when get multiple signals in one bar in backtesting */
PositionSize = - 20; /* trade size will be 20% of available equty */
SetBarsRequired(10000, 10000); /* this ensures that the charts include all bars AND NOT just those on screen */
SetFormulaName("Simons Lazy Trading System"); /* name it for backtest report identification */
SetOption("CommissionAmount", 7000); /* commissions AND cost R70*/
SetOption("CommissionMode", 2); /* set commissions AND costs as $ per trade */
SetOption("InitialEquity", 10000000); /* starting capital R100,000*/
SetOption("MaxOpenPositions", 8); /* I don't want to comit more than 80% of Equity at any one time */
SetOption("PriceBoundChecking", 1); /* trade only within the chart bar's price range */
SetOption("UsePrevBarEquityForPosSizing", 1); /* set the use of last bars equity for trade size */

/*...to be continued ...*/
0 Kudos
kr_pto
Super Contributor
/*...continued...*/ /*-------------------------------------
Calculate Indicators
-------------------------------------*/
EMAPer = Param("EMA Period", 15, 5, 20);

EMA1 = EMA(Close,30);
EMA2 = EMA(Close,35);
EMA3 = EMA(Close,40);
EMA4 = EMA(Close,45);
EMA5 = EMA(Close,50);
EMA6 = EMA(Close,60);

/*
Define primary trend as being at least 4 out of 5 of the medium term MAs must be above their higher counterpart
*/
PrimaryUp = ( (EMA1 >= EMA2) + (EMA2 >= EMA3) + (EMA3 >= EMA4) + (EMA4 >= EMA5) + (EMA5 >= EMA6) ) >= 4;
PrimaryDown = ( (EMA1 <= EMA2) + (EMA2 <= EMA3) + (EMA3 <= EMA4) + (EMA4 <= EMA5) + (EMA5 <= EMA6) ) >= 4;

/*-------------------------------------
Trade
-------------------------------------*/

/*
Determine initial buy signals as the closing price crossing the EMA from below, and if primary trend.
Then confirm this Day later if Close is positive
*/
Buy = Cross( Close, EMA(Close,EMAPer) ) AND PrimaryUp;
BuyConfirm[ 0 ] = 0;
for( i = 1 ; i < BarCount; i++)
{
BuyConfirm[i] = (Buy[i-1] AND (Close[i] > Close[i-1]));
}

/*
Reset Buy to the new Buy confirmation Signal (i.e. if following Day closes positive (OR seems to be closing positive))
*/
BuyAlert = Buy;
Buy = BuyConfirm;

/*
Determine any false buy signals, in which primary trend is not correct
*/
FalseBuy = Cross( Close, EMA(Close,EMAPer) ) AND NOT(Buy);
for( i = 1 ; i < BarCount; i++)
{
if (FalseBuy[i-1] AND Buy[i]) FalseBuy[i-1] = 0;
}

/*
Determine the purchase price for use in calculating absolute stop loss
*/
pricebought[ 0 ] = Close[ 0 ];
for( i = 1; i < BarCount; i++)
{
if (Buy[ i ]) pricebought[ i ] = Close[i];
else pricebought[ i ] = pricebought[ i - 1 ];
}
/*...to be continued...*/
0 Kudos
kr_pto
Super Contributor
/*...continued...*/ /*
Stop Loss: strict stop loss percent until cross buy price, then at buy price
*/
stopperc = Param("Stop Loss %", 10, 0, 20, 0.1);
stopamount = Close * (stopperc/100); // calculate ATR
initial = Close - (stopamount);
stop[ 0 ] = Close[ 0 ];
for( i = 1 ; i < BarCount; i++)
{
if( Close[ i ] > stop[ i - 1])
{
temp = Close[ i ] - stopamount[ i ];
if ( ( temp > stop[ i - 1 ] ) AND (temp <= PriceBought[ i ])) stop [ i ] = temp;
else if (temp > PriceBought[ i ]) stop[ i ] = PriceBought[ i ];
else stop[ i ] = stop[ i - 1 ];
}
else stop[ i ] = initial[ i ];
}

/*
Trailing "last Low" stop. If we are above purchase price, and we break get a lower low, then time to sell.
*/
lowerlowstop[ 0 ] = 0 ;
directiondown[ 0 ] = 0 ;
directionup[ 0 ] = 0 ;
turnup = 0;
turndown = 0;
for( i = 1 ; i < BarCount; i++)
{
if (Close[i] == Close[i-1])
{
directiondown[i] = directiondown[i-1];
directionup[i] = directionup[i-1];
} else
{
directiondown[i] = (Close[i] < Close[i-1]);
directionup[i] = (Close[i] > Close[i-1]);
}
}

inthemoney = (Close > EMA(Close,EMAPer));

for( i = 1 ; i < BarCount; i++)
{
if (Buy[i]) lowerlowstop[i-1] = Close[i-1] * 0.85;

if ( directiondown[i-1] AND directionup[i]) turnup = 1; else turnup = 0;
if ( directionup[i-1] AND directiondown[i]) turndown = 1; else turndown = 0;

if ((turnup) AND (Close[i-1] > lowerlowstop[i-1]) AND inthemoney[i-1])
{
lowerlowstop[i-1] = Close[i-1];
turnup = 0;
}
lowerlowstop[i] = lowerlowstop[i-1];
}

/*
We Sell if we Cross the lowerlow rule OR if our trailing stop loss is activated
*/
Sell = Cross(lowerlowstop , Close) OR (Close < Ref( stop, -1));

/* exrem is one method to remove surplus strade signals */
Buy = ExRem(Buy, Sell);
BuyAlert = ExRem(BuyAlert, Sell);
FalseBuy = ExRem(FalseBuy, Buy);
Sell = ExRem(Sell, Buy);

/*
Set variables for use in the colour of the price graph
*/
EntrySignal = (Close > (EMA(Close,EMAPer))) AND PrimaryUp;
ExitSignal = Sell;

/*-------------------------------------
Automatic Analysis (AA) Settings
This formula can be used for the following purposes:
1 - Indicator, 2 - Commentary, 3 - Scan, 4 - Exploration, 5 - Backtest, Optimize
-------------------------------------*/

AASettings = Status("action");
if (AASettings == 1) {
/* [Indicator] */
GraphXSpace = 5; /* create empty space of 10% top and bottom of chart */
Color = IIf( EntrySignal, colorBlue, IIf( ExitSignal, colorOrange, colorGrey50 ));

Plot(C, " Close Price", Color, styleLine);
Plot(EMA(C,EMAper), " EMA("+EMAper+")", colorGreen, styleLine);
Plot( stop, "Stop Loss", colorRed, styleDashed);
Plot( lowerlowstop, "Last Low", colorGrey50, styleDashed);

SellColor = IIf( stop < Ref( stop,-1), colorOrange, colorRed);

/* 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(shapeHollowUpArrow * BuyAlert, colorBlue, 0, L, - 20);
PlotShapes(shapeHollowUpArrow * FalseBuy, colorGreen, 0, L, - 30);
PlotShapes(shapeDownArrow * Sell, SellColor, 0, H, - 10);

} else if (AASettings == 2) {
// [Commentary]
"Closing price = " + WriteVal(Close);
"Change since yesterday = " + WriteVal(Close - Ref(Close, -1));
"Percent chg. since yesterday = " + WriteVal(ROC(Close, 1)) + " %";

} else if (AASettings == 3) {
// [Scan]
AlertIf(Buy, "SOUND C:\\PROGRAM FILES\\AMIBROKER\\BUY.WAV", "Buy", 3);
AlertIf(Sell, "SOUND C:\\PROGRAM FILES\\AMIBROKER\\SELL.WAV", "Sell", 3);

} else if (AASettings == 4) {
// [Exploration]
/* We 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(directionup, "UP", 1);
AddColumn(directiondown, "DOWN", 1);

} else if (AASettings == 5) {
// [Backtest]
SetTradeDelays(0, 0, 0, 0);
}

_SECTION_END();
0 Kudos
kr_pto
Super Contributor
and if you're wandering why 4 posts instead of 1, thank the forum software for limiting the length of a post! and will also result in the text alignment (tabs, etc) being out, so you will have to reformat if you want...
enjoy and let me know if anyone finds any problems or suggestions. ciao.
0 Kudos
DCTrader
Super Contributor
You've got too much time on your hands...
0 Kudos
kr_pto
Super Contributor
sigh, what to do what to do...
0 Kudos
Werner_1
Super Contributor
thanks, i copied it and will look at it now. I also am quite interested in it...
0 Kudos
kr_pto
Super Contributor
oh, and I am looking for more history data on TOPI, as SFM only has 1 year history on their indices. anyone know anywhere one could download this without having to pay for a monthly service of history database?
0 Kudos
Werner_1
Super Contributor
how can i contact you - email - maybe i can help?
0 Kudos
kr_pto
Super Contributor
sure thing. give me your email addie and will pop you an email, if that's cool. pity this forum doesnt have private chat option.
0 Kudos
kr_pto
Super Contributor
have created a private email addie if anyone needs to email re this program or other stuff: [email protected]. just let me know to check it. thanks werner, will drop you a mail now.
0 Kudos