Volatility Break Out Day Trader

Here is a nice template to use when testing a volatility break out system to daytade. Note I haven’t yet finished the filter coding.

{OPEN RANGE BREAK OUT with Trade Management}
{:data1 = 5 minbars
 :data2 = daily bars}
 
inputs: atrLookBack(10),brkOutAmt(.20),initProtStop$(500),profitThresh$(300),percentTrail(0.3),waitNumBars(3),endTradeEntryTime(1430);
inputs: tradeFilterNum(1);
{tradeFilterNum indicates how you want to 
 filter the trades:
 filter #1 : prior day was a narrow range
 filter #2 : prior day was a NR4
 filter #3 : buy/sell day only base on today's open
 filter #4 : combo of filter #1 and filter #3
 filter #5 : combo of filter #2 and filter #3 
 }


vars: buysToday(0),sellsToday(0),atrVal(0),todaysOpen(0),canBuy(false),canSell(false);
vars: trailLong(false),trailShort(false),trailLongStop(0),trailShortStop(999999);
vars: myBuysToday(0),mySellsToday(0);
if tradeFilterNum = 1 then
begin
	canBuy = false;
	canSell = false;
	if range of data2 < avgTrueRange(atrLookBack) of data2 and time < endTradeEntryTime then
	begin
		canBuy = true;
		canSell = true;
	end;
end; 

if date <> date[1] then
begin
	todaysOpen = open; {Capture Today's Open}
	trailLongStop = 0;
	trailShortStop = 9999999;
	myBuysToday = 0;
	mySellsToday = 0;
end;

if marketPosition = 1 then myBuysToday = 1;
if marketPosition = -1 then mySellsToday = -1;

atrVal = avgTrueRange(atrLookBack) of data2;

if  canBuy and myBuysToday = 0 and marketPosition <> 1 then buy("BBO") next bar at todaysOpen + atrVal * brkOutAmt stop;
if canSell and mySellsToday = 0 and marketPosition <>-1 then sellshort("SBO") next bar at todaysOpen - atrVal *brkOutAmt stop;

if marketPosition <> 1 then trailLong = false;
if marketPosition <> -1 then trailShort = false;

if marketPosition = 1 then
begin
	sell("LongExit") next bar at entryPrice - initProtStop$/bigPointValue stop;
	if h > entryPrice + profitThresh$/bigPointValue then trailLong = true;
	if trailLong then
	begin
		trailLongStop = maxList(trailLongStop,h - (h - entryPrice)*percentTrail);
		sell("LongTrail") next bar at trailLongStop stop;
	end;
end;

if marketPosition = -1 then
begin
	buyToCover("ShrtExit") next bar at entryPrice + initProtStop$/bigPointValue stop;
	if l < entryPrice - profitThresh$/bigPointValue then trailShort = true;
	if trailShort then
	begin
		trailShortStop = minList(trailShortStop,l + (entryPrice - l)*percentTrail);
		buyToCover("ShortTrail") next bar at trailShortStop stop;
	end;
end;

setExitOnClose;

{finished}