Open Range BreakOut with Trade Management
How difficult is it to program a day trading system using an open range break out, protective stop and a trailing stop? Let’s see. I started working on this and it got a little more detailed than I wanted so I have now split it up into two posts. Part 2 will follow very soon.
What inputs do we need? How about the number of days used in the volatility calculation? What percentage of the volatility from the open do you want to buy or sell? Should we have a different value for buys and sells? Do we want to use a volatility based protective stop or a fixed dollar? How about a trailing stop? Should we wait to get to a certain profit level before engaging the trailing stop? Should it also be based on volatility or fixed dollar amt? How much should we trail – again an amount of volatility or fixed dollar?
Proposed inputs:
inputs: volCalcLen(10), orboBuyPer(.2), orboSellPer(.2), volStopPer(.7), $Stop(500), volProfThreshPer(.5), $ProfThresh(250),volTrailPer(.2),$Trail(200);
That should do it for the inputs – we can change later if necessary.
Possible pitfalls:
This is where I will save you some time. If we use an open range break out entry we must limit the number of entries or TradeStation will continue to execute as long as the price is above our buy level. You might ask, “That’s what we want -right?” What if we use a tight stop and we get stopped out of our first position. Do you want to buy again later in the day? What if we use a trailing stop and we get out of the market above the buy level. What will TradeStation do? It will follow your exact instructions and buy again if you don’t control the number of allowed entries. Do you want to carry the buy and sell stops overnight for execution on the open of the next day – probably not! So we not only need to control the number of entries buy we also need to control the time period we can enter a trade.
Calculations:
We need to determine the volatility and a good way do this is calculating the average range over the past N days. There are two ways to do this: 1) incorporate a daily chart as data2 and use a built-in function for the calculation or 2) use a for-loop and use the built-in functions HighD and LowD and just use one data feed. Both have their drawbacks. The first is you need to have a multi-data chart and the second you get a warning that you shouldn’t put a series function call inside the body of a for-loop. I have done it both ways and I prefer to deal with the warning – so far it has worked out nicely – so let’s go with a single data chart.
Building the code:
Inputs:
Since we are combining a volatility and fixed $ amount in our trade management, you will need to set either the vol or dollar amounts to a high value to disable them. You can use both but I am taking the smaller of the respective values.
inputs: volCalcLen(10),orboBuyPer(.2),orboSellPer(.2);
inputs: volStopPer(.7),$Stop(500/bigPointValue);
inputs: volThreshPer(.5),$ProfThresh(250/bigPointValue);
inputs: volTrailPer(.2),$Trail(200/bigPointValue);
Inputs We Will Need - Can Changer Later
Variables:
vars:vol(0),buyPoint(0),sellPoint(0),
longStopAmt(0),shortStopAmt(0),longExitPoint(0),shortExitPoint(0),
longThreshAmt(0),shortThreshAmt(0),
longTrailAmt(0),shortTrailAmt(0),
longTrailLevel(0),shortTrailLevel(0),
hiSinceLong(0),loSinceShort(0),mp(0),
rangeSum(0),iCnt(0),
buysToday(0),shortsToday(0)
Variables That We Might Need
Once A Day Calculations:
Since we will be working with five-minute bars we don’t want to do daily calculations on each bar. If we do it will slow down the process. So let’s do these calculation on the first bar of the day only.
If d <> d[1] then
Begin
rangeSum = 0.0; // range calculation for entry
For iCnt = 1 to volCalcLen
Begin
rangeSum = rangeSum + (highD(iCnt) - lowD(iCnt));
end;
vol = rangeSum/volCalcLen;
buyPoint = openD(0) + vol*orboBuyPer;
sellPoint = openD(0) - vol*orboSellPer;
longStopAmt = vol * volStopPer;
longStopAmt = minList(longStopAmt,Stop$);
shortStopAmt = vol *volStopPer;
shortStopAmt = minList(shortStopAmt,Stop$);
longThreshAmt = vol * volThreshPer;
longThreshAmt = minList(longThreshAmt,ProfThresh$);
shortThreshAmt = vol * volThreshPer;
shortThreshAmt = minList(shortThreshAmt,ProfThresh$);
longTrailAmt = vol * volTrailPer;
longTrailAmt = minList(longTrailAmt,Trail$);
shortTrailAmt = vol * volTrailPer;
shortTrailAmt = minList(shortTrailAmt,Trail$);
longTrailLevel = 0;
shortTrailLevel = 999999;
buysToday = 0;
shortsToday = 0;
end;
Do These Just Once A Day
For All of You Who Don’t Want To Wait – Beta Version Is Available Below:
In my next post, I will dissect the following code for a better understanding. Sorry I just ran out of time.
inputs: volCalcLen(10),orboBuyPer(.2),orboSellPer(.2);
inputs: volStopPer(.7),Stop$(500/bigPointValue);
inputs: volThreshPer(.3),ProfThresh$(250/bigPointValue);
inputs: volTrailPer(.2),Trail$(200/bigPointValue);
vars:vol(0),buyPoint(0),sellPoint(0),
longStopAmt(0),shortStopAmt(0),longExitPoint(0),shortExitPoint(0),
longThreshAmt(0),shortThreshAmt(0),
longTrailAmt(0),shortTrailAmt(0),
longTrailLevel(0),shortTrailLevel(0),
hiSinceLong(0),loSinceShort(0),mp(0),
rangeSum(0),iCnt(0),
buysToday(0),shortsToday(0);
If d <> d[1] then
Begin
rangeSum = 0.0; // range calculation for entry
For iCnt = 1 to volCalcLen
Begin
rangeSum = rangeSum + (highD(iCnt) - lowD(iCnt));
end;
vol = rangeSum/volCalcLen;
buyPoint = openD(0) + vol*orboBuyPer;
sellPoint = openD(0) - vol*orboSellPer;
longStopAmt = vol * volStopPer;
longStopAmt = minList(longStopAmt,Stop$);
shortStopAmt = vol *volStopPer;
shortStopAmt = minList(shortStopAmt,Stop$);
longThreshAmt = vol * volThreshPer;
longThreshAmt = minList(longThreshAmt,ProfThresh$);
shortThreshAmt = vol * volThreshPer;
shortThreshAmt = minList(shortThreshAmt,ProfThresh$);
longTrailAmt = vol * volTrailPer;
longTrailAmt = minList(longTrailAmt,Trail$);
shortTrailAmt = vol * volTrailPer;
shortTrailAmt = minList(shortTrailAmt,Trail$);
longTrailLevel = 0;
shortTrailLevel = 999999;
buysToday = 0;
shortsToday = 0;
end;
mp = marketPosition;
If mp = 1 and mp[1] <> 1 then buysToday = buysToday + 1;
If mp = -1 and mp[1] <> -1 then shortsToday = shortsToday + 1;
if time < sessionendTime(0,1) and buysToday < 1 then Buy("ORBo-B") next bar at buyPoint stop;
if time < sessionendTime(0,1) and shortsToday < 1 then Sellshort("ORBo-S") next bar at sellPoint stop;
If marketposition = 1 then
Begin
longExitPoint = entryPrice - longStopAmt;
sell("L-Exit") next bar at longExitPoint stop;
end;
If marketposition = -1 then
Begin
shortExitPoint = entryPrice + shortStopAmt;
buyToCover("S-Exit") next bar at shortExitPoint stop;
end;
If marketPosition = 1 and maxContractProfit/bigPointValue >= longThreshAmt then
Begin
longTrailLevel = maxList(highest(h,barsSinceEntry) - longTrailAmt,longTrailLevel);
sell("TrailSell") next bar at longTrailLevel stop;
end;
If marketPosition = -1 and maxContractProfit/bigPointValue >= shortThreshAmt then
Begin
shortTrailLevel = minList(lowest(l,barsSinceEntry) + shortTrailAmt,ShortTraillevel);
buyToCover("TrailCover") next bar at shortTrailLevel stop;
end;
SetExitOnClose;
Beta Version - I will clean up later and post it
Like this:
Like Loading...
Related
Discover more from George Pruitt
Subscribe to get the latest posts sent to your email.