dlucas
22nd August 2006, 07:46 AM
I am having a few difficulties in the timing of entry signals. I am looking at a system that when backtested with TradeSim gives solid (although not astonishing) results over 10-15 years of data and hundreds of stocks.
Initially I created this as a system that generates a signal based on the close and then also buys at the close. While in reality you could probably achieve something like this - by buying several minutes before the close if the signal had already been generated during the trading day - a more realistic and less demanding approach would be to test the system on the assumption that you buy at the open of the following day.
If this were a moving average system one way to implement it might be this:
EntryTrigger := Cross(Mov(C,10,S),Mov(C,20,S));
EntryPrice := Ref(OPEN,1);
ExitTrigger := Cross(Mov(C,20,S),Mov(C,10,S));
ExitPrice := Ref(OPEN,1);
As you can see, I am using Ref() to point into the "future" so that if the buy signal occurred during backtesting on 1 Jan 2002, the entry is on 2 Jan 2002. This approach gives results that are very similar to those of the "buy at close" system, which is what I would expect, because the open of the following day does not appear to be consistently higher or lower than the close of the day a signal is generated.
However, a more natural approach (to my mind anyway) would be to use Ref() on the signal, which in this example is the moving average, rather than on the entry price. So, I take the MAs for the previous day (yesterday) and see if they cross, then buy at the open of the next day (today). This is how I implemented it:
EntryTrigger:=Cross(Ref(Mov(C,10,S),-1),Ref(Mov(C,20,S),-1));
EntryPrice:= OPEN;
ExitTrigger:= Cross(Ref(Mov(C,20,S),-1),Ref(Mov(C,10,S),-1));
ExitPrice:= OPEN;
When I tried this latter formulation I got some very strange results. Basically, the system - which was profitable previously - was useless. Not only that but it generated an equity curve that, for the same data, seems to be the inverse of that generated by the profitable system. It looks almost as if the system is selling on buy signals. Yet when I look at the above syntax it still seems correct to me.
I suspect that there is an apparently small but fundamental mistake in the way I am approaching this that is causing the problem, but can anybody suggest what it might be? Failing that, can anybody reassure me that the first approach using ref(open,1) for the entry price is conceptually sound?
Regards
Dan
Initially I created this as a system that generates a signal based on the close and then also buys at the close. While in reality you could probably achieve something like this - by buying several minutes before the close if the signal had already been generated during the trading day - a more realistic and less demanding approach would be to test the system on the assumption that you buy at the open of the following day.
If this were a moving average system one way to implement it might be this:
EntryTrigger := Cross(Mov(C,10,S),Mov(C,20,S));
EntryPrice := Ref(OPEN,1);
ExitTrigger := Cross(Mov(C,20,S),Mov(C,10,S));
ExitPrice := Ref(OPEN,1);
As you can see, I am using Ref() to point into the "future" so that if the buy signal occurred during backtesting on 1 Jan 2002, the entry is on 2 Jan 2002. This approach gives results that are very similar to those of the "buy at close" system, which is what I would expect, because the open of the following day does not appear to be consistently higher or lower than the close of the day a signal is generated.
However, a more natural approach (to my mind anyway) would be to use Ref() on the signal, which in this example is the moving average, rather than on the entry price. So, I take the MAs for the previous day (yesterday) and see if they cross, then buy at the open of the next day (today). This is how I implemented it:
EntryTrigger:=Cross(Ref(Mov(C,10,S),-1),Ref(Mov(C,20,S),-1));
EntryPrice:= OPEN;
ExitTrigger:= Cross(Ref(Mov(C,20,S),-1),Ref(Mov(C,10,S),-1));
ExitPrice:= OPEN;
When I tried this latter formulation I got some very strange results. Basically, the system - which was profitable previously - was useless. Not only that but it generated an equity curve that, for the same data, seems to be the inverse of that generated by the profitable system. It looks almost as if the system is selling on buy signals. Yet when I look at the above syntax it still seems correct to me.
I suspect that there is an apparently small but fundamental mistake in the way I am approaching this that is causing the problem, but can anybody suggest what it might be? Failing that, can anybody reassure me that the first approach using ref(open,1) for the entry price is conceptually sound?
Regards
Dan