# A Sample System to Play With



## lesm (4 October 2006)

With some of the newcomers asking questions about charting, etc., thought it may be worthwhile having a bit of a discussion on system development.

As an example I have put together a small test system that anyone is free to play around with. 

Part of the system below is derived from a trend following system that was developed in 1999 for the futures market using 30 minute intra-day charts.

With the tools available today it is relatively easy to set up a simple system and test it. It is quite a simple matter to play around with ideas and modify parameters, so feel free to modify, add or change anything that you see below.

The Metastock code is included below:

_Filter_
ADX(14) < 25 
AND C > Ref(HHV(C,15),-1) 
AND Fml("Liquidity") > 400000 
AND C < 5.00 AND C > O 
AND (Mov(C,10,E) > Mov(C,20,E) > Mov(C,50,E)> Mov(C,200,E))

_Indicator_
Liquidity
Mov(V * C,21,S)

*WARNING: the code above is untested and is only provided as an example.*

I have only run it as an exploration in Metastock to see what it would produce. If I was testing it I would convert and run it under AmiBroker.

*NB:* The above doesn't represent any system that I currently use live.

Anyway have fun.


----------



## doctorj (5 October 2006)

In the interests of fair play.

To make this work, I've nabbed Mr Tech/A's exit.

Monte Carlo Report
(LesTrader)

Simulation Summary
Simulation Date:                                             4/10/2006
Simulation Time:                                           10:30:25 PM
Simulation Duration:                                     20.59 seconds

Trade Parameters
Initial Capital:                                           $100,000.00
Portfolio Limit:                                               100.00%
Maximum number of open positions:                                  100
Position Size Model:                                Fixed Percent Risk
Percentage of capital risked per trade:                          2.00%
Position size limit:                                           100.00%
Portfolio Heat:                                                 20.00%
Pyramid profits:                                                   Yes
Transaction cost (Trade Entry):                                 $30.00
Transaction cost (Trade Exit):                                  $30.00
Margin Requirement:                                            100.00%

Trade Preferences
Trading Instrument:                                             Stocks
Break Even Trades:                                  Process separately
Trade Position Type:                                Process all trades
Entry Order Type:                                        Default Order
Exit Order Type:                                         Default Order
Minimum Trade Size:                                              $0.00
Accept Partial Trades:                                              No
Volume Filter:                               Ignore Volume Information
Pyramid Trades:                                                    Yes
Favour Trade Pyramid:                                              Yes

Simulation Stats
Number of trade simulations:                                     10000
Trades processed per simulation:                                   632
Maximum Number of Trades Executed:                                  74
Average Number of Trades Executed:                                  70
Minimum Number of Trades Executed:                                  62
Standard Deviation:                                               3.29

Profit Stats
Maximum Profit:                                  $320,294.87 (320.29%)
Average Profit:                                  $278,352.04 (278.35%)
Minimum Profit:                                  $246,082.56 (246.08%)
Standard Deviation:                                $16,402.33 (16.40%)
Probability of Profit:                                         100.00%
Probability of Loss:                                             0.00%

Percent Winning Trade Stats
Maximum percentage of winning trades:                           30.16%
Average percentage of winning trades:                           25.47%
Minimum percentage of winning trades:                           22.97%
Standard Deviation:                                              2.04%

Percent Losing Trade Stats
Maximum percentage of losing trades:                            77.03%
Average percentage of losing Trades:                            74.53%
Minimum percentage of losing trades:                            69.84%
Standard Deviation:                                              2.04%

Average Relative Dollar Drawdown Stats
Maximum of the Average Relative Dollar Drawdown:            $11,297.68
Average of the Average Relative Dollar Drawdown:            $10,243.06
Minimum of the Average Relative Dollar Drawdown:             $9,148.22
Standard Deviation:                                            $684.34

Average Relative Percent Drawdown Stats
Maximum of the Average Relative Percent Drawdown:              4.4323%
Average of the Average Relative Percent Drawdown:              3.9288%
Minimum of the Average Relative Percent Drawdown:              3.1527%
Standard Deviation:                                            0.4112%

Maximum Peak-to-Valley Dollar Drawdown Stats
Maximum Absolute Dollar Drawdown:                          $128,242.88
Average Absolute Dollar Drawdown:                          $104,692.46
Minimum Absolute Dollar Drawdown:                           $85,869.40
Standard Deviation:                                         $12,444.39

Maximum Peak-to-Valley Percent Drawdown Stats
Maximum Absolute Percent Drawdown:                            28.4717%
Average Absolute Percent Drawdown:                            24.9138%
Minimum Absolute Percent Drawdown:                            18.2609%
Standard Deviation:                                            2.8536%


----------



## lesm (5 October 2006)

For a bit more of the sample an AmiBroker version with initial Backtesting results attached.

Cheers.

// ADX and 4 EMAs Test System
// Define buy conditions and name each one as a variable
//Test run using Buy on OPEN

PositionSize = -10; // always invest only 10% of the current Equity

cond1=C>Ref(HHV(C,15),-1); // when todays high crosses last highest high over the last 10 periods
cond2=ADX(14) < 25; // ADX (period = 14) > 25
cond3=EMA(V*C,21) > 500000; // ensure at least $500k of money flow
cond4=C < 10.00; // only trading in stocks less than $10
cond5=C > O; // todays close higher than open
Cond6=(EMA(C,10) > EMA(C,20) > EMA(C,50) > EMA(C,200));

// the following line is the trigger if all conditions satisfied
Buy=cond1 AND cond2 AND cond3 AND cond4 AND cond5 AND Cond6;

// here we define variables used once in the trade
ApplyStop( stopTypeLoss, stopModePercent, amount=5 );
Sell=Close<Ref(LLV(Close,5),-1);

// here we define what gets displayed on the chart
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy , colorYellow, colorRed ), 0, IIf( Buy , Low, High));

Filter = Buy; // lists exploration results conforming to our buy criteria
AddColumn(Buy, "buy", 1.0); //


----------



## lesm (5 October 2006)

Doctorj,

Thanks for that.

Just wanted to see if there was any interest, as I just put a few pieces together and realised later that I hadn't provided an exit condition.

Cheers.


----------



## doctorj (5 October 2006)

Not anywhere near as good with that exit.  Though, I'm suspicious.  It appears in my testing, much of the gains in each of those monte carlo runs with the previous exit is due to DOW going nuts.

Monte Carlo Report
(LesTrader)

Simulation Summary
Simulation Date:                                             4/10/2006
Simulation Time:                                           10:44:43 PM
Simulation Duration:                                     24.58 seconds

Trade Parameters
Initial Capital:                                           $100,000.00
Portfolio Limit:                                               100.00%
Maximum number of open positions:                                  100
Position Size Model:                                Fixed Percent Risk
Percentage of capital risked per trade:                          2.00%
Position size limit:                                           100.00%
Portfolio Heat:                                                 20.00%
Pyramid profits:                                                   Yes
Transaction cost (Trade Entry):                                 $30.00
Transaction cost (Trade Exit):                                  $30.00
Margin Requirement:                                            100.00%

Trade Preferences
Trading Instrument:                                             Stocks
Break Even Trades:                                  Process separately
Trade Position Type:                                Process all trades
Entry Order Type:                                        Default Order
Exit Order Type:                                         Default Order
Minimum Trade Size:                                              $0.00
Accept Partial Trades:                                              No
Volume Filter:                               Ignore Volume Information
Pyramid Trades:                                                    Yes
Favour Trade Pyramid:                                              Yes

Simulation Stats
Number of trade simulations:                                     10000
Trades processed per simulation:                                   800
Maximum Number of Trades Executed:                                 313
Average Number of Trades Executed:                                 305
Minimum Number of Trades Executed:                                 295
Standard Deviation:                                               2.89

Profit Stats
Maximum Profit:                                  $156,765.52 (156.77%)
Average Profit:                                    $83,776.51 (83.78%)
Minimum Profit:                                    $37,886.37 (37.89%)
Standard Deviation:                                $18,634.82 (18.63%)
Probability of Profit:                                         100.00%
Probability of Loss:                                             0.00%

Percent Winning Trade Stats
Maximum percentage of winning trades:                           43.62%
Average percentage of winning trades:                           41.14%
Minimum percentage of winning trades:                           38.71%
Standard Deviation:                                              0.70%

Percent Losing Trade Stats
Maximum percentage of losing trades:                            61.29%
Average percentage of losing Trades:                            58.86%
Minimum percentage of losing trades:                            56.38%
Standard Deviation:                                              0.70%

Average Relative Dollar Drawdown Stats
Maximum of the Average Relative Dollar Drawdown:             $2,876.68
Average of the Average Relative Dollar Drawdown:             $2,361.22
Minimum of the Average Relative Dollar Drawdown:             $2,069.08
Standard Deviation:                                            $135.40

Average Relative Percent Drawdown Stats
Maximum of the Average Relative Percent Drawdown:              2.3928%
Average of the Average Relative Percent Drawdown:              2.0120%
Minimum of the Average Relative Percent Drawdown:              1.7793%
Standard Deviation:                                            0.1039%

Maximum Peak-to-Valley Dollar Drawdown Stats
Maximum Absolute Dollar Drawdown:                           $42,345.63
Average Absolute Dollar Drawdown:                           $36,956.19
Minimum Absolute Dollar Drawdown:                           $31,226.33
Standard Deviation:                                          $1,930.03

Maximum Peak-to-Valley Percent Drawdown Stats
Maximum Absolute Percent Drawdown:                            33.5322%
Average Absolute Percent Drawdown:                            29.3323%
Minimum Absolute Percent Drawdown:                            24.8209%
Standard Deviation:                                            1.5315%


----------



## lesm (5 October 2006)

Doctorj,

It's interesting playing with the exits, as well as with the difference between buying on open as opposed to buying on the close.

Have only run some very quick backtests since posting it and had a play with another version using 3 EMAs, as well as a couple of different exits.

BTW, I have the maximum number of open positions set to 10.

Cheers.


----------



## Milk Man (5 October 2006)

Thanks dude, I like systems with high win rates nowadays.


----------



## hardmoney (5 October 2006)

cond2=ADX(14) < 25; // ADX (period = 14) > 25

Not sure that this line is correct ??,should it read

cond2=ADX(14)>25;



Rgds,
HM


----------



## lesm (5 October 2006)

hardmoney said:
			
		

> cond2=ADX(14) < 25; // ADX (period = 14) > 25
> 
> Not sure that this line is correct ??,should it read
> 
> ...




Hi HM,

As a starting point the condition is correct, but the comment is incorrect.

Should read '// ADX (period = 14) < 25'

Thanks for picking it up.

Was doing some playing around by reversing the condition to see what would happen if it was turned around, but didn't update the comment.

I will add in a short side component this evening and another version using 3 EMAs for comparison. Maybe add a couple of different exit techniques for comparison as well. Will see how it goes. Will run additional tests along the way for comparative purposes.

Feel free to do whatever you like with the system. Looking at this more as a discussion and ideas topic.

Cheers,
Les.


----------



## lesm (5 October 2006)

Here is a variant on the sample system using the ADX and 3 EMAs, as opposed to 4 EMAs, a different set of EMA periods.

It includes conditions for going long and short. Have simplified it by reversing some of the long conditions, just as a simple example.

Any of the conditions can be varied or changed to try out different settings or to use a different approach. Fixed a couple of typos in the comments. Have tidied up the layout and the variable descriptive names.

Feel free to play and experiment at *YOUR OWN PERIL*, as I have only undertaken some cursory testing. If the system was used only using the ADX, it should fail under volatile market conditions.

Anyway enjoy have a bit of fun.

As an experiment you could try reversing the "<" to ">" for the ADX test and look at the difference in the test results or remove the EMA test condition from the SHORT position and look at the change that makes.

As always never use anything, if you dont understand how it works or its strengths and weaknesses.

Cheers.

AmiBroker Sample System below:


// ADX and 3 EMAs Test Sample System
// We define LONG and SHORT conditions and name each one as a variable
// Tests run using BUY/SELL on OPEN and SHORT/COVER on OPEN
// Account size $100,000

PositionSize = -10; // always invest only 10% of the current Equity

// General set of conditions used for both BUY and SHORT
GeneralCond1 = ADX(14) < 25; // ADX (period = 14) < 25
GeneralCond2 = EMA(V * Close,21) > 500000; // ensure at least $500k of money flow
GeneralCond3 = Close < 10.00; // only trading in stocks less than $10

// Conditions used for BUY
LongCond1 = Close > Ref(HHV(Close,15),-1); // when todays high crosses last highest high over the last 15 periods
LongCond2=(EMA(Close,21) > EMA(Close,35) > EMA(Close,85));
LongCond3 = Close > Open; // todays close higher than open

//Conditions used for SELL
SellCond1 = Close < Ref(LLV(Close,5),-1);

// Conditions used for SHORT
ShortCond1 = Close < Ref(LLV(Close,15),-1); 
ShortCond2 = (EMA(Close,21) < EMA(Close,35) < EMA(Close,85));
ShortCond3 = Close < Open; // todays close lower than open

//Conditions used for COVER
CoverCond1 = Close > Ref(HHV(Close,5),-1);

// Buy Long
// the following line is the triggered if all conditions satisfied
Buy = LongCond1 AND LongCond2 AND LongCond3 AND GeneralCond1 AND GeneralCond2 AND GeneralCond3;
Sell = SellCond1;

// Sell Short
// The following line is triggered if all conditions are satisifed
Short = ShortCond1 AND ShortCond2 AND ShortCond3 AND GeneralCond1 AND GeneralCond2 AND GeneralCond3;
Cover = CoverCond1;

// Risk 2% per trade
ApplyStop( stopTypeLoss, stopModePercent, amount = 2 );

// here we define what gets displayed on the chart
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy , colorYellow, colorRed ), 0, IIf( Buy , Low, High));

Filter = Buy; // lists exploration results conforming to our buy criteria
AddColumn(Buy, "buy", 1.0);

Filter = Short; // lists exploration results conforming to our short criteria
AddColumn(Short, "short", 1.0);


----------



## nizar (27 August 2007)

Some interesting stuff in this thread.
Iv been trying to test some of the stuff on here, but i still keep getting this same problem appearing on the tradesim(DLL) plugin.
I keep getting warnings that trade prices had to be modified because of invalid entry price data.

The code i used for the metastock exploration is below?



> Ent:= ADX(14) < 25 AND C > Ref(HHV(C,15),-1) AND Mov(V * C, 21, S) > 400000 AND C < 5.00 AND C > O
> AND (Mov(C,10,E) > Mov(C,20,E) > Mov(C,50,E)> Mov(C,200,E))
> 
> EntryTrigger:=Ent;
> ...




Any thoughts please guys on how to fix this problem?


----------



## tech/a (28 August 2007)

Nizar.

There is a discussion here.
http://compuvision.com.au/vBulletin/showthread.php?t=126&highlight=Invalid+entry+price+data

Another way to find where the error is is to place {around pieces of code} until the error disappears.This will isolate the problem.

BUT I think I have found it.

Your missing the *;* at the end of this code

Ent:= ADX(14) < 25 AND C > Ref(HHV(C,15),-1) AND Mov(V * C, 21, S) > 400000 AND C < 5.00 AND C > O 
AND (Mov(C,10,E) > Mov(C,20,E) > Mov(C,50,E)> Mov(C,200,E));

Try that.


----------



## rnr (28 August 2007)

Nizar,

Details in bold are the changes I believe are required to get rid of your problems:-
{1} as mentioned by tech,
{2} obviates the need for this function (ExtFml("Tradesim.EnableDelayOfEntryByOneBar")) to be called in TradeSim and I have found it seems to cause less problems,
{3} TradeSim function call to initialize and
{4} the exclusion for the "delay of entry" as mentioned in {2} above.



> Ent:= ADX(14) < 25 AND C > Ref(HHV(C,15),-1) AND Mov(V * C, 21, S) > 400000 AND C < 5.00 AND C > O
> AND (Mov(C,10,E) > Mov(C,20,E) > Mov(C,50,E)> Mov(C,200,E))*;* {1}
> 
> EntryTrigger:=*Ref(*Ent*,-1)*; {2}
> ...




As you have set the InitialStop to zero you will not be able to run any "Risk Based" simulations in TradeSim.


----------



## nizar (28 August 2007)

rnr many thanks.
Initial stop i have added one it didnt work (ie. i still cannot choose fixed risk models in tradesim) but i will make those changes first as you said, and then will try with the initial stop again. If any problems i will post here.

Tech/a as always your posts are very helpful and much appreciated.


----------



## nizar (31 August 2007)

Does:

ExtFml( "Tradesim.EnableDelayOfEntryByOneBar") 
ExtFml("Tradesim.EnableDelayOfAllExitsByOneBar");

Mean the same as this??

ActualEntryTrigger:=Ref(EntryTrigger,-1);

ActualExitTrigger:=Ref(ExitTrigger,-1);

If not -- then whats the difference?

THanks.


----------



## nizar (31 August 2007)

ExtFml("TradeSim.EnableProtectiveStop",*1*); 

What does it mean when the number is 0 or -1 or 1 ??


----------



## tech/a (31 August 2007)

Nizar.
Why dont you read the manual.
Thats why David spent months writing it.


----------

