#//Opening Range Fibonaccis (c) coleJustice
#// This indicator uses the concept of the "Opening Range" to create a Fibonacci zone from the high and low set during a specific time period after open (Defaults to a 30-minute range, 9:30 - 10:00 AM, EST)
#// The Opening Range is a popular tool for intraday technical analysis. Price frequently uses these levels as support/resistance, and a breakout from within the range can be a sign of further movement.
#// The Fibonacci levels are set such that the opening range high/low fall on the +/-0.5 fib. These levels tend to act as areas of support and resistance.
#indicator(title="Opening Range Fibonaccis", shorttitle="Opening Range Fibs", overlay=true)
# Converted by Sam4Cok@Samer800 - 03/2024
input startTime = 930;
input endTime = 1000;
input useAfternoonRange = no; #(false, "Afternoon Range (EST)", inline="afternoon")
input afternoonStart = 1300;
input afternoonEnd = 1400;
input showFibo1 = yes; #(true, title='', group='Fibonacci Levels', inline='1')
input fibLevel1 = 0.236; #, title='', group='Fibonacci Levels', inline='1')
input showFib1_line = yes; #(true, title='Line', group='Fibonacci Levels', inline='1')
input showFibo2 = yes; #(true, title='', group='Fibonacci Levels', inline='2')
input fibLevel2 = 0.382; #, title='', group='Fibonacci Levels', inline='2')
input showFib2_line = no; #(false, title='Line', group='Fibonacci Levels', inline='2')
input showFibo3 = yes; #(true, title='', group='Fibonacci Levels', inline='3')
input fibLevel3 = 0.5; #, title='', group='Fibonacci Levels', inline='3')
input showFib3_line = yes; #(true, title='Line', group='Fibonacci Levels', inline='3')
input showFibo4 = yes; #(true, title='', group='Fibonacci Levels', inline='4')
input fibLevel4 = 0.618; #, title='', group='Fibonacci Levels', inline='4')
input showFib4_line = no; #(false, title='Line', group='Fibonacci Levels', inline='4')
input showFibo5 = yes; #(true, title='', group='Fibonacci Levels', inline='5')
input fibLevel5 = 0.786; #, title='', group='Fibonacci Levels', inline='5')
input showFib5_line = no; #(false, title='Line', group='Fibonacci Levels', inline='5')
input showFibo6 = yes; #(true, title='', group='Fibonacci Levels', inline='6')
input fibLevel6 = 1.0; #, title='', group='Fibonacci Levels', inline='6')
input showFib6_line = yes; #(true, title='Line', group='Fibonacci Levels', inline='6')
input dynamic = yes; #(true, title='Dynamically Toggle Higher Fib Levels'
input showFibo7 = yes; #(true, title='', inline='7', group='Overridden by Dynamic Mode')
input fibLevel7 = 1.618; #, title='', inline='7', group='Overridden by Dynamic Mode')
input showFib7_line = yes; #(true, title='Line', group='Overridden by Dynamic Mode', inline='7')
input showFibo8 = no; #(false, title='', inline='8', group='Overridden by Dynamic Mode')
input fibLevel8 = 2.618; #, title='', inline='8', group='Overridden by Dynamic Mode')
input showFib8_line = yes; #(true, title='Line', group='Overridden by Dynamic Mode', inline='8')
input showFibo9 = no; #(false, title='', inline='9', group='Overridden by Dynamic Mode')
input fibLevel9 = 3.618; #, title='', inline='9', group='Overridden by Dynamic Mode')
input showFib9_line = yes; #(true, title='Line', group='Overridden by Dynamic Mode', inline='9')
input showFibo10 = no; #(false, title='', inline='10', group='Overridden by Dynamic Mode')
input fibLevel10 = 4.236; #, title='', inline='10', group='Overridden by Dynamic Mode')
input showFib10_line = yes; #(true, title='Line', group='Overridden by Dynamic Mode', inline='10')
input fibScale = 1.0;
input showZonesFill = yes; #(true, title='Fill Zones')
input showZonesOnly = no; #(false, title='Show Zones Only')
input showTodayOnly = no; #(false, title='Plot For Today Only')
def na = Double.NaN;
def today = GetDay() == GetLastDay();
def isToday = if today then yes else if !showTodayOnly then yes else no;
def openingRangeSession = SecondsTillTime(endTime) > 0 and SecondsFromTime(startTime) >= 0;
def afternoonRangePeriod = SecondsTillTime(afternoonEnd) > 0 and SecondsFromTime(afternoonStart) >= 0;
def afternoonRangeSession = if useAfternoonRange then afternoonRangePeriod else openingRangeSession;
#-- Color.
DefineGlobalColor("fib1", CreateColor(244,67,54));
DefineGlobalColor("fib2", CreateColor(129,199,132));
DefineGlobalColor("fib3", CreateColor(76,175,80));
DefineGlobalColor("fib4", CreateColor(0,150,136));
DefineGlobalColor("fib5", CreateColor(100,181,246));
DefineGlobalColor("fib6", CreateColor(255,255,255));
DefineGlobalColor("fib7", CreateColor(33,150,243));
DefineGlobalColor("fib8", CreateColor(244,67,54));
DefineGlobalColor("fib9", CreateColor(156,39,176));
DefineGlobalColor("fib10", CreateColor(233,30,99));
def hod = high(Period = "DAY");
def lod = low(Period = "DAY");
def timeframe_low = low;
def timeframe_high = high;
def openingRangeHigh;
def openingRangeLow;
if openingRangeSession {
if !openingRangeSession[1] {
openingRangeLow = timeframe_low;
openingRangeHigh = timeframe_high;
} else {
openingRangeLow = Min(timeframe_low, openingRangeLow[1]);
openingRangeHigh = Max(timeframe_high, openingRangeHigh[1]);
}
} else if afternoonRangeSession {
if !afternoonRangeSession[1] {
openingRangeLow = timeframe_low;
openingRangeHigh = timeframe_high;
} else {
openingRangeLow = Min(timeframe_low, openingRangeLow[1]);
openingRangeHigh = Max(timeframe_high, openingRangeHigh[1]);
}
} else {
openingRangeLow = openingRangeLow[1];
openingRangeHigh = openingRangeHigh[1];
}
def openingRangeMid = openingRangeLow + ((openingRangeHigh - openingRangeLow) / 2);
def openingRangeFib_1_High = openingRangeMid + ((openingRangeHigh - openingRangeLow) * fibLevel1 * fibScale);
def openingRangeFib_1_Low = openingRangeMid - ((openingRangeHigh - openingRangeLow) * fibLevel1 * fibScale);
def openingRangeFib_2_High = openingRangeMid + ((openingRangeHigh - openingRangeLow) * fibLevel2 * fibScale);
def openingRangeFib_2_Low = openingRangeMid - ((openingRangeHigh - openingRangeLow) * fibLevel2 * fibScale);
def openingRangeFib_3_High = openingRangeMid + ((openingRangeHigh - openingRangeLow) * fibLevel3 * fibScale);
def openingRangeFib_3_Low = openingRangeMid - ((openingRangeHigh - openingRangeLow) * fibLevel3 * fibScale);
def openingRangeFib_4_High = openingRangeMid + ((openingRangeHigh - openingRangeLow) * fibLevel4 * fibScale);
def openingRangeFib_4_Low = openingRangeMid - ((openingRangeHigh - openingRangeLow) * fibLevel4 * fibScale);
def openingRangeFib_5_High = openingRangeMid + ((openingRangeHigh - openingRangeLow) * fibLevel5 * fibScale);
def openingRangeFib_5_Low = openingRangeMid - ((openingRangeHigh - openingRangeLow) * fibLevel5 * fibScale);
def openingRangeFib_6_High = openingRangeMid + ((openingRangeHigh - openingRangeLow) * fibLevel6 * fibScale);
def openingRangeFib_6_Low = openingRangeMid - ((openingRangeHigh - openingRangeLow) * fibLevel6 * fibScale);
def openingRangeFib_7_High = openingRangeMid + ((openingRangeHigh - openingRangeLow) * fibLevel7 * fibScale);
def openingRangeFib_7_Low = openingRangeMid - ((openingRangeHigh - openingRangeLow) * fibLevel7 * fibScale);
def openingRangeFib_8_High = openingRangeMid + ((openingRangeHigh - openingRangeLow) * fibLevel8 * fibScale);
def openingRangeFib_8_Low = openingRangeMid - ((openingRangeHigh - openingRangeLow) * fibLevel8 * fibScale);
def openingRangeFib_9_High = openingRangeMid + ((openingRangeHigh - openingRangeLow) * fibLevel9 * fibScale);
def openingRangeFib_9_Low = openingRangeMid - ((openingRangeHigh - openingRangeLow) * fibLevel9 * fibScale);
def openingRangeFib_10_High = openingRangeMid + ((openingRangeHigh - openingRangeLow) * fibLevel10 * fibScale);
def openingRangeFib_10_Low = openingRangeMid - ((openingRangeHigh - openingRangeLow) * fibLevel10 * fibScale);
def plotCond = isToday and !openingRangeSession and !afternoonRangeSession;
def showFib7;
def showFib7Low;
def showFib8;
def showFib8Low;
def showFib9;
def showFib9Low;
def showFib10;
def showFib10Low;
if dynamic {
showFib7 = hod > openingRangeFib_6_High;
showFib7Low = lod < openingRangeFib_6_Low;
showFib8 = hod > openingRangeFib_7_High;
showFib8Low = lod < openingRangeFib_7_Low;
showFib9 = hod > openingRangeFib_8_High;
showFib9Low = lod < openingRangeFib_8_Low;
showFib10 = hod > openingRangeFib_9_High;
showFib10Low = lod < openingRangeFib_10_Low;
} else {
showFib7 = na;
showFib7Low = showFib7[1];
showFib8 = na;
showFib8Low = showFib8[1];
showFib9 = na;
showFib9Low = showFib9[1];
showFib10 = na;
showFib10Low = showFib10[1];
}
#-- Plot
plot oRHi = if plotCond then openingRangeHigh else na; #"Opening Range High"
plot oRLo = if plotCond then openingRangeLow else na; #"Opening Range Low"
plot oRMi = if plotCond then openingRangeMid else na; #"Opening Range Mid"
oRHi.SetStyle(Curve.POINTS);
oRLo.SetStyle(Curve.POINTS);
oRMi.SetStyle(Curve.SHORT_DASH);
oRHi.SetDefaultColor(Color.WHITE);
oRLo.SetDefaultColor(Color.WHITE);
oRMi.SetDefaultColor(Color.WHITE);
plot oRFib1Hi = if plotCond and showFibo1 then openingRangeFib_1_High else na;
plot oRFib1Lo = if plotCond and showFibo1 then openingRangeFib_1_Low else na;
plot oRFib2Hi = if plotCond and showFibo2 then openingRangeFib_2_High else na;
plot oRFib2Lo = if plotCond and showFibo2 then openingRangeFib_2_Low else na;
plot oRFib3Hi = if plotCond and showFibo3 then openingRangeFib_3_High else na;
plot oRFib3Lo = if plotCond and showFibo3 then openingRangeFib_3_Low else na;
plot oRFib4Hi = if plotCond and showFibo4 then openingRangeFib_4_High else na;
plot oRFib4Lo = if plotCond and showFibo4 then openingRangeFib_4_Low else na;
plot oRFib5Hi = if plotCond and showFibo5 then openingRangeFib_5_High else na;
plot oRFib5Lo = if plotCond and showFibo5 then openingRangeFib_5_Low else na;
plot oRFib6Hi = if plotCond and showFibo6 then openingRangeFib_6_High else na;
plot oRFib6Lo = if plotCond and showFibo6 then openingRangeFib_6_Low else na;
plot oRFib7Hi = if plotCond and showFib7 then openingRangeFib_7_High else na;
plot oRFib7Lo = if plotCond and showFib7Low then openingRangeFib_7_Low else na;
plot oRFib8Hi = if plotCond and showFib8 then openingRangeFib_8_High else na;
plot oRFib8Lo = if plotCond and showFib8Low then openingRangeFib_8_Low else na;
plot oRFib9Hi = if plotCond and showFib9 then openingRangeFib_9_High else na;
plot oRFib9Lo = if plotCond and showFib9Low then openingRangeFib_9_Low else na;
plot oRFib10Hi = if plotCond and showFib10 then openingRangeFib_10_High else na;
plot oRFib10Lo = if plotCond and showFib10Low then openingRangeFib_10_Low else na;
oRFib1Hi.SetHiding(showZonesOnly or !showFib1_line);
oRFib1Lo.SetHiding(showZonesOnly or !showFib1_line);
oRFib2Hi.SetHiding(showZonesOnly or !showFib2_line);
oRFib2Lo.SetHiding(showZonesOnly or !showFib2_line);
oRFib3Hi.SetHiding(showZonesOnly or !showFib3_line);
oRFib3Lo.SetHiding(showZonesOnly or !showFib3_line);
oRFib4Hi.SetHiding(showZonesOnly or !showFib4_line);
oRFib4Lo.SetHiding(showZonesOnly or !showFib4_line);
oRFib5Hi.SetHiding(showZonesOnly or !showFib5_line);
oRFib5Lo.SetHiding(showZonesOnly or !showFib5_line);
oRFib6Hi.SetHiding(showZonesOnly or !showFib6_line);
oRFib6Lo.SetHiding(showZonesOnly or !showFib6_line);
oRFib7Hi.SetHiding(showZonesOnly or !showFib7_line);
oRFib7Lo.SetHiding(showZonesOnly or !showFib7_line);
oRFib8Hi.SetHiding(showZonesOnly or !showFib8_line);
oRFib8Lo.SetHiding(showZonesOnly or !showFib8_line);
oRFib9Hi.SetHiding(showZonesOnly or !showFib9_line);
oRFib9Lo.SetHiding(showZonesOnly or !showFib9_line);
oRFib10Hi.SetHiding(showZonesOnly or !showFib10_line);
oRFib10Lo.SetHiding(showZonesOnly or !showFib10_line);
oRFib1Hi.SetDefaultColor(GlobalColor("fib1"));
oRFib1Lo.SetDefaultColor(GlobalColor("fib1"));
oRFib2Hi.SetDefaultColor(GlobalColor("fib2"));
oRFib2Lo.SetDefaultColor(GlobalColor("fib2"));
oRFib3Hi.SetDefaultColor(GlobalColor("fib3"));
oRFib3Lo.SetDefaultColor(GlobalColor("fib3"));
oRFib4Hi.SetDefaultColor(GlobalColor("fib4"));
oRFib4Lo.SetDefaultColor(GlobalColor("fib4"));
oRFib5Hi.SetDefaultColor(GlobalColor("fib5"));
oRFib5Lo.SetDefaultColor(GlobalColor("fib5"));
oRFib6Hi.SetDefaultColor(GlobalColor("fib6"));
oRFib6Lo.SetDefaultColor(GlobalColor("fib6"));
oRFib7Hi.SetDefaultColor(GlobalColor("fib7"));
oRFib7Lo.SetDefaultColor(GlobalColor("fib7"));
oRFib8Hi.SetDefaultColor(GlobalColor("fib8"));
oRFib8Lo.SetDefaultColor(GlobalColor("fib8"));
oRFib9Hi.SetDefaultColor(GlobalColor("fib9"));
oRFib9Lo.SetDefaultColor(GlobalColor("fib9"));
oRFib10Hi.SetDefaultColor(GlobalColor("fib10"));
oRFib10Lo.SetDefaultColor(GlobalColor("fib10"));
AddCloud(if showZonesFill and showFibo1 then oRMi else na, oRFib1Hi, GlobalColor("fib1"), GlobalColor("fib1"));
AddCloud(if showZonesFill and showFibo1 then oRMi else na, oRFib1Lo, GlobalColor("fib1"), GlobalColor("fib1"));
AddCloud(if showZonesFill and showFibo2 then oRFib1Hi else na, oRFib2Hi, GlobalColor("fib2"), GlobalColor("fib2"));
AddCloud(if showZonesFill and showFibo2 then oRFib1Lo else na, oRFib2Lo, GlobalColor("fib2"), GlobalColor("fib2"));
AddCloud(if showZonesFill and showFibo3 then oRFib2Hi else na, oRFib3Hi, GlobalColor("fib3"), GlobalColor("fib3"));
AddCloud(if showZonesFill and showFibo3 then oRFib2Lo else na, oRFib3Lo, GlobalColor("fib3"), GlobalColor("fib3"));
AddCloud(if showZonesFill and showFibo4 then oRFib3Hi else na, oRFib4Hi, GlobalColor("fib4"), GlobalColor("fib4"));
AddCloud(if showZonesFill and showFibo4 then oRFib3Lo else na, oRFib4Lo, GlobalColor("fib4"), GlobalColor("fib4"));
AddCloud(if showZonesFill and showFibo5 then oRFib4Hi else na, oRFib5Hi, GlobalColor("fib5"), GlobalColor("fib5"));
AddCloud(if showZonesFill and showFibo5 then oRFib4Lo else na, oRFib5Lo, GlobalColor("fib5"), GlobalColor("fib5"));
AddCloud(if showZonesFill and showFibo6 then oRFib5Hi else na, oRFib6Hi, GlobalColor("fib6"), GlobalColor("fib6"));
AddCloud(if showZonesFill and showFibo6 then oRFib5Lo else na, oRFib6Lo, GlobalColor("fib6"), GlobalColor("fib6"));
AddCloud(if showZonesFill and showFib7 then oRFib6Hi else na, oRFib7Hi, GlobalColor("fib7"), GlobalColor("fib7"));
AddCloud(if showZonesFill and showFib7 then oRFib6Lo else na, oRFib7Lo, GlobalColor("fib7"), GlobalColor("fib7"));
AddCloud(if showZonesFill and showFib8 then oRFib7Hi else na, oRFib8Hi, GlobalColor("fib8"), GlobalColor("fib8"));
AddCloud(if showZonesFill and showFib8 then oRFib7Lo else na, oRFib8Lo, GlobalColor("fib8"), GlobalColor("fib8"));
AddCloud(if showZonesFill and showFib9 then oRFib8Hi else na, oRFib9Hi, GlobalColor("fib9"), GlobalColor("fib9"));
AddCloud(if showZonesFill and showFib9 then oRFib8Lo else na, oRFib9Lo, GlobalColor("fib9"), GlobalColor("fib9"));
AddCloud(if showZonesFill and showFib10 then oRFib9Hi else na, oRFib10Hi, GlobalColor("fib10"), GlobalColor("fib10"));
AddCloud(if showZonesFill and showFib10 then oRFib9Lo else na, oRFib10Lo, GlobalColor("fib10"), GlobalColor("fib10"));
#-- END of CODE