Opening Range Breakout Strategy with Market Volatility for ThinkorSwim

@Simteaz No issue on my end.
Hey Benten! Been looking through the archives and this first post, but can't seem to get my head straight with the coding since I never really code with Intraday. Got a strategy I'm trying to backtest, how do I designate to just buy (not depending on ORB) the open at 30 minutes after market open? This is the daily chart
 
Is this strategy still being used? What kinds of results are you all seeing? Also, sorry for being a bit dense but can someone explain what the TC_O, TC_C's mean?
 
@wtf_dude Sorry, not sure how I missed your question. So you just want to buy right off the bat after the first 30 min? Is that right?

@JonPM O = open and C = close.
 
@BenTen , Thank you !! This upgrade for market volatility is very helpful. You can also enter using the 5/13 ema cross over and exit using the 8/13 ema crossover.
 
@BenTen I noticed that you mentioned in a couple of posts, that a scanner can be set up for this strategy. Can you kindly share how? I did save it as strategy. I am able to display it in charts. However, when I go to scan, the strategy is not showing up. I tried to use the script instead (in scan area), but that is not working either.

thanks,
jaan
 
Huh. I did not realize that. I tested this strategy on some of breakout charts from last week. So i was thinking of using it as a scan so that i get alerted any time it would produce a buy to open or sell to open signal. Any ideas on how i can do that?
 
@kelbadawi You probably added it as an indicator rather than as a strategy. This is a backtesting strategy. Next to your Studies tab is the Strategies tab. Add the script there.
 
@BenTen @RobertPayne

Very nice! Question: Would either of you know if after a "OrderType.BUY_TO_OPEN" has executed, a way that I can code a way to detect that it's active or closed by using a IF statement?



Code:
# 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");
 
Last edited:
Hi,

Is there anyway we can modify this scan to pick up the stocks with a buy or sell signal? Currently this scan is only picking up stocks that are above the opening range or below, and it takes some work to sort through all this. Thanks!
 
@BenTen Is it possible to make this a 15 min Open Range Breakout rather than the 30 min, keeping everything the same, I feel the buy signal is too late with the 30 min
 
@K_O_Trader In the indicator's settings, change OpenRangeMinutes from 30 to your desired breakout time, in this case 15.

@egshih Here is the modified version. It's now an indicator rather than a backtesting strategy. You can use the scanner with it.

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
def bull = ((!UseEmaCross AND close crosses above OpenRangeHigh) OR (UseEMACross AND ema1 crosses above OpenRangeHigh)) and TradeTimeFilter < 1 and volatile;

# Bearish
def bear = ((!UseEmaCross AND close crosses below OpenRangeLow) OR (UseEMACross AND ema1 crosses below OpenRangeLow)) and TradeTimeFilter < 1 and volatile;

plot arrowUp = bull;
arrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
arrowUp.SetDefaultColor(Color.CYAN);
arrowUp.SetLineWeight(1);

plot arrowDown = bear;
arrowDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_Down);
arrowDown.SetDefaultColor(Color.MAGENTA);
arrowDown.SetLineWeight(1);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
356 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top