InvestorsHub Logo
icon url

Vesselin

09/04/02 6:26 AM

#108 RE: Tom K #107

Testing the clarified system

I believe your second interpretation is what I had in mind.

I suspect that there is still a bit of misunderstanding, because your next words seemingly contradict the above. :-)

If the Aroon is below -50, the CCI must cross above -200 AND -100 to generate a buy signal. The rule dictates that the CCI must be below -200 (at some point) when the Aroon is in the -50 state. If a signal isn't triggered, and the Aroon moves above -50, the CCI only needs to cross above -100.

See, that's the problem. What does "wait until" mean exactly?

Suppose that today the system is out of the market. You check the AroonOsc. If it is not below -50, things are simple - you Buy if CCI has crossed above -100 and you don't if it hasn't. But what if today AroonOsc is below -50? OK, you check the CCI. If it has not crossed below -200 yet, everything is fine for today - you do nothing.

But what do you do tomorrow? Do you perform exactly the same checks from the start? Or do you, since the AroonOsc has already fallen below -50, only check the CCI from now on and monitor it until it falls below -200 and then rises above -100?

What happens if, while you are waiting for that to happen, AroonOsc moves back above -50? Do you ignore it - or do you then stop monitoring the CCI for falling below -200 first and start again to monitor it for just rising above -100?

I am sorry if I am not expressing myself clearly enough and/or if I am not understanding what you are saying - but please keep in mind that I am not a native English speaker (English is not only not my first language - it's not even my second language) and one needs to understand the rules very precisely, in order to program them correctly in a computer. Computers can't guess what you could have possibly meant - you have to tell them very explicitly what exactly you want done and how.

Since you said that you meant my second interpretation, that's why I have implemented (once the AroonOsc drops below -50, start waiting for the CCI to cross below -200 and then above -100, no matter what the AroonOsc does meanwhile) - but I am still not sure (because of your words above) that this is really what you meant originally.

Cover shorts on any subsequent buy rule.

Very well; I have implemented Short trading rules, too. Also switched to 5% stop-loss.

The system would have been whipsawed using 10% stops. Do more agressive stops (5%) make sense?

The size of the stops doesn't matter, if the problem is that the system keeps trying to buy into downtrends. If you put a large stop, you'll simply lose one big sum of money in one chunk. If you put a small stop, the system will get stopped out much earlier, but it will try to buy almost immediately again - so, you'll lose essentially the same amount of money in multiple consecutive losing trades. The problem has to be fixed by making the system not buy into severe downtrends before they have clearly bottomed - not by adjusting the stop-loss.

The stop-loss has to be adjusted when the system whipsaws. That is, when it enters a trade at the wrong moment, the market goes against it for some time, but after a while reverses and the trade ends up a winner. A too tight stop here is likely to take the system out of the trade too early and at a loss - instead of letting the trade eventually win.

In general, it is a good idea to initially develop a system without stops and make sure that it enters trades at the right moment and exits them at reasonable place, too. Only then you could try to improve the performance by placing stop-losses (provided that the system isn't likely to re-enter the trade almost immediately) and trailing stops (to take profits).

Humor me Vess, can you run the test one more time using the rules I described above?

Certainly, I'm glad to help. Here is what the latest implementation does when trading the COMPX. The performance is better than before - but the percentage of winning trades is much lower, too, and the system trades more often. Exact transcript of the trades follows (thanks to oeo2oo for teaching me how to use pre-formatted text here); the system assumes trading $5,000 positions (i.e., no compounding):

 
Pos. Shares Entry Date Entry At Exit Date Exit At % Change Net Profit Held Profit/Bar Buy Sig Sell Signal Cum Profit
Long 17 16-Oct-1985 285.70 31-Mar-1987 427.80 49.33 2,395.72 367 6.53 Buy Sell Higher 2,395.72
Long 15 27-Nov-1987 317.20 03-Dec-1987 301.34 -5.42 -257.88 4 -64.47 Buy Stop Loss 2,137.84
Short 16 04-Dec-1987 295.80 09-Dec-1987 299.40 -1.64 -77.58 3 -25.86 Short Cover & Buy 2,060.26
Long 16 09-Dec-1987 299.40 28-Mar-1988 369.00 22.83 1,093.62 75 14.58 Sell Higher 3,153.88
Long 13 02-Dec-1988 373.10 27-Feb-1989 398.40 6.37 308.92 58 5.33 Buy Sell Higher 3,462.80
Long 11 09-Nov-1989 454.70 19-Dec-1989 431.97 -5.40 -270.06 27 -10.00 Buy Stop Loss 3,192.73
Long 11 28-Dec-1989 448.60 24-Jan-1990 419.90 -6.80 -335.68 18 -18.65 Buy Stop Loss 2,857.05
Long 11 16-Feb-1990 430.00 26-Jun-1990 457.60 6.00 283.62 89 3.19 Buy Sell Higher 3,140.67
Short 11 06-Aug-1990 403.70 23-Oct-1990 340.40 15.23 676.32 55 12.30 Short Cover&Buy Lower 3,816.99
Long 14 23-Oct-1990 340.40 20-Mar-1991 462.21 35.37 1,685.36 102 16.52 Sell Higher 5,502.35
Long 8 10-Apr-1992 590.59 28-Apr-1992 561.06 -5.42 -256.22 11 -23.29 Buy Stop Loss 5,246.14
Long 8 06-May-1992 589.86 17-Jun-1992 560.37 -5.42 -255.92 29 -8.82 Buy Stop Loss 4,990.21
Long 8 01-Jul-1992 563.73 24-Sep-1992 584.47 3.24 145.94 59 2.47 Buy Sell Higher 5,136.15
Long 7 23-Apr-1993 661.47 09-Jun-1993 687.00 3.43 158.73 32 4.96 Buy Sell Higher 5,294.88
Long 6 04-May-1994 739.38 23-Jun-1994 702.41 -5.45 -241.79 35 -6.91 Buy Stop Loss 5,053.09
Short 7 24-Jun-1994 699.78 13-Jul-1994 710.88 -1.99 -97.68 12 -8.14 Short Cover & Buy 4,955.41
Long 7 13-Jul-1994 710.88 23-Sep-1994 759.88 6.49 323.02 51 6.33 Sell Higher 5,278.43
Short 6 25-Nov-1994 737.22 28-Nov-1994 743.08 -1.25 -55.14 1 -55.14 Short Cover & Buy 5,223.29
Long 6 28-Nov-1994 743.08 10-Apr-1995 814.44 9.16 408.18 92 4.44 Sell Higher 5,631.47
Long 4 20-Dec-1995 1,032.51 16-Jan-1996 980.88 -5.48 -226.48 17 -13.32 Buy Stop Loss 5,404.99
Long 4 22-Jan-1996 1,019.72 05-Mar-1996 1,084.24 5.84 238.10 30 7.94 Buy Sell Higher 5,643.09
Long 4 05-Aug-1996 1,127.91 24-Sep-1996 1,210.96 6.92 312.22 35 8.92 Buy Sell Higher 5,955.31
Long 4 10-Apr-1997 1,248.31 23-May-1997 1,377.73 9.97 497.70 31 16.05 Buy Sell Higher 6,453.01
Long 3 17-Nov-1997 1,601.95 15-Dec-1997 1,521.85 -5.42 -260.27 19 -13.70 Buy Stop Loss 6,192.74
Long 3 31-Dec-1997 1,565.87 12-Jan-1998 1,482.01 -5.78 -271.56 7 -38.79 Buy Stop Loss 5,921.18
Long 3 14-Jan-1998 1,549.80 08-Apr-1998 1,801.11 15.79 733.95 58 12.65 Buy Sell Higher 6,655.13
Long 2 18-Jun-1998 1,776.35 28-Jul-1998 1,931.83 8.19 290.98 27 10.78 Buy Sell Higher 6,946.11
Long 2 17-Sep-1998 1,646.19 05-Oct-1998 1,563.88 -5.61 -184.60 12 -15.38 Buy Stop Loss 6,761.51
Long 3 16-Oct-1998 1,625.24 10-Feb-1999 2,304.25 41.37 2,017.05 79 25.53 Buy Sell Higher 8,778.56
Long 1 01-May-2000 3,930.18 03-May-2000 3,733.67 -5.51 -216.49 2 -108.24 Buy Stop Loss 8,562.07
Long 1 08-May-2000 3,758.46 09-May-2000 3,570.54 -5.53 -207.90 1 -207.90 Buy Stop Loss 8,354.16
Long 1 17-May-2000 3,649.54 19-May-2000 3,467.06 -5.55 -202.46 2 -101.23 Buy Stop Loss 8,151.71
Long 1 01-Jun-2000 3,471.95 07-Sep-2000 4,047.02 15.99 555.09 68 8.16 Buy Sell Higher 8,706.80
Short 1 25-Sep-2000 3,852.53 26-Sep-2000 3,762.65 1.81 69.90 1 69.90 Short Cover & Buy 8,776.70
Long 1 26-Sep-2000 3,762.65 02-Oct-2000 3,574.52 -5.53 -208.11 4 -52.03 Stop Loss 8,568.58
Short 1 09-Nov-2000 3,174.90 11-Oct-2001 1,649.55 47.41 1,505.37 227 6.63 Short Cover&Buy Lower 10,073.96
Long 3 11-Oct-2001 1,649.55 14-Dec-2001 1,945.18 17.52 866.91 45 19.26 Sell Higher 10,940.87
Short 2 20-Feb-2002 1,762.43 04-Mar-2002 1,850.55 -5.57 -196.22 8 -24.53 Short Stop Loss 10,744.64
Long 2 05-Mar-2002 1,854.71 08-Apr-2002 1,741.10 -6.66 -247.20 23 -10.75 Buy Stop Loss 10,497.44
Long 2 17-Apr-2002 1,829.58 23-Apr-2002 1,738.10 -5.55 -202.94 4 -50.73 Buy Stop Loss 10,294.50
Short 2 24-Apr-2002 1,739.13 15-May-2002 1,705.45 1.36 47.38 15 3.16 Short Cover & Buy 10,341.88
Long 2 15-May-2002 1,705.45 30-May-2002 1,613.42 -5.98 -204.04 10 -20.40 Stop Loss 10,137.84


I'm not practiced in writing scripts.

Not a problem. Have you tried at least entering the script at the Wealth-Lab Web site? It would allow you to experiment with different indexes and stocks - even if you don't know how to modify the script to change its behaviour.

Anyway, here is the modified WealthScript implementation.

Regards,
Vesselin

 
const AroonPeriod = 200;
const AroonHigh = 50;
const AroonLow = -50;
const Neutral = 0;
const CCIPeriod = 80;
const CCILow = -100;
const CCILower = -200;
const CCIHigh = 100;
const CCIHigher = 200;
const StopLoss = 5;

var AroonPane, CCIPane, AroonOsc, MyCCI : integer;
var Bar, StartBar, EndBar, BuyState, SellState : integer;

HideVolume;

CCIPane := CreatePane(60, False, True);
SetPaneMinMax(CCIPane, CCILower - 10, CCIHigher + 10);
MyCCI := CCISeries(CCIPeriod);
PlotSeries(MyCCI, CCIPane, #Black, #Thick);
DrawHorzLine(CCILow, CCIPane, #Red, #Thin);
DrawHorzLine(CCILower, CCIPane, #Red, #Thick);
DrawHorzLine(Neutral, CCIPane, #Red, #Dotted);
DrawHorzLine(CCIHigh, CCIPane, #Red, #Thin);
DrawHorzLine(CCIHigher, CCIPane, #Red, #Thick);
DrawLabel(GetDescription(MyCCI), CCIPane);

AroonPane := CreatePane(60, False, True);
SetPaneMinMax(AroonPane, AroonLow - 10, AroonHigh + 10);
AroonOsc := SubtractSeries(AroonUpSeries (#Close, AroonPeriod),
AroonDownSeries(#Close, AroonPeriod));
PlotSeries(AroonOsc, AroonPane, #Black, #Thick);
DrawHorzLine(AroonHigh, AroonPane, #Blue, #Thick);
DrawHorzLine(AroonLow, AroonPane, #Blue, #Thick);
DrawHorzLine(Neutral, AroonPane, #Black, #Dotted);
DrawLabel('Aroon Osc (' + IntToStr(AroonPeriod) + ')', AroonPane);

InstallStopLoss(StopLoss);

BuyState := 0;
SellState := 0;
StartBar := AroonPeriod;
EndBar := BarCount - 1;

for Bar := StartBar to EndBar do
begin
ApplyAutoStops(Bar);
if LastPositionActive then
begin
if PositionLong(LastPosition) then
begin
{ Long Position Exit Rules }
case SellState of
0 :
if GetSeriesValue(Bar, AroonOsc) < AroonHigh then
begin
if CrossUnderValue(Bar, MyCCI, CCIHigh) then
SellAtMarket(Bar + 1, LastPosition, 'Sell');
end
else
SellState := 1; { Wait for a crossing above CCIHigher }
1 :
if CrossOverValue(Bar, MyCCI, CCIHigher) then
SellState := 2; { Wait for a crossing below CCIHigh }
2 :
if CrossUnderValue(Bar, MyCCI, CCIHigh) then
SellAtMarket(Bar + 1, LastPosition, 'Sell Higher');
end;
end
else { We have a Short position }
begin
{ Short Position Exit Rules }
case BuyState of
0 :
if GetSeriesValue(Bar, AroonOsc) > AroonLow then
begin
if CrossOverValue(Bar, MyCCI, CCILow) then
begin
CoverAtMarket(Bar + 1, LastPosition, 'Cover & Buy');
BuyAtMarket(Bar + 1, '');
end;
end
else
BuyState := 1; { Wait for a crossing below CCILower }
1 :
if CrossUnderValue(Bar, MyCCI, CCILower) then
BuyState := 2; { Wait for a crossing above CCILow }
2 :
if CrossOverValue(Bar, MyCCI, CCILow) then
begin
CoverAtMarket(Bar + 1, LastPosition, 'Cover&Buy Lower');
BuyAtMarket(Bar + 1, '');
BuyState := 0;
end;
end;
end;
end
else
begin
{ Long Position Entry Rules }
case BuyState of
0 :
if GetSeriesValue(Bar, AroonOsc) > AroonLow then
begin
if CrossOverValue(Bar, MyCCI, CCILow) then
BuyAtMarket(Bar + 1, 'Buy');
end
else
BuyState := 1; { Wait for a crossing below CCILower }
1 :
if CrossUnderValue(Bar, MyCCI, CCILower) then
BuyState := 2; { Wait for a crossing above CCILow }
2 :
if CrossOverValue(Bar, MyCCI, CCILow) then
begin
BuyAtMarket(Bar + 1, 'Buy Lower');
BuyState := 0;
end;
end;
{ Short Position Entry Rules }
if (GetSeriesValue(Bar, AroonOsc) < Neutral) and
(CrossUnderValue(Bar, MyCCI, CCILow)) then
ShortAtMarket(Bar + 1, 'Short');
end;
end;