@ges Thinking about the speed, TechniFilter must be extremly fast I did a quick test of the code below on the 30 Dow Jones stocks. I tested 1000 bars of each stock, it took me in the 'slow' mode 12 seconds. That is using money managment on the portfolio level. The system was doing very good. I post the results here too. The system was published in February 2002, so it has already 9 month out of sample running.
All Trades Long Trades Short Trades Buy && Hold
100.000,00 $ 100.000,00 $ 100.000,00 $ 100.000,00 $
182.990,42 $ 157.736,66 $ 125.253,66 $ 109.897,23 $
var atrprofit, atrstop, nextatrprofit, temp, thisatr, thisrsi, buyprice,
limitprice, exitprice, maxrisk, maxriskprice : float;
var atrrange,srsi,lrsi,rsiperiod,minprice,minadx,adxperiod,
Bar, buybar, p : integer;
var str : string;
{ setup variables }
atrprofit := 200 / 100; { percentage of the ATR as a target}
nextatrprofit := 110 / 100; { target for day 2, calculated from the open }
atrstop := 100 / 100; { percentage of the ATR as a stop }
maxrisk := 15; { never more than this, even on big atr stocks }
atrrange := 21; { need lots of bars to establish TRUE range }
lrsi := 18;
srsi := 82;
rsiperiod := 5; { this seems to suit the short term hold period }
minprice := 0; { play with price levels here }
minadx := 22; { filter out rangebound stocks }
adxperiod := 14;
for Bar := 41 to BarCount() - 1 do
begin
{ let's calc this for later }
thisrsi := RSI(Bar,#close,rsiperiod);
thisatr := ATR(Bar,atrrange);
for p := 0 to PositionCount() - 1 do
begin
if PositionActive(p) then
begin
buybar := PositionEntryBar(p);
buyprice := PositionEntryPrice(p);
if PositionLong( p ) then
begin
{ Use our wide ATR exits on day one }
if ( Bar = buybar) then
begin
limitprice := buyprice + (atrprofit * thisatr);
exitprice := buyprice - (atrstop * thisatr);
maxriskprice := buyprice * (1 - (maxrisk / 100));
if (exitprice < maxriskprice) then exitprice := maxriskprice;
if not SellAtStop( Bar, exitprice, p, 'atrstop') then
if (PriceClose(Bar) > limitprice) then
SellAtClose( Bar, p, 'day1close');
end;
{ Tighten the target, and get out at the close if we don't get it }
if ((Bar - buybar) = 1)
AND (PositionActive(p)) then
begin
limitprice := PriceOpen(Bar) + (nextatrprofit * thisatr);
exitprice := PriceLow(Bar-1) * 0.995;
maxriskprice := buyprice * (1 - (maxrisk / 100));
if (exitprice < maxriskprice) then exitprice := maxriskprice;
if not SellAtStop( Bar, exitprice, p, 'day2stop') then
if not SellAtLimit( Bar, limitprice, p, 'day2limit') then
SellAtClose(Bar,p,'timeout');
end;
end
else
begin
if ( Bar = buybar ) then
begin
buyprice := PositionEntryPrice(p);
limitprice := buyprice - (atrprofit * thisatr);
exitprice := buyprice + (atrstop * thisatr);
maxriskprice := buyprice * (1 + (maxrisk / 100));
if (exitprice > maxriskprice) then exitprice := maxriskprice;
if not CoverAtStop( Bar, exitprice, p, 'atrstop') then
if (PriceClose(Bar) < limitprice) then
CoverAtClose( Bar, p, 'day1close');
end;
if ((Bar - buybar) = 1)
AND (PositionActive(p)) then
begin
limitprice := PriceOpen(Bar) - (nextatrprofit * thisatr);
exitprice := PriceHigh(Bar-1) * 1.005;
maxriskprice := buyprice * (1 + (maxrisk / 100));
if (exitprice > maxriskprice) then exitprice := maxriskprice;
if not CoverAtStop( Bar, exitprice, p, 'day2stop') then
if not CoverAtLimit( Bar, limitprice, p, 'day2limit') then
CoverAtClose(Bar,p,'timeout');
end;
end;
end;
end; { for position loop }
{ entry rules... }
if (ADX(bar,adxperiod) > minadx)
AND (thisrsi < lrsi)
AND (Pricelow(bar) > minprice)
then
begin
BuyAtMarket( Bar+1,'');
{ tell simulator to enter more oversold stocks first }
SetPositionData(LastPosition, (100 - thisrsi));
end;
if ((ADX(bar,adxperiod) > minadx)
AND (thisrsi > srsi)
AND (PriceLow(bar) > minprice))
then
begin
ShortAtMarket( Bar+1, '');
{ tell simulator to enter more overbought stocks first }
SetPositionData(LastPosition, thisrsi);
end;
end;
var INDPane: integer;
INDPane := CreatePane( 50, true, true );
PlotSeries( RSISeries( #Close,rsiperiod ), INDPane, 009, #Thin );
str := 'ATR(' + FloatToStr(atrrange) + ') = ' + FormatFloat('##.##',thisatr);
DrawLabel( str, INDPane );
str := 'RSI(5): ' + FormatFloat('##.##',thisrsi);
DrawLabel( str, INDPane );
Changing the risk to 20% per trade took less then 2 seconds and here is the result:
All Trades Long Trades Short Trades Buy && Hold
100.000,00 $ 100.000,00 $ 100.000,00 $ 100.000,00 $
316.819,00 $ 258.984,98 $ 157.833,91 $ 109.897,23 $
I think this is pretty fast?
Volker