Opening Range Breakout Strategy with Market Volatility for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
We're releasing our first algo for ThinkorSwim based on the Opening Range Breakout indicator. Although calling it an algo, it's simply just a strategy that plot buy and sell signals on your chart. Auto trade isn't supported in ThinkorSwim at the moment so you still have to execute the trade on your own.

The indicator and strategy were developed to solve our own problem. Using the standard ORB indicator, we saw that there were a lot of false breakouts. So we asked ourselves how can we solve this problem.

How Did We Get to This Point?

The biggest issue with the Opening Range indicator is false breakouts and breakdowns. To do so, we added additional indicators into it.

Here is what we added:
Those 3 important components allowed us to trim down a lot of fake breakouts.

We learned that when a breakout or breakdown happen while the market is calm or quiet (not trending) then most likely it's going to be a false signal. As a result, using the Market Volatility that we found was the perfect solution.

Next, sometimes a stock would breakout or breakdown near market close. We don't want that. So we added a time filter into the indicator. This would tell the algo to stop giving us signals an hour before the market closing time.

Lastly, using EMA crossover also helps to confirm the trend indicated by the algo. If there is no crossover then there is no trade. Ultimately, all 3 components have to agree in order for the buy and sell signals to be produced.

Meet the Enhanced ORB Strategy

Rich (BB code):
# 30 min opening range Market Volatility V1.1
# Robert Payne
# Adapted to strategy by WalkingBallista and BenTen
# https://usethinkscript.com/threads/opening-range-breakout-strategy-with-market-volatility-for-thinkorswim.164/

script MV {

input atrlength = 14;

input avglength = 500;

input plotlower = {default "yes", "no"};

def vol = reference ATR(atrlength, averageType = AverageType.SIMPLE);

def avgvol = Average(vol, avglength);

def calm = vol < avgvol - (avgvol * .1);

def neutral = avgvol + (avgvol * .1) > vol > avgvol - (avgvol * .1);

def Volatile = vol > avgvol + (avgvol * .1);

AddLabel(yes, Concat("Market is Currently ", (if calm then "Calm" else if neutral then "Neutral" else if Volatile then "Volatile" else "Neutral")),  if calm then Color.GREEN else if neutral then Color.BLUE else if Volatile then Color.RED  else Color.GRAY);

declare lower;

plot window =  vol - avgvol;

window.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

window.AssignValueColor(if Volatile then Color.RED else if calm then Color.GREEN else if neutral then Color.BLUE else Color.GRAY);

plot zeroline = 0;

};

def volatile = MV().volatile;

def OpenRangeMinutes = 30;
def MarketOpenTime = 0930;
def LastBar = SecondsFromTime(1530) == 0;
input TimeToStopSignal = 1525;
def TradeTimeFilter = SecondsFromTime(TimeToStopSignal);
input ShowTodayOnly = no;
input UseEMACross = yes;
input ema1_len = 8;
input ema2_len = 13;
AddVerticalLine(SecondsFromTime(0930)==0,"Open",Color.Gray,Curve.SHORT_DASH);
AddVerticalLine(!TradeTimeFilter,"Last Signal",Color.Dark_Gray,Curve.SHORT_DASH);
def Today = if GetDay() == GetLastDay() then 1 else 0;
def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0;
def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes then 1 else 0;

def ORHigh =  if FirstMinute then high else if OpenRangeTime and high > ORHigh[1] then high else ORHigh[1];
def ORLow = if FirstMinute then low else if OpenRangeTime and low < ORLow[1] then low else ORLow[1];

plot OpenRangeHigh = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORHigh else Double.NaN;
plot OpenRangeLow = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORLow else Double.NaN;

OpenRangeHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OpenRangeHigh.SetDefaultColor(Color.YELLOW);
OpenRangeHigh.SetLineWeight(2);
OpenRangeLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OpenRangeLow.SetDefaultColor(Color.YELLOW);
OpenRangeLow.SetLineWeight(2);

def dailyRange = high(period = "day" )[1] - low(period = "day" )[1];
def range = Average(dailyRange, 10);

plot ema1 = MovAvgExponential(length=ema1_len);
plot ema2 = MovAvgExponential(length=ema2_len);

# Bullish
AddOrder(OrderType.BUY_TO_OPEN, ((!UseEmaCross AND close crosses above OpenRangeHigh) OR (UseEMACross AND ema1 crosses above OpenRangeHigh)) and TradeTimeFilter < 1 and volatile, tradeSize = 100, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "TC_O");

AddOrder(OrderType.SELL_TO_CLOSE, ema1 crosses below ema2 or (close < OpenRangeHigh) or LastBar, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "TC_C");

# Bearish
AddOrder(OrderType.SELL_TO_OPEN, ((!UseEmaCross AND close crosses below OpenRangeLow) OR (UseEMACross AND ema1 crosses below OpenRangeLow)) and TradeTimeFilter < 1 and volatile, tradeSize = 100, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "TC_O");

AddOrder(OrderType.BUY_TO_CLOSE, ema1 crosses above ema2 or (close > OpenRangeLow) or LastBar, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "TC_C");
I'm happy to share with you some outstanding results.





Over to You!

Those are just some of the most successful plays we had from last week. But don't get too excited just yet because like any other indicators, this one also has its own weakness.

By adding 3 additional conditions into the indicator, we were able to produce a great trading strategy. However, you may still be able to spot some fake breakouts and breakdowns on the chart. Now it's up to you to use your skills to identify these false signals and not to take the trade.

Additionally, we also implemented the EMA crossover rule so that even if the algo is wrong it will still be able to cut losses early.



We recommend that you take partial profit to avoid incident like this.



If you have any issues, recommendations, or questions while using the algo please comment down below.

Credits:
  • I can't thank @WalkingBallista enough for helping me code all of my ideas into one script. Sometimes we would be up until 1-2 am working on the strategy. If you're in our Discord chatroom please drop him a like &#128512;.
  • Robert Payne for the original ORB indicator
 
Last edited:
S

San

New member
VIP
@BenTen,

I have crated new chart with only above script but nothing shows pls assist... Do i need to add any other indicator.

 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@San You need to add it as a new Strategy not Indicator.

 
Last edited:
M

mikeraya

New member
BenTen: If I load this will this show up on Friday's chart?

 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@mikeraya Yes. You can show it on any other days as well as long as there is a breakdown or breakout based on the conditions that we put into the indicator.

 
Last edited:
M

mikeraya

New member
@BenTen put it on chart. Nothing shows up.

 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@mikeraya Got any example? Which ticker were you looking at?

 
Last edited:
S

San

New member
VIP
@BenTen , Tried Goog, AMZN,SPY,QQQ...etc.

 
Last edited:
S

San

New member
VIP
@BenTen, My bad , Added the script under Stategies instead of Study... Now i am able to see it... Thanks..


 
Last edited:
R

ruthiem

New member
I am getting an error message when i remove Delete this line from TOS# can you share the link? thx

 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@ruthiem You do not need to remove anything. Just leave that line in there &#128512;

 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@mikeraya 3 signals last week.



 
Last edited:
R

ruthiem

New member
i feel dumb... thank you for your awesomeness as always.

 
Last edited:
R

runit

New member


Seems like a massive loss over 180 days using floating P/L for the strat? This is only with 1 contract.


 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@runit The P/L does not reflect the true potential of this indicator. Due to the nature and limitations of ThinkorSwim we were not able to implement early or partial profit taking as we go. It's nearly impossible to tweak it so that it works perfectly on paper.



Things like this can be one of the major causes for the P/L to be in deep red.













Don't get me wrong, this indicator is not perfect. It produced false plays as well. But by studying past trades, you can improve a lot manually.

 
Last edited:
1

15minofpham

New member
Is there a way to convert this into a scan?

 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@john3 It’s called The Syndicate. Try contacting Discord and see what happen. The links are working fine for others.



@15minofpham Not at the moment. Will look into it.

 
Last edited:
C

Chenthy73

New member
Great thesis and result. I will evaluate it. Thanks a lot, Gang!

 
Last edited:

Top