Australian (ASX) Stock Market Forum

Developing a mechanical system from scratch

Indeed. Can you tell I don't use tradesim too often?:D I ran the simulation again just after and it returned a loss (I correctly included the commission the second time) hence why I posted something was amiss.

It's not a complete fowl up though. It does show the entry isn't entirely bad. The question now is whether there is anything practical we can change to make it profitable (position sizing, the exit, the universe of stocks)? Tweaking the entry to exclude stocks without an upward bias by including a long term MA would be my starting point. We need to establish whether or not the system has an edge we can exploit.

Or, alternatively, we decide the system is nice in theory, but isn't tradeable. Plenty of ideas like that around.

Hi Doctorj

May I suggest you test say 10 bluechips across the sectors with entry time at say 2.45pm and exit at 10.45am?

Cheers
Happytrader
 
Hi Doctorj

May I suggest you test say 10 bluechips across the sectors with entry time at say 2.45pm and exit at 10.45am?

Cheers
Happytrader
Happytrader - I don't have intraday data and I'm not sure how your post follows through on the work we've done to date.
 
I imagine that position size would have a great bearing on the result. I'm not sure how the software works out the size, but I assume initially it is either starting funds / max positions ($500.00) or starting size * max risk ($1000.00).
Could you try the same simulation with a trading size around $5,000 as that would reduce the impact of brokerage.
 
OK Guys, FWIW, I’ll present a very simple (rough as guts) system that is based on a volatility breakout, using Nick’s suggestion as a basis.

The system identifies the 3 inside bar setup and then immediately looks for a breakout bar, which is defined by having High greater than the high of the smallest inside (a clear break from the micro-triangle). The other caveat is that the low of the breakout bar must be within the range of the smallest breakout bar.

When the breakout bar is identified, a long @ open is initiated the following day and the trade is automatically closed off after 5 days (also at the open).

Because the system only holds for 5 days and the frequency of trade is not overly high, I have adjusted the parameters to allow each position trade to be larger (otherwise the system will sit there with cash in the bank doing nothing)

1) $100K initial investment
2) only 4 max concurrent trades
3) Each trades uses using 25% of available equity.

Stock Universe: ASX300
Test Period: Last 1000 quotations

Even then, the exposure to the market is SFA.

The Setup, Amibroker code and results follow:
 

Attachments

  • asfsetup.jpg
    asfsetup.jpg
    11.5 KB · Views: 385
  • ASFresults.doc
    70 KB · Views: 82
  • asfcode.doc
    26 KB · Views: 81
Good job.

At last something to work with.

Have you run it over a number of portfolios.
I dont use Ami so dont know its full capabilities.
Can also start playing with exits and stops to seek improvement.
Could also look at various universes.

If someone knocks this up in M/S code I'll run Tradesim Montecarlo on it and try a few varients.

Dont have a lot of time myself.
But if no code pops up I'll do it when I get a chance.
 
tech/A,Bingk6

That Pattern is called a Shark Bar Pattern.
Google "Shark-32 "
At the top of the page you will find the code for Metastock and Tradestation.

The Guy Walter Downs talks about a break above the High of the pattern, not a break above the high of the last inside bar.

I dont Know if this will help or not.

Cheers....Onemore
 
Tech,

The testing was done on a portfolio level.

The number of trades involved in this system is so small, 228 trades over a test period of 1000 days, across 300 stocks, it works out at roughly less than 1 trade every 4 days. What are the odds of having more than 4 stocks competing for funds on any given day? Probably close to zilch. In any case, when the trade goes on, it only lasts for 5 days, so the exposure to the market is very small. In this instance, Monte Carlo Analysis may have very limited application because funds will be available to take every trade.

As far as the Metastock code is concerned, as there are no looping involved, it can be taken out pretty much exactly as per the Amibroker code I enclosed previously, viz:


LiquidityCond:= EMA(V * C, 21) > 500000;
InsideDay1:= H <= Ref(High,-1) AND Low >= Ref(Low,-1);
InsideDay2:= Ref(High,-1)<= Ref(High,-2) AND Ref(Low,-1)>= Ref(Low,-2);
InsideDayCond:= InsideDay1 AND InsideDay2 ;
Extremevolume:=V>=2*Ref(EMA(V,5),-1);
Closepercentile:=(C-L)/(H-L);
Closeonhigh=:Closepercentile>=0.7;
Buy:= Ref(Insidedaycond,-1) AND Ref(Liquiditycond,-1)
AND L>=Ref(L,-1) AND L<=Ref(H,-1) AND H>Ref(H,-1)
AND Closeonhigh AND Extremevolume;


The Metastock code for the exit is very difficult to code, as we simply want to exit unconditionally after 5 days. Tradesim (I believe) does allow you to simulate these sorts of exits easily. Amibroker does it easily.


As for the system, I have done more testing to test the effectiveness of the of the 5 day stop relative to other stops. Attached below are the results all the way from 1day stop to 30 day stop and everything else in between.

Look at the system %DD, all <20%. For a short term system, we must aim for <20%. The concept for such a short term is to pinch your profit whenever you can, so that hopefully whenever the bad days occur in the market, you are NOT in it. Thats the theory anyway.

So Can (our fearless leader!!! :D), plenty of material presented as a starting point, FWIW. Admitted its rough, no sophiscated exits, no money management, no trailing stops - simple entry, so lets see where we go from here.
 

Attachments

  • asfallresults.jpg
    asfallresults.jpg
    156.9 KB · Views: 253
tech/A,Bingk6

That Pattern is called a Shark Bar Pattern.
Google "Shark-32 "
At the top of the page you will find the code for Metastock and Tradestation.

The Guy Walter Downs talks about a break above the High of the pattern, not a break above the high of the last inside bar.

I dont Know if this will help or not.

Cheers....Onemore

Yes, I can see the similarities. Wish I had known about this. Will see if we can pinch some ideas from your link. Thanks for posting.
 
For those looking to set a time-related stop in Metastock that have Tradesim, the following code will do it for you:

ExtFml( "TradeSim.SetTimeStop",X );
Where X is an positive whole number. If it's a daily system, it will exit after x days.

It's probably possible to code a time-related stop with vanilla metastock using the dayofmonth() and year() functions.
 
Doing a bit of work on this.

This is my code.

I believe we want 2 inside days then the trigger bar.
Hence my code is a little different.

However it only gives me 26 trades in 8 yrs!

Ref(H,-1)<=Ref(HIGH,-2) AND Ref(LOW,-1)>=Ref(LOW,-2)AND Ref(HIGH,-2)<= Ref(HIGH,-3) AND Ref(LOW,-2)>= Ref(LOW,-3)AND L>=Ref(L,-1) AND L<=Ref(H,-1) AND H>Ref(H,-1) AND V>=2*Ref(Mov(V,5,E),-1) AND ((C-L)/(H-L))*.7;

Anyone see anything obvious?
 
"For those looking to set a time-related stop in Metastock that have Tradesim, the following code will do it for you:

ExtFml( "TradeSim.SetTimeStop",X );
Where X is an positive whole number. If it's a daily system, it will exit after x days."


Just a minor correction... The above counts bars, not days, so:
ExtFml( "TradeSim.SetTimeStop",X );
...means exit on the Xth bar.

To use days you need a dash in front of the number:
ExtFml( "TradeSim.SetTimeStop",-X );
...which means exit on the Xth day.
 
"For those looking to set a time-related stop in Metastock that have Tradesim, the following code will do it for you:

ExtFml( "TradeSim.SetTimeStop",X );
Where X is an positive whole number. If it's a daily system, it will exit after x days."


Just a minor correction... The above counts bars, not days, so:
ExtFml( "TradeSim.SetTimeStop",X );
...means exit on the Xth bar.

To use days you need a dash in front of the number:
ExtFml( "TradeSim.SetTimeStop",-X );
...which means exit on the Xth day.

Do you mean a dash or - if "-" then that makes it a negative number and tradesim will report it as an error.
 
From the Tradesim manual:

SetTimeStop

ExtFml(“TradeSim.SetTimeStop”,NBARS);

This function is used to limit the maximum number of bars before the RecordTrades function is forced to exit a trade irrespective of the condition of the ExitTrigger. When a trade is entered and a valid exit trigger has not been detected after NBARS have been counted the trade will automatically be terminated on the next bar. If NBARS is set to zero then the time stop will be disabled. A call to the Initialize function disables the effects of a call to this function. You can also specify the time stop in terms of days. This can be done by using a negative time value.i.e, -10 specifies a time stop of 10 days where as a +10 specifies a time stop of 10 bars.
Note: To avoid confusion the time stop now exits on the actual Nth bar/day rather than one bar/day after.


Example
The following example sets up a time stop to automatically exit a trade after 60 bars have passed and an ExitTrigger has not been detected.
ExtFml(“TradeSim.SetTimeStop”,60);

Example
The following example sets up a time stop to automatically exit a trade after 10 days have passed and an ExitTrigger has not been detected.
ExtFml(“TradeSim.SetTimeStop”,-10);


Copyright © 2000-2007 by Compuvision Australia Pty Ltd. All Rights Reserved
http://www.compuvision.com.au - Last updated on 2 May 2007
Page 88
TradeSim ®
Pre-Release Beta Version 5.3.3
 
Doing a bit of work on this.

This is my code.

I believe we want 2 inside days then the trigger bar.
Hence my code is a little different.

However it only gives me 26 trades in 8 yrs!

Ref(H,-1)<=Ref(HIGH,-2) AND Ref(LOW,-1)>=Ref(LOW,-2)AND Ref(HIGH,-2)<= Ref(HIGH,-3) AND Ref(LOW,-2)>= Ref(LOW,-3)AND L>=Ref(L,-1) AND L<=Ref(H,-1) AND H>Ref(H,-1) AND V>=2*Ref(Mov(V,5,E),-1) AND ((C-L)/(H-L))*.7;

Anyone see anything obvious?

Should that section be ((C-L)/(H-L))>=.7;

Though I doubt that would give you more results as the way it is written (*.7) would always give a TRUE unless C=L

Most stocks would only achieve the volume requirement a few times a year, without that I think you should find plenty of candidates
 
Thanks M/S Id forgotten the Comma.

I have also dropped the Volume condition and now have 40 trades in 7 yrs.
I'm using the BT margin list.Which is roughly equivelent to the ASX300.

What are you other guys using for the universe to get 109 trades?

Also looking at the trade log profit is derived from on a few trades (Larger profit)
The problem appear to be frequency (Not enough) and Time in the trade (Not enough for this method.).
 
I found these in my explorer files. I used to search NASDAQ stocks years ago for that Shark Bar Pattern.

Symmetry:=.28;
Apex:=(H+L)/2;
WB:=Ref(H,-2)-Ref(L,-2);

If((H<Ref(H,-1) AND L>Ref(L,-1) AND Ref(H,-1)<Ref(H,-2) AND
Ref(L,-1)>Ref(L,-2)),
If(apex <= (Ref(H,-2)-(WB*Symmetry)) AND Apex >=
(Ref(L,-2)+(WB*Symmetry)) ,1,0),0);


Symmetry:=.10;
Apex:=(H+L)/2;
WB:=Ref(H,-2)-Ref(L,-2);

If((H<Ref(H,-1) AND L>Ref(L,-1) AND Ref(H,-1)<Ref(H,-2) AND
Ref(L,-1)>Ref(L,-2)),
If(apex <= (Ref(H,-2)-(WB*Symmetry)) AND Apex >=
(Ref(L,-2)+(WB*Symmetry)) ,1,0),0);


Are They any help?

Onemore.
 
I found these in my explorer files. I used to search NASDAQ stocks years ago for that Shark Bar Pattern.

Symmetry:=.28;
Apex:=(H+L)/2;
WB:=Ref(H,-2)-Ref(L,-2);

If((H<Ref(H,-1) AND L>Ref(L,-1) AND Ref(H,-1)<Ref(H,-2) AND
Ref(L,-1)>Ref(L,-2)),
If(apex <= (Ref(H,-2)-(WB*Symmetry)) AND Apex >=
(Ref(L,-2)+(WB*Symmetry)) ,1,0),0);


Symmetry:=.10;
Apex:=(H+L)/2;
WB:=Ref(H,-2)-Ref(L,-2);

If((H<Ref(H,-1) AND L>Ref(L,-1) AND Ref(H,-1)<Ref(H,-2) AND
Ref(L,-1)>Ref(L,-2)),
If(apex <= (Ref(H,-2)-(WB*Symmetry)) AND Apex >=
(Ref(L,-2)+(WB*Symmetry)) ,1,0),0);


Are They any help?

Onemore.


Hello All,

Here's a link to the MS code for the above mentioned 3-bar Shark Pattern...

http://trader.online.pl/MSZ/e-se-Combining_Statistical_Pattern_Analysis_Shark_32.html


Regards,

Chorlton
 
Greetings --

Thanks to those of you who had kind words for my book, Quantitative Trading Systems.

I see that the posting I am making now is about 6 weeks after the last post in the thread, so maybe this is a dead issue. But I would like to make a couple of points.

First -- I am a firm believer that the objective function is extremely important, must incorporate the personality of the trader, and must be decided before serious testing of systems begins. There were several suggestions in this thread to define an objective function, but I did not see that one was defined. That is not surprising, since there are so many contributors to the thread. The objective function needs to be personal.

Second -- Analysis of in-sample results cannot be used to estimate the future profitability (or whatever other metric is being used) of a trading system. Only out-of-sample results can be used.

Thanks for listening,
Howard Bandy
www.quantitativetradingsystems.com
 
I have read this thread with great interest as I am trying to get my head around charting and systems generally.

I have been following GBG's chart for some time and note they had reducing range followed by upswing day in July. They also have had reducing range for the last three days.

Sorry I don't have any way of posting a chart at this stage but can anyone confirm if I am reading this right and it fits the mechanics of the system discussed in this thread?

cheers
Surly
 
Top