Australian (ASX) Stock Market Forum

Testing a mechanical plan

Hi Again,

I was just thinking about the methods or software for used for backtesting and how does the software know if a stock has broken a long term trend line? Or does it not matter?

Cheers
 
stink said:
I was just thinking about the methods or software for used for backtesting and how does the software know if a stock has broken a long term trend line? Or does it not matter?
If your exit is the break of a long term trend line, then this is specified in the Exit Trigger formula.

As an example, using MetaStock and TradeSim, you would code this as;

ExitTrigger:=CLOSE<MOV(CLOSE,175,EXPONENTIAL).

This signals the trading simulator to exit a trade if the day's CLOSE is below a long term moving average.
 
For a cross of the close I prefer this

Cross(Ref(Mov(C,175,E),-1),C).

But thats not the question.
Stink I'm yet to see a software that will allow you to code the crossing of a Trendline.
The problem being that you need to use Zig Zag in the coding to identify peaks and troughs.Your idea is to have price cross a downtrend as one of your entry criteria.
Specifying troughs or peaks can be in % or point value.Either way the leg in question (The now peak or trough) is dynamic.
To explain.Lets say you have 10% move in a peak and tommorow the stock retraces to 8% the peak is clearly 2% above the 10% value.
Trend is drawn
2 days later the price has moved 5% beyond the original 10% and is still not correcting.
The old peak is no longer there as price is still seen as an up move without a new trough being made.
So yesterdays trendline is no longer there.
Dynamic code cannot be used in systems tests.

As for software.

I use the same as Michael, Metastock coupled with Tradesim -- Enterprise edition with Montecarlo capability.Around $2500 for both
If youve never coded Amibroker is cheaper and very very good.About $400 I think.
 
tech/a said:
Dynamic code cannot be used in systems tests.
Actually it can in this respect, as buy and sell signals are generated each day based on the trend line as it is that particular day. If the next day the trend line changes, then the next day's signals will be generated with the new trend line. What can happen though is that after a buy signal is generated, the trend line can move such that there wouldn't have been a buy signal at all, meaning there won't now be any condition to look for for a sell signal. Some alternate sell signal may be needed for protection in this case.

And when you back test and look at all the buy and sell points, they may not match where the final trend line signals would be, as the trend lines may have moved since those particular signals were generated.

Recalculating trend line history for every day can be pretty slow though, making back tests take a long time.

Cheers,
GP
 
GP in systems tests the software will look for a true condition and as systems tests are on past history then the peaks and troughs are no longer dynamic except of course for the current one.
You'll get the results but they will not reflect live trading.
 
tech/a said:
then the peaks and troughs are no longer dynamic
They don't have to be. All that is required is that buy and sell signals be based on trend lines as they would have been placed on each particular day ignoring all future data, which mimics live trading (on an EOD basis of course). How they change on subsequent days doesn't matter, except as mentioned before where a trend line changes after a buy signal so as to remove the buy indication. That's what I meant about having to recalculate the trend lines for every day.

This is exactly what I do in my AmiBroker trend line plugin, and why backtests are so slow.

Cheers,
GP
 
You can use zigzag for signals, BUT, you must allow for the retracement to have occured. Once the retracement % has been made then the last peak or trough point is fixed and can be used. In my own coding for zigzag I call this the CreateTrough (CTB) and CreatePeak (CPB) bar. backtesting can then be done provided you always specify the the barssince the CTB or CPB is less than the barssince the respective trough or peak
 
Thanks for all the input peeps,

I was playing around last night and i am having problems finding the right indicators to use to take advantage of possible trades. I intially started using moving average cross overs where the fast crosses the slow would indicate a potential entry point.

What i found though was when i reviewed the report and then when to that particular time on the chart there may have been another two or three opportunities to do a trade but the system didnt pick it up. I then thought maybe if i add a price and volume increase into the entry criteria but so far have not been happy with the results. also the more entry criteria i add the harder to actually find the entry points, on a couple of runs i ran it from 04 through to present and it didnt pick up one trading opportunity (asx200).

I suppose its just a matter of trying different combinations and seeing what works the best, theres just so many indicators and i dont have a clue about half of em :confused:

At the moment i am papertrading successfully mainly using trend lines and a couple of basic indicators but trying to get the system to do that is harder than i thought it would be.

Cheers All
Stink
 
Trend lines are particularly difficult to use in an automated system as their placement is tricky and time-consuming to calculate. Moving averages are considerably easier, but of course have time lag.

I think you'll find that it will be difficult to find a good system based on simple moving average crossovers, otherwise everyone would be doing it already.

Cheers,
GP
 
GP and Kave.

Thanks.
Must be "easier" to do in Ami.
Nigh impossible in Metastock
 
Magdoran said:
As for the May pull back, using technical analysis, many people identified that the trend was at risk, and had exited their longs by the end of April (I certainly did). The more aggressive players actually went short, or entered a sideways strategy… that’s the advantage of not using lagging indicators.
Hi Magdoran,

Just picked up this statement in an earlier post of yours. I'm a not-very-good trader who didn't identify that the trend was at risk - apart from having a sort-of gut feeling that things were moving too fast - so I'm keen to know how others made that judgement. Would you care to elucidate? (Of course, if you don't wish to reveal any of your own "proprietary" methods, that's fine too!)

Cheers, Staybaker. :)
 
Tech I wrote my own code for zigzag which allows me much greater flexibilty and control than built in zigzag function. eg built in is just single array (eg high to High), and percent change
I can do dual array (eg High to Low), percent/point/array reversals (eg reversal using multiple of ATR)
Also allows me to properly build into a trading system
 
Originally Posted by Staybaker

Quote:
Originally Posted by Magdoran
As for the May pull back, using technical analysis, many people identified that the trend was at risk, and had exited their longs by the end of April (I certainly did). The more aggressive players actually went short, or entered a sideways strategy… that’s the advantage of not using lagging indicators.

Hi Magdoran,

Just picked up this statement in an earlier post of yours. I'm a not-very-good trader who didn't identify that the trend was at risk - apart from having a sort-of gut feeling that things were moving too fast - so I'm keen to know how others made that judgement. Would you care to elucidate? (Of course, if you don't wish to reveal any of your own "proprietary" methods, that's fine too!)

Cheers, Staybaker.


Hello Staybaker,


That’s actually quite a hard question to answer. You know, I think there is a skill in asking the right questions (like the one you’ve just posed), and quite a skill to answer these (trying to answer this is a daunting task), and quite another to actually know what you are talking about and be able to express it so other people can understand the concept.

Judging by the array of moving average/back testing methods populating this thread, my approaches will probably be as alien as speaking a foreign language to the majority of readers.

My perspective of technical analysis is that it is more art than science, and that interpreting charts is more akin to appraising fine art, while forecasting future events involves imagination (for how future events may unfold), and an appreciation for pattern recognition (including recognising subtle shifts which may give clues that larger changes are imminent).

It’s a bit like being an actuary for an insurance company. You have to look at macro trends, and assess the risk of different potential events. I was involved in enterprise IT projects in the past, and was involved in the development of risk management systems for complex deployments into the government. An aspect of this involved making project estimates to price for tenders, and establishing risk management approaches.

So, having said that, here is the core answer: I was using a version of Gann based time forecasting. The analysis was based on the pattern of trend, (which encompassed both the shorter 180 calendar day drive, and the whole bullish campaign from 2003). This also involved using a division of the range projected up to forecast levels of resistance in price.

Partly I was looking at the wave structure (a Gann/Prechter-Frost/R.N. Elliott hybrid of Elliott Wave theory with some embellishments), and how it had moved in time and price over the last 20 years, and looked at how blow off moves tend to trend and what they look like. What I (and others of my ilk) concluded was that the probabilities favoured a “topping pattern”.

I got the time point wrong though, the projected top was for the 19th of April (interestingly I had made this projection independently, and others came in with the same date, but by different methods), but there was an extension for a marginal high above the projected date (actually it was about a quarter extension in time of a square of 90 in hindsight, but there was no way I was capable of forecasting this was going to happen on this day with my methods, but I did know from the pattern and time and price that the trend was at risk).

The time cycles certainly lined up once the top was clearly identified, exactly 360 calendar days from the key higher low on 17th May 2005. My approach is not to try to trade major highs and lows, I try to ride the trends and counter trends once I can measure either time, price (preferably both), wave structure, and primarily see a pattern that I can trade with reasonable accuracy in time and price. Hence I just stay out of the market during times when I can’t make high probability forecasts.

So, I just sat out watching the pattern of trend when the major high came in for a few days, looking at the bars and volume (volume can confirm or throw doubt on certain patterns – where high or low volume can tell a lot about what’s going on ). I was also trying to see potential wave structures forming, looking at “harmonic price ranges” for support/resistance, looking for dominant time cycles in daily weekly and monthly charts…

Add to this the backdrop of looking at the related indexes and stocks too with the same analysis… Forex, commodities, international indexes, bond rates etc etc - all with full analysis as suggested above, then a process of factoring the probabilities for all of these into the potential way the XAO may behave.

For instance, for me to trade BHP, several factors will effect the way it trends above it’s own vibration – futures prices in metals, crude oil, fuels (like Hu-spotV), currency cross rates (like US-Australian Dollar, Euro – US, Yen-US, etc), other price movement in overseas markets for BHP, indirectly – US bond rates, etc etc. So I actively forecast for all of these in time and price. If any deviate from these projections, I have to revise my projections.

So, my price and time targets in the trading plan actually can be modified if a key factor moves beyond tolerance (so there is a two level approach to the plan – the core plan, and the ability for exception handling for unfavourable events). A classic example would be the fall in copper prices recently which would trigger a partial or full exit from a long position depending on the magnitude.

As you can imagine, there is a lot more to this than I have covered, but that’s essentially it… hope it made sense!



Regards


Magdoran
 
Woops, it was actually 358 days from the low, not 360 - I had the time cycle noted on the chart, but the actual high came in 2 days earlier...
 
Magdoran,

Wow. Thanks. I won't pretend to understand all that ... but I'll have fun trying!

Cheers, Staybaker. :)
 
Tech/a
TradeStation can do trend line trading systems. The following chart shows automatic trend lines drawn in basis input criteria. Below that is a trading system that uses trend line breakouts.


autotrend9lz.gif


Input: TrendLen(20);

VALUE1=@MOMENTUM(C,3);
VALUE2=@MOMENTUM(C,3)[1];
VALUE3=0.3*(VALUE1-VALUE2)+(1-0.3)*VALUE3;
VALUE4=WAVERAGE((VALUE3),6);
VALUE5=@RSI(C,9)+VALUE4;

{ Determine then beginning and ending points of an Upward Trend Line. }

Value6 = SwingLowBar(1,Low,3,TrendLen);
Print("Date: ",Date:0:0," Time: ",Time:4:0," SwingLowBar 1st# = ",Value6:2);
If Value6 > -1 then begin
Value7 = SwingLowBar(1,Low,3,TrendLen)[Value6];
Print("Date: ",Date:0:0," Time: ",Time:4:0," SwingLowBar 2nd# = ",Value7:2);
If Value7 > -1 then begin
Value8 = TLValue(Low,Value6,Low,Value7,-1);
Print("Date: ",Date:0:0," Time: ",Time:4:0," Trend Line UP = ",Value8);
End;
End;

{ Determine then beginning and ending points of a Downward Trend Line. }

Value9 = SwingHighBar(1,High,3,TrendLen);
Print("Date: ",Date:0:0," Time: ",Time:4:0," SwingHighBar 1st# = ",Value9:2);
If Value9 > -1 then begin
Value10 = SwingHighBar(1,High,3,TrendLen)[Value9];
Print("Date: ",Date:0:0," Time: ",Time:4:0," SwingHighBar 2nd# = ",Value10:2);
If Value10 > -1 then begin
Value11 = TLValue(High,Value9,High,Value10,-1);
Print("Date: ",Date:0:0," Time: ",Time:4:0," Trend Line DN = ",Value11);
End;
End;

{ Breakout of a Downward Trend Line. }
CONDITION1=SLOWD(9)[1]<SLOWD(9);
CONDITION2=VALUE4[1]<VALUE4;
CONDITION3=VALUE5[1]<VALUE5;
CONDITION4=VALUE5>50;
CONDITION5=Close>Value11;

{ Breakout of an Upward Trend Line. }
CONDITION6=SLOWD(90)[1]>SLOWD(9);
CONDITION7=VALUE4[1]>VALUE4;
CONDITION8=VALUE5[1]>VALUE5;
CONDITION9=VALUE5<50;
CONDITION10=Close<Value8;

If Value9 < Value6 and Value10 < Value7 then begin
IF {CONDITION1 AND CONDITION2 AND CONDITION3 AND CONDITION4 AND} CONDITION5 THEN BUY ON CLOSE;
End;

If Value9 > Value6 and Value10 > Value7 then begin
IF {CONDITION6 AND CONDITION7 AND CONDITION8 AND CONDITION9 AND} CONDITION10 THEN SELL ON CLOSE;
End;
 
Hi Stink, and the others who have contributed to this thread

I'm also going through the process of developing a system and looking for ways to back test it - I've also been looking through this forum for a while for just this reason and decided to join today when I found this thread.

The charting system I have does not have a back-testing facility; I may look into Amibroker as it seems to get a good wrap.

I look forward to joining in on and reading other threads; this is really a great forum.

Cheers
rubles
 
Rubles, have a look here
http://www.spacejock.com/
FCharts Pro is what I use, but you can get the free version which also has a trade tester and stock scanner.
You enter your formulae into two areas (four with the pro version), and it plots out green and red dots on the chart for entry and exits.

They have a forum which discusses formulae and general usage of FCharts.
IMHO it's an awesome charting program. Locally developed and supported.
The pro version is only a couple of hundred bucks and well worth it.
 
For those who use AmiBroker, do you also use MarketCast data? I was going to go AmiBroker until I realised you can only get realtime data for it via SBS TV signal. No good for when I'm roaming around... Where did you get historical ASX data from?

Might trial MetaStock. Been using The Bourse / Bourse Scan for a while but it's not as clean as AmiBroker and MetaStock.

Also, for those who use TradeStation, does it support ASX data? I can't find any info on data sources...
 
Top