- Platform
-
- Thinkorswim
This indicator plots the premarket High and Low, and Fibonacci retracements. Make sure pre-market data is turned on.

Code:
# PreMarket High/Low and Fibs
# Assembled for b4indicators.com
# Free for use. Header credits must be included when any form of the code included in this package is used.
# User assumes all risk. Author not responsible for errors or use of tool.
# v1.0 - barbaros
# v1.1 - barbaros - Added showing only today or historical levels
# v1.2 - barbaros - Added extra fibs
input ShowOnlyToday = yes;
input ShowLabels = yes;
input plotHighFib1 = yes;
input highFibCoefficient1 = -1.0;
input plotHighFib2 = yes;
input highFibCoefficient2 = -0.786;
input plotHighFib3 = yes;
input highFibCoefficient3 = -0.618;
input plotHighFib4 = yes;
input highFibCoefficient4 = -0.5;
input plotHighFib5 = yes;
input highFibCoefficient5 = -0.382;
input plotHighFib6 = yes;
input highFibCoefficient6 = -0.236;
input plotFib1 = yes;
input fibCoefficient1 = 0.236;
input plotFib2 = yes;
input fibCoefficient2 = 0.382;
input plotFib3 = yes;
input fibCoefficient3 = 0.5;
input plotFib4 = yes;
input fibCoefficient4 = 0.618;
input plotFib5 = yes;
input fibCoefficient5 = 0.786;
input plotLowFib1 = yes;
input LowfibCoefficient1 = 1.236;
input plotLowFib2 = yes;
input LowfibCoefficient2 = 1.382;
input plotLowFib3 = yes;
input LowfibCoefficient3 = 1.5;
input plotLowFib4 = yes;
input LowfibCoefficient4 = 1.618;
input plotLowFib5 = yes;
input LowfibCoefficient5 = 1.786;
input plotLowFib6 = yes;
input LowfibCoefficient6 = 2.0;
def okToPlot = !ShowOnlyToday or (GetLastDay() <= GetDay() and GetLastYear() <= GetYear());
def regularSessionHours = RegularTradingStart(GetYYYYMMDD()) <= GetTime();
def extendedSessionHours = RegularTradingStart(GetYYYYMMDD()) >= GetTime();
def extendedSessionStart = regularSessionHours[1] and extendedSessionHours;
def regularSessionStart = extendedSessionHours[1] and regularSessionHours;
def extendedSessionHigh = CompoundValue(1, if extendedSessionStart then high else if extendedSessionHours then Max(high, extendedSessionHigh[1]) else extendedSessionHigh[1], 0);
def extendedSessionLow = CompoundValue(1, if extendedSessionStart then low else if extendedSessionHours then Min(low, extendedSessionLow[1]) else extendedSessionLow[1], 0);
def regularSessionHigh = CompoundValue(1, if regularSessionStart then high else if regularSessionHours then Max(high, regularSessionHigh[1]) else regularSessionHigh[1], 0);
def regularSessionLow = CompoundValue(1, if regularSessionStart then low else if regularSessionHours then Min(low, regularSessionLow[1]) else regularSessionLow[1], 0);
# Overnight high/low during regular market hours
plot overnightHigh = if okToPlot and regularSessionHours then extendedSessionHigh else Double.NaN;
overnightHigh.SetDefaultColor(Color.GREEN);
overnightHigh.SetLineWeight(3);
plot overnightLow = if okToPlot and regularSessionHours then extendedSessionLow else Double.NaN;
overnightLow.SetDefaultColor(Color.RED);
overnightLow.SetLineWeight(3);
# Fib retracements and extensions
def overnightRange = overnightHigh - overnightLow;
plot highFibLevel1 = if plotHighFib1 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * highFibCoefficient1) else Double.NaN;
highFibLevel1.SetDefaultColor(Color.WHITE);
highFibLevel1.SetPaintingStrategy(PaintingStrategy.DASHES);
highFibLevel1.HideBubble();
highFibLevel1.HideTitle();
plot highFibLevel2 = if plotHighFib2 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * highFibCoefficient2) else Double.NaN;
highFibLevel2.SetDefaultColor(Color.WHITE);
highFibLevel2.SetPaintingStrategy(PaintingStrategy.DASHES);
highFibLevel2.HideBubble();
highFibLevel2.HideTitle();
plot highFibLevel3 = if plotHighFib3 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * highFibCoefficient3) else Double.NaN;
highFibLevel3.SetDefaultColor(Color.WHITE);
highFibLevel3.SetPaintingStrategy(PaintingStrategy.DASHES);
highFibLevel3.HideBubble();
highFibLevel3.HideTitle();
plot highFibLevel4 = if plotHighFib4 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * highFibCoefficient4) else Double.NaN;
highFibLevel4.SetDefaultColor(Color.WHITE);
highFibLevel4.SetPaintingStrategy(PaintingStrategy.DASHES);
highFibLevel4.HideBubble();
highFibLevel4.HideTitle();
plot highFibLevel5 = if plotHighFib5 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * highFibCoefficient5) else Double.NaN;
highFibLevel5.SetDefaultColor(Color.WHITE);
highFibLevel5.SetPaintingStrategy(PaintingStrategy.DASHES);
highFibLevel5.HideBubble();
highFibLevel5.HideTitle();
plot highFibLevel6 = if plotHighFib6 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * highFibCoefficient6) else Double.NaN;
highFibLevel6.SetDefaultColor(Color.WHITE);
highFibLevel6.SetPaintingStrategy(PaintingStrategy.DASHES);
highFibLevel6.HideBubble();
highFibLevel6.HideTitle();
plot fibLevel1 = if plotFib1 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * fibCoefficient1) else Double.NaN;
FibLevel1.SetDefaultColor(Color.WHITE);
FibLevel1.SetPaintingStrategy(PaintingStrategy.DASHES);
FibLevel1.HideBubble();
FibLevel1.HideTitle();
plot fibLevel2 = if plotFib2 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * fibCoefficient2) else Double.NaN;
FibLevel2.SetDefaultColor(Color.WHITE);
FibLevel2.SetPaintingStrategy(PaintingStrategy.DASHES);
FibLevel2.HideBubble();
FibLevel2.HideTitle();
plot fibLevel3 = if plotFib3 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * fibCoefficient3) else Double.NaN;
FibLevel3.SetDefaultColor(Color.WHITE);
FibLevel3.SetPaintingStrategy(PaintingStrategy.DASHES);
FibLevel3.HideBubble();
FibLevel3.HideTitle();
plot fibLevel4 = if plotFib4 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * fibCoefficient4) else Double.NaN;
FibLevel4.SetDefaultColor(Color.WHITE);
FibLevel4.SetPaintingStrategy(PaintingStrategy.DASHES);
FibLevel4.HideBubble();
FibLevel4.HideTitle();
plot fibLevel5 = if plotFib5 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * fibCoefficient5) else Double.NaN;
FibLevel5.SetDefaultColor(Color.WHITE);
FibLevel5.SetPaintingStrategy(PaintingStrategy.DASHES);
FibLevel5.HideBubble();
FibLevel5.HideTitle();
plot lowFibLevel1 = if plotLowFib1 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * lowFibCoefficient1) else Double.NaN;
lowFibLevel1.SetDefaultColor(Color.WHITE);
lowFibLevel1.SetPaintingStrategy(PaintingStrategy.DASHES);
lowFibLevel1.HideBubble();
lowFibLevel1.HideTitle();
plot lowFibLevel2 = if plotLowFib2 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * lowFibCoefficient2) else Double.NaN;
lowFibLevel2.SetDefaultColor(Color.WHITE);
lowFibLevel2.SetPaintingStrategy(PaintingStrategy.DASHES);
lowFibLevel2.HideBubble();
lowFibLevel2.HideTitle();
plot lowFibLevel3 = if plotLowFib3 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * lowFibCoefficient3) else Double.NaN;
lowFibLevel3.SetDefaultColor(Color.WHITE);
lowFibLevel3.SetPaintingStrategy(PaintingStrategy.DASHES);
lowFibLevel3.HideBubble();
lowFibLevel3.HideTitle();
plot lowFibLevel4 = if plotLowFib4 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * lowFibCoefficient4) else Double.NaN;
lowFibLevel4.SetDefaultColor(Color.WHITE);
lowFibLevel4.SetPaintingStrategy(PaintingStrategy.DASHES);
lowFibLevel4.HideBubble();
lowFibLevel4.HideTitle();
plot lowFibLevel5 = if plotLowFib5 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * lowFibCoefficient5) else Double.NaN;
lowFibLevel5.SetDefaultColor(Color.WHITE);
lowFibLevel5.SetPaintingStrategy(PaintingStrategy.DASHES);
lowFibLevel5.HideBubble();
lowFibLevel5.HideTitle();
plot lowFibLevel6 = if plotLowFib6 and okToPlot and regularSessionHours then overnightHigh - (overnightRange * lowFibCoefficient6) else Double.NaN;
lowFibLevel6.SetDefaultColor(Color.WHITE);
lowFibLevel6.SetPaintingStrategy(PaintingStrategy.DASHES);
lowFibLevel6.HideBubble();
lowFibLevel6.HideTitle();
# Chart bubbles
DefineGlobalColor("Labels", Color.WHITE);
AddChartBubble(ShowLabels and plotHighFib1 and regularSessionStart, highFibLevel1, highFibCoefficient1, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotHighFib3 and regularSessionStart, highFibLevel3, highFibCoefficient3, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotHighFib2 and regularSessionStart, highFibLevel2, highFibCoefficient2, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotHighFib4 and regularSessionStart, highFibLevel4, highFibCoefficient4, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotHighFib5 and regularSessionStart, highFibLevel5, highFibCoefficient5, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotHighFib6 and regularSessionStart, highFibLevel6, highFibCoefficient6, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotFib1 and regularSessionStart, fibLevel1, fibCoefficient1, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotFib2 and regularSessionStart, fibLevel2, fibCoefficient2, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotFib3 and regularSessionStart, fibLevel3, fibCoefficient3, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotFib4 and regularSessionStart, fibLevel4, fibCoefficient4, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotFib5 and regularSessionStart, fibLevel5, fibCoefficient5, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotLowfib1 and regularSessionStart, lowFibLevel1, lowFibCoefficient1, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotLowfib2 and regularSessionStart, lowFibLevel2, lowFibCoefficient2, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotLowfib3 and regularSessionStart, lowFibLevel3, lowFibCoefficient3, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotLowfib4 and regularSessionStart, lowFibLevel4, lowFibCoefficient4, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotLowfib5 and regularSessionStart, lowFibLevel5, lowFibCoefficient5, GlobalColor("Labels"), no);
AddChartBubble(ShowLabels and plotLowfib6 and regularSessionStart, lowFibLevel6, lowFibCoefficient6, GlobalColor("Labels"), no);
Last edited: