ProBacktest Help

mb325

Well-known member
Messages
473
Likes
87
I'm trying to backtest a daily system which buys on the break of previous day high and sells on the break of previous day low, with preset stop and profit taking amounts. I have an A Level in computing and thus can't even get this simple system working using the 'assisted creation' function.

I've optimistically tried working out how to do the coding myself (read through the manual etc. and scannned forums) but either i'm screwing up the coding, or i'm not approaching it in the right way.

It seems like quite an easy piece of coding so i'd really appreciate it if someone could spare 5mins and help me out!

Cheers
 
This is just a code fragment, but I think it has the guts of what you want to do:

IF NOT LONGONMARKET AND (DHigh(0) < DHigh(1)) THEN
BUY 10%CAPITAL AT DHigh(1) LIMIT
ENDIF

IF NOT SHORTONMARKET AND (DLow(0) > DLow(1)) THEN
SELLSHORT 10%CAPITAL AT DLow(1) LIMIT
ENDIF
 
Thanks. I've tried that and the results show 0 trades have been taken, which is impossible?
 
Sorry, all sorts of problems in that previous scrap of code. Here's a replacement.

After pasting it in you should tweak the first 2 variables to match your market. You'll also need to set the backtest's stoploss, profit stop and capital. I used 1%, 2% and 100,000. Run it against the hourly timeframe or lower (there's not enough information in the higher timeframes).

I've tested this against the FTSE100 and it seems to work, although it doesn't make any money on that particular market :eek:

Code:
// set these variables according to your market
breakoutdistance = 10
barsperday = 24

// highest and lowest prices of the day so far
dailyhigh = highest[IntradayBarIndex+1](high)
dailylow = lowest[IntradayBarIndex+1](low)

longalreadytriggered=0
shortalreadytriggered=0

IF (IntradayBarIndex=(barsperday-1)) THEN
	// last bar of day
	buyprice = DHigh(0) + breakoutdistance
	sellprice = DLow(0) - breakoutdistance
ELSE
	//not the last bar of the day
	buyprice = DHigh(1) + breakoutdistance
	sellprice = DLow(1) - breakoutdistance
	
	//check to see if an order has already been triggered today
	//this prevents re-entry immediately after taking profit
	IF dailyhigh >= buyprice THEN
		longalreadytriggered=1
	ENDIF
	IF dailylow <= sellprice THEN
		shortalreadytriggered=1
	ENDIF
	
ENDIF

//Place the orders
IF NOT LONGONMARKET AND longalreadytriggered=0 THEN
	BUY 1000 CASH AT buyprice  STOP
ENDIF

IF NOT SHORTONMARKET AND shortalreadytriggered=0 THEN
	SELLSHORT 1000 CASH AT sellprice STOP
ENDIF
 
Top