Random entry system a la Van Tharp

Hi, I tried coding it in WEalth-Lab. Im getting strange results. Its supposed to be profitable on like 9 out of 10 markets, instead it seems to lose on those. Maybe I miscoded something. The rules are: 1) Flip a coin, take a position long/short 2) Use 3*10dayATR as a trailing stop 3) When stop hit, exit and go back to 1.

Here's the code:

var Upband, Downband, bar: integer;
var stop: float;
Upband := CreateSeries();
Downband := CreateSeries();
for Bar := 1 to BarCount()-1 do
begin
SetSeriesValue( Bar, Upband, (PriceClose(Bar-1)+3*ATR(bar-1, 10)));
SetSeriesValue( Bar, Downband, (PriceClose(Bar-1)-3*ATR(bar-1, 10)));
end;
PlotSeries( Upband, 0, #Red, #Thick );
PlotSeries( Downband, 0, #Green, #Thick );
HideVolume;

Randomize;
for Bar := 1 to BarCount()-1 do
begin

if not LastPositionActive() then
begin
if Random() > 0.5 then ShortAtMarket(bar, '') else BuyAtMarket(bar, '');
if PositionLong(LastActivePosition) then stop := GetSeriesValue( bar, Downband )
else stop := GetSeriesValue( bar, Upband );
end

else begin


if PositionLong(LastActivePosition) then begin
if GetSeriesValue( bar, Downband ) > stop
then stop := GetSeriesValue( bar, Downband );
if PriceClose(bar) < stop
then SellAtClose(bar, LastActivePosition, '');
end
else
if GetSeriesValue( bar, Upband ) < stop
then stop := GetSeriesValue( bar, Upband );

if PriceClose(bar) > stop then
CoverAtClose(bar, LastActivePosition, '');
end
end;
 
Hello Traderkay,
Having fun with your script, my attempt:

Randomize;
for Bar := 1 to BarCount()-1 do
begin
if not LastPositionActive() then
begin
if Random() > 0.5 then
begin
ShortAtMarket(bar+1, ''); //shorts at open
stop := GetSeriesValue( bar, Upband );
CoverAtStop( Bar+1, stop, LastPosition, 'Stop Loss' ); //intraday stop
end
else
begin
BuyAtMarket(bar+1, ''); //buys at open
stop := GetSeriesValue( bar, Downband );
SellAtStop( Bar+1, stop, LastPosition, 'Stop Loss' ); //intraday stop
end
end
else //Previous position is open
begin
if PositionLong(LastActivePosition) then
begin
if GetSeriesValue( bar, Downband ) > stop then
begin
stop := GetSeriesValue( bar, Downband );
SellAtStop( Bar, stop, LastPosition, 'Stop Loss' );
end
else
if GetSeriesValue( bar, Upband ) < stop then
begin
stop := GetSeriesValue( bar, Upband );
CoverAtStop( Bar, stop, LastPosition, 'Stop Loss' );
end
end
end
end;


Due to the random function its hard to evaluate as each run varies.
Should it maybe be ran over and over on the same trading vehicle
and timeframe to establish an average performance?
smitty
 
I don't know about 9 out of 10. I tested it on 63 futures markets using daily data from 1990 - 2000. 33 of the 63 markets were consistently profitable. In looking at what was profitable vs a loser, I found the markets had to have a strong characteristic to trend. All the metals markets lost money while all the oil and gas complex made money. My guess is the stocks you're testing it on don't have a strong tendency to trend. You might have better luck using weekly data.

BTW, this exit method was developed by Tom Bierovic.
 
Well, I'm testing on 60min continuous bars of ES, since 97 til this August. And every freaking time I see a nice, consistent diagonal equity curve DOWN! And i cant figure out how to make it up. And the funny thing is entries are random and it's down almost every time i run it. BTW i think numerous runs with random variables are called Monte Carlo simulations. What results are you getting mitts?
 
Originally posted by traderkay
Well, I'm testing on 60min continuous bars of ES, since 97 til this August. And every freaking time I see a nice, consistent diagonal equity curve DOWN! And i cant figure out how to make it up. And the funny thing is entries are random and it's down almost every time i run it. BTW i think numerous runs with random variables are called Monte Carlo simulations. What results are you getting mitts?


Why dont you just fade the system and retire? :)

--MIKE
 
Traderkay,
Just running this on QQQ daily data, created a "fake" OptVar using optimize function in WLD then control the number of runs by the range & step value of the OptVar. Don't use this variable for anything, just a way to run the system over and over and get a group of results. Looks profitable this way.
Smitty
 
That's what I tried to do TrendFader. I reversed every single exit rule (since entry is random), changed every > to < and it's still down every time, hahaha!
 
Originally posted by acrary
I don't know about 9 out of 10. I tested it on 63 futures markets using daily data from 1990 - 2000. 33 of the 63 markets were consistently profitable. In looking at what was profitable vs a loser, I found the markets had to have a strong characteristic to trend.

Bingo! Which is the case with nearly all the setups and systems you'll come across, and, in a trend, nearly anything will work. The trick is to determine whether or not you're in a trend. If you're not, then you have to turn to scalping strategies, and coin tosses ain't it.

--Db
 
Back
Top