Australian (ASX) Stock Market Forum

Developing a mechanical system from scratch

PDZ looks the goods.
A good example of what may happen to a stock after 3 inside days.
 

Attachments

  • pdz0206.gif
    pdz0206.gif
    9.3 KB · Views: 333
Not sure how to attach the file Niz, any suggestions?
 
Just mucking about with this on my futures data, the buy signals on index's seem to work pretty good....is this a bit strange?

Here's one for Prof.
Cheers,
 

Attachments

  • HG LESM3.jpg
    HG LESM3.jpg
    81.8 KB · Views: 219
What AB backtester setings everyone using ? this way everyone with Amibroker will be on the same page.
 
Hi Tech/A

Not sure if this is what you had in mind ... this is an indicator I put together today which plots an equity curve of a system in Metastock.

I make no claim to the accuracy of the coding, and this should be reviewed and checked for errors.

I recommend ploting the indicator, saving it has a default template, and moving it across the ASX20.

{SHORT TERM SYSTEM - EQUITY CURVE v1}
{NOTE - BUY/SHORT ON OPEN AND SELL/COVER ON CLOSE}

ps:=Input("$Position Size: ",1,1000000,10000);
con:=ps/OPEN;
pv:=Input("Leverage: 0-100%",1,100,10);
pv:=100/pv;
sp:=Input("Start Periods: ",1,2500,1250);
stop:=Input("Place Stop (0 = no stop): ",0,100,0);
coms:=Input("round trip Commission: ",0,1000,40);
signals:=Input("Signals: Buy (1) Short (2) All (3)",1,3,3);

{LONG}
LE:=OPEN > Ref(HIGH,-1) AND (Ref(HIGH,-1)-Ref(LOW,-1)) < (Ref(HIGH,-2)-Ref(LOW,-2)) AND (Ref(HIGH,-2)-Ref(LOW,-2)) < (Ref(HIGH,-3)-Ref(LOW,-3)) AND
(Ref(HIGH,-3)-Ref(LOW,-3)) < (Ref(HIGH,-4)-Ref(LOW,-4));
LPnostp:=CLOSE - OPEN;
LPstp:=If(OPEN-LOW > stop,-1*stop,CLOSE-OPEN);
LP:=If(stop=0,LPnostp,LPstp);
LP:=If(LE,con*pv*LP-coms,0);
LcP:=Cum(LP); {Long Cumulative Profit}
Zero:=ValueWhen(1,Cum(1)=LastValue(Cum(1))-sp,LcP);
LcP:=LcP-Zero;

{Short}
ShE:=OPEN < Ref(LOW,-1) AND (Ref(HIGH,-1)-Ref(LOW,-1)) < (Ref(HIGH,-2)-Ref(LOW,-2)) AND (Ref(HIGH,-2)-Ref(LOW,-2)) < (Ref(HIGH,-3)-Ref(LOW,-3)) AND
(Ref(HIGH,-3)-Ref(LOW,-3)) < (Ref(HIGH,-4)-Ref(LOW,-4));
ShPnostp:=OPEN-CLOSE;
ShPstp:=If(HIGH - OPEN > stop,-1*stop,OPEN-CLOSE);
ShP:=If(stop=0,ShPnostp,ShPstp);
ShP:=If(ShE,con*pv*ShP-coms,0);
ShcP:=Cum(ShP); {Short Cumulative Profit}
ShZero:=ValueWhen(1,Cum(1)=LastValue(Cum(1))-sp,ShcP);
ShcP:=ShcP-ShZero;

{Signals}
If(signals=1,Lcp,If(signals=2,ShcP,Lcp+ShcP));
0;
 
Weird.

Excellent.
I can cut what I need from there to then place in Tradesim.
Thanks for the Equity Curve and others may find it useful,but Tradesim does all that.
Think I can follow what I need.
Wish I had that talent!

Next some exit suggestions then I can test some.
 
I would think with these types of systems, that stock selection is very imporant, and the system may not perform well on a general index based watchlist, without additional filtering.

As an example of a stock that it performs well on is BHP.

Also I went abit overboard with defining the narrowing range, the following is more in line with the discussion,

LE:=OPEN > Ref(HIGH,-1) AND (Ref(HIGH,-1)-Ref(LOW,-1)) < (Ref(HIGH,-2)-Ref(LOW,-2)) AND (Ref(HIGH,-2)-Ref(LOW,-2)) < (Ref(HIGH,-3)-Ref(LOW,-3));

ShE:=OPEN < Ref(LOW,-1) AND (Ref(HIGH,-1)-Ref(LOW,-1)) < (Ref(HIGH,-2)-Ref(LOW,-2)) AND (Ref(HIGH,-2)-Ref(LOW,-2)) < (Ref(HIGH,-3)-Ref(LOW,-3));
 
Nick,

Thanks for your input and guidance much appreciated, as well as the benchmark.

Keeping it simple as per your example is always a good approach.

NR4 and HV were the first things that came to mind when looking at the pattern and charts.

Weird,

Good to see your input and sure it will be appreciated.

Can,

This exercise will be useful to different people in different ways and everyone should get something out of it at the end of the day. You may like to thing about trying out ASXG's looping example as an alternative approach. A good way to learn more about AB, especially AFL.

Anyone,

Any suggestions with respect to exits, as this is a community exercise.

As per Nick's reference/benchmark, can buy on Open, hold it overnight and exit next day on Open, as one option.

Trying different exits can provide an idea of how it may perform/behave over different holding periods.
 
Having thought about some of the things said during this morning's presentation, I just put this following together and put it on a few charts.

Code:
Ref(C,-1)<O AND Ref(V,-1)> (2*Ref(Mov(V,13,E),-1)) AND C>Ref(C,-1) AND ( Ref(H,-1)-Ref(L,-1))< Ref(Mov(H-L,13,E),-1);

I've plotted it against a few charts (chuck it in expert advisor in MS) and it looks promising for about 30s of work.

First observation is that it doesn't appear to generate many signals.
 
Now I've had a little more of a play with it, by changing the volume condition it generates more signals without too much extra noise.

But I would keep the multiplier higher than 1.5 or it begins to become worthless...
 
Here's it plotted against IAG for those still converting it to Ami.
 

Attachments

  • IAG.jpg
    IAG.jpg
    69.2 KB · Views: 220
This is doing my head in!!!!:banghead:

I can't get it to buy on the next bar after the insidedaycond.

It keeps buying on inside bar 1.....

Enough for tonite...my GF and i have been trying to figure it out....she's catching onto AFL faster than me.

Cheers,

Can,

You may have got this solved by now, but as far as I can see, the reason that you think that you are buying on the wrong bar is because of the position of the arrow in your chart (which I presume is generated with a plotshape command). If that is the case, the arrow in the chart would indicate when the buy criteria is triggered, which is a different kettle of fish to when the trade will actually take place.

This is where lesm's comment regarding the settradedelay command comes in.
SetTradeDelays( 1, 1, 1, 1) implies that you physically enter the trade (long) one day after the buy criteria is triggered and similarly exit the trade one day after the sell criteria is triggered.

In order for you to actually see when the trades physically take place, you need to back test the strategy, whereupon you will receive a trade list. Select any of those trades in the tradelist, right-click any trade and select "show current trade arrow" and you'll see exactly when the trade was entered into and exited from -- which should be exactly as per your expectation.

Just to take this discussion a little further, if you were to implement Nicks strategy with a one day hold, there are several ways to implement that in Amibroker, but I have found that the easiest is simply to set the sell signal to be the same as the buy signal, but set the sell trade delay to 2 days, ie.

SetTradeDelays( 1, 2, 1, 1);
buyprice=open;
sellprice=open;

buy = .....
sell = buy;

That way, your system is set to enter the trade one day after the buy criteria (on the open) and exit the trade the next day (also on the open)

PS, You're doing a great job - keep it up. Others will try to chip in whenever they can.
 
I have been following along more out of curiosty than anything else but it would seem that if you are going for a swing trade system wouldn't you rather want to base your exits on something other than a one day hold? I believe that Nick knows more about trading the stock market than I do and would venture to say that most of the poster here also are better equipped to comment, but I thought that swing trading was used to catch the move up or down of a stock over several days and at the first hint of failure of the stock to perform to it's potential is when your exit stratagey would kick in and take you out of the play be it 1 day or 1 month. Just an observation over the last couple of days of posting good luck in your journey, I will continue to follow along.

Disq
 
Can,

You may have got this solved by now, but as far as I can see, the reason that you think that you are buying on the wrong bar is because of the position of the arrow in your chart (which I presume is generated with a plotshape command). If that is the case, the arrow in the chart would indicate when the buy criteria is triggered, which is a different kettle of fish to when the trade will actually take place.

This is where lesm's comment regarding the settradedelay command comes in.
SetTradeDelays( 1, 1, 1, 1) implies that you physically enter the trade (long) one day after the buy criteria is triggered and similarly exit the trade one day after the sell criteria is triggered.

In order for you to actually see when the trades physically take place, you need to back test the strategy, whereupon you will receive a trade list. Select any of those trades in the tradelist, right-click any trade and select "show current trade arrow" and you'll see exactly when the trade was entered into and exited from -- which should be exactly as per your expectation.

Just to take this discussion a little further, if you were to implement Nicks strategy with a one day hold, there are several ways to implement that in Amibroker, but I have found that the easiest is simply to set the sell signal to be the same as the buy signal, but set the sell trade delay to 2 days, ie.

SetTradeDelays( 1, 2, 1, 1);
buyprice=open;
sellprice=open;

buy = .....
sell = buy;

That way, your system is set to enter the trade one day after the buy criteria (on the open) and exit the trade the next day (also on the open)

PS, You're doing a great job - keep it up. Others will try to chip in whenever they can.

Thanks allot Bingk6....i'm so new with Amiborker, but all this really helps me learn...i hope a few others are learning along with me...and that was the whole purpose of this thread.

I've tried a few things on the weekend, but the inet has been so slow i haven't tried to post much, i hope it improves at least enough to get my orders through in the morning...or i'll be on the phone again!

I'll try all these things tomorrow hopefully...keep the good stuff coming folks!

Thanks again everyone for all your help!

Cheers,
 
Can,

Have you been able to understand and convert the metastock code?

Weird uses a good style and his code is easy to follow.

"LE" = Long Entry

Substitute "Buy =" in AB

"ShE" = Short Entry

Substitute "Short =" in AB

From Doc's code:

"(2*Ref(Mov(V,13,E),-1))" converts to "(2*Ref(EMA(V,13),-1))"

"Ref(Mov(H-L,13,E),-1)" converts to "Ref(EMA(H-L,13),-1)"

It usually straightforward to convert most Metastock to AB or vice versa.

Ran some tests using weird and doc's code last night. Picked up a couple of illiquid stocks using the volume test of doc's. Doc made a comment related to the multiplier when he posted the code.

Let us know when you are ready Can and we can do some more work on this exercise. Hope your Internet conenction gets sorted out. Raise any questions that you may have along the way, as you can see there is always someone around who can help out.

Cheers.
 
My code's rough, but I see it as a starting point - we can filter for volume and the like easily.
 
wouldn't you rather want to base your exits on something other than a one day hold?

disqplay,
Valid question and conclusion. When testing, especially on Australian stocks since 1980, you will find very quickly that the longer you hold, the better the result, the less the work, the less comm's and less the stress. However, Longer term exposure, even out to a few months in length, also increases exposure to the market and increased exposure also increases risk.

Which situation is better:

(a) Net profit 20% pa. Exposure 100%
or
(b) Net profit 18% pa. Exposure 50%

The answer is different for everyone. Some are less risk adverse. Others just want the highest profits.

The other issue to consider is why just use a longer term system only? Why not have a shorter term system plugging away in the background as more of an income generator? A longer term system attemts to swing for the fences. A shorter term system requires less capital and just chips away.

Here is an equity curve of a simple pattern system that would take less than 5-mins a day to run. It trades 4 Australian stocks and using CFD's you could trade it with ease on 1 $10,000 account. This is 8-years worth incl comm's and no pyramiding. The "Open" or "Close" represent exiting on the next days open or the next days close. Having one of these ticking over in the background and it could pay your salary whilst the longer term system looks after the rest.

combotg0.png
 
I thought that swing trading was used to catch the move up or down of a stock over several days and at the first hint of failure of the stock to perform to it's potential is when your exit stratagey would kick in and take you out of the play be it 1 day or 1 month.

I think the answer to that is, it depends. If you have a profit target and a tight initial stop, you may decide not to use a trailing stop.
 
Top