> @BenTen P.S: I'll let Warmaster Steve talk more about the usage of TEMA and EMA when he's on. 😜
# Volume Profile for ORB
# V01.05.02.2018
# TOS Volume Profile with cond altered for a user input Time Range. Labels added for ORH, ORL, OR POC, Opening Range Value Percents upper and lower.
# For Intraday use only
input valueAreaPercent = 70.0;
input opacity = 15;
input RthBegin = 0930;
input OREnd = 1000;
input TimeLength = 30; #hint TimeLenght: In Minutes
def o = open;
def h = high;
def l = low;
def c = close;
def x = BarNumber();
def t = GetTime();
def RTS = RegularTradingStart(GetYYYYMMDD());
def RTE = RegularTradingEnd(GetYYYYMMDD());
def Active = SecondsFromTime(RthBegin) >= 0 and
SecondsTillTime(OREnd) > 0;
def firstBar = if Active and !Active[1]
then x
else Double.NaN;
def agg = GetAggregationPeriod();
def ORperiod_1 = if t crosses above RTS - agg + 300000
then Round(((Highest(h, 3) + Lowest(l, 3)) / 2) / TickSize(), 0) * TickSize()
else ORperiod_1[1];
plot OR_M = if x >= HighestAll(firstBar)
then HighestAll(if IsNaN(c[-1])
then ORperiod_1
else Double.NaN)
else Double.NaN;
OR_M.SetStyle(Curve.LONG_DASH);
OR_M.SetLineWeight(2);
OR_M.SetDefaultColor(Color.YELLOW);
AddChartBubble(x == firstBar, OR_M, "ORM", OR_M.TakeValueColor());
def timeSegment = (SecondsFromTime(0000) / 60) % TimeLength == 0;
def profiles = 1440 / TimeLength; # Profiles for 24 hours
def cond = if Active and !Active[1]
then 1
else timeSegment;
profile vol = VolumeProfile("startNewProfile" = cond,
"onExpansion" = 0,
"numberOfProfiles" = 20,
"pricePerRow" = TickSize(),
"value area percent" = valueAreaPercent);
def pc = if IsNaN(vol.GetPointOfControl())
then pc[1]
else vol.GetPointOfControl();
def hVA = if IsNaN(vol.GetHighestValueArea())
then hVA[1]
else vol.GetHighestValueArea();
def lVA = if IsNaN(vol.GetLowestValueArea())
then lVA[1]
else vol.GetLowestValueArea();
def hProfile = if IsNaN(vol.GetHighest())
then hProfile[1]
else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest())
then lProfile[1]
else vol.GetLowest();
def POC_ = if Active
then Round(pc / TickSize(), 0) * TickSize()
else POC_[1];
plot POC = if x >= HighestAll(firstBar)
then HighestAll(if IsNaN(c[-1])
then POC_
else Double.NaN)
else Double.NaN;
def ProfileHigh_ = if Active
then hProfile
else ProfileHigh_[1];
plot ProfileHigh = if x >= HighestAll(firstBar)
then ProfileHigh_
else Double.NaN;
def ProfileLow_ = if Active
then lProfile
else ProfileLow_[1];
plot ProfileLow = if x >= HighestAll(firstBar)
then ProfileLow_
else Double.NaN;
def VAHigh_ = if Active
then Round(hVA / TickSize(), 0) * TickSize()
else VAHigh_[1];
plot VAHigh = if x >= HighestAll(firstBar)
then HighestAll(if IsNaN(c[-1])
then VAHigh_
else Double.NaN)
else Double.NaN;
def VALow_ = if Active
then Round(lVA / TickSize(), 0) * TickSize()
else VALow_[1];
plot VALow = if x >= HighestAll(firstBar)
then HighestAll(if IsNaN(c[-1])
then VALow_
else Double.NaN)
else Double.NaN;
vol.Show(color.current, Color.YELLOW, Color.current, opacity);
POC.SetStyle(Curve.LONG_DASH);
POC.SetLineWeight(3);
POC.SetDefaultColor(Color.YELLOW);
VAHigh.SetStyle(Curve.LONG_DASH);
VAHigh.SetLineWeight(1);
VALow.SetStyle(Curve.LONG_DASH);
VALow.SetLineWeight(1);
VAHigh.SetDefaultColor(Color.GRAY);
VALow.SetDefaultColor(Color.GRAY);
ProfileHigh.SetStyle(Curve.LONG_DASH);
ProfileHigh.SetLineWeight(3);
ProfileLow.SetStyle(Curve.LONG_DASH);
ProfileLow.SetLineWeight(3);
ProfileHigh.SetDefaultColor(Color.GREEN);
ProfileLow.SetDefaultColor(Color.RED);
def bubble = IsNaN(c[2]) and !IsNaN(c[3]);
AddChartBubble(bubble, VAHigh, "OR %" + valueAreaPercent, VAHigh.TakeValueColor(), yes);
AddChartBubble(bubble, VALow, "OR %" + valueAreaPercent, VALow.TakeValueColor(), no);
AddChartBubble(bubble, POC, "OR POC", POC.TakeValueColor(), no);
AddChartBubble(bubble, ProfileHigh, "ORH", ProfileHigh.TakeValueColor(), yes);
AddChartBubble(bubble, ProfileLow, "ORL", ProfileLow.TakeValueColor(), no);
AddVerticalLine(Active and !Active[1], "RTH", Color.CYAN, Curve.SHORT_DASH);
AddVerticalLine(!Active and Active[1], "ORend", Color.CYAN, Curve.SHORT_DASH);
AddVerticalLine(t crosses above RTE, "RTHend", Color.CYAN, Curve.SHORT_DASH);
def prevClose = if t crosses above RTE
then vwap
else prevClose[1];
def prevCloseBar = if t crosses above RTE
then BarNumber()
else Double.NaN;
plot prevCloseLine = if x >= HighestAll(prevCloseBar)
then HighestAll(if IsNaN(c[-1])
then prevClose
else Double.NaN)
else Double.NaN;
prevCloseLine.SetStyle(Curve.SHORT_DASH);
prevCloseLine.SetDefaultColor(Color.GRAY);
AddChartBubble(x == HighestAll(x), prevCloseLine, "RTH C", prevCloseLine.TakeValueColor(), no);
def RTHopen = if Active and !Active[1]
then o
else RTHopen[1];
plot RTHopen_ = if x >= HighestAll(firstBar)
then HighestAll(if IsNaN(c[-1])
then RTHopen
else Double.NaN)
else Double.NaN;
RTHopen_.SetStyle(Curve.SHORT_DASH);
RTHopen_.SetDefaultColor(Color.GRAY);
AddChartBubble(x == HighestAll(x), RTHopen, "RTH O", RTHopen_.TakeValueColor(), no);
# End Code ORB using Volume Profile
Opening Range Breakout
linus, 2014 Feb 22, v0.6
declare lower; # for testing on chart.
#hint UseDate: If UseDate is Yes then only scan when the date matches the DateToScanFor input.
input UseDate = No;
#hint DateToScanFor: if UseDate = Yes then set to the date on which the scanner will search;
input DateToScanFor = 20140220;
#hint FindAllBreakouts: If Yes then all breakouts after the opening range will be flagged, else if No then just the first breakout (up or down) will be flagged.
input FindAllBreakouts = Yes;
#hint TradeZoneStartTime: Entry must be at or after this time to be found, in Eastern time.
input TradeZoneStartTime = 930;
#hint TradeZoneEndTime: Entry must be before this time to be found, in Eastern time.
input TradeZoneEndTime = 1600;
#hint MinutesInRange: Duration in minutes of opening range.
input MinutesInRange = 1;
#hint TargetRange: If 0, don't scan for TargetRange. If greater than zero and less than 5 then multiply the height of the range by TargetRange to determine when targets have been hit. [Example: TargetRange = 0.5 scans for price above Range High + ((Height of Range) * 0.5), or price below Range Low - ((Height of Range) * 0.5)].
input TargetRange = 0.0;
#hint price: Price used to signal an entry when crossing opening range.
input price = close;
def dateOK = !UseDate or DaysFromDate(DateToScanFor) == 0;
def startSecs = SecondsFromTime(TradeZoneStartTime);
# True if the current bar is in the opening range.
def inOR = startSecs >= 0 and startSecs < MinutesInRange * 60;
# True if in the trade zone.
def inTradeZone = startSecs >= 0 and SecondsTillTime(TradeZoneEndTime) > 0;
# H2, L2 store the current high and low of opening range.
def H2 = if !inTradeZone then Double.NaN else if inOR and !inOR[1] then high else if inOR and H2[1] < high then high else H2[1];
def L2 = if !inTradeZone then Double.NaN else if inOR and !inOR[1] then low else if inOR and L2[1] > low then low else L2[1];
# pastOR is 0 if not in the trading zone, or in the opening range. pastOR is 1 if at the first bar after the opening range. pastOR is 2 if past the first bar after range.
def pastOR = CompoundValue(1, if !inTradeZone or inOR or !dateOK then 0 else if !inOR and inOR[1] then 1 else if pastOR[1] == 1 then 2 else pastOR[1], 0);
def target = if !pastOR then 0 else if TargetRange > 0 and TargetRange < 5 then (H2 - L2) * TargetRange else 0;
# Breakout is 1 if price has crossed above opening range, -1 if price has crossed below then opening range, else is 0.
def signal = compoundValue(1,
if !pastOR then 0
else if signal[1] != 0 and !FindAllBreakouts then signal[1]
else if price > H2 + target then 1
else if price < L2 - target then -1
else 0
, 0);
plot Breakout = if !isNaN(close) then signal else Double.NaN;
Breakout.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
Breakout.AssignValueColor(if Breakout > 0 then Color.GREEN else if Breakout < 0 then Color.RED else Color.GRAY);
END SCAN
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.