Pre-market High Low Indicator with Fibonacci for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
This indicator for ThinkorSwim will automatically plot overnight High and Low on your chart. In addition, the indicator will also include Fibonacci retracement based on the highest and lowest values from pre-market.

This can be useful for anyone who often plays pre-market breakout or breakdown. You may want to check out this strategy as well.



thinkScript Code

Rich (BB code):
# GlobeX or Overnight High / Low with Fibonacci Values 

# Mobius 

# V01.2012 

input PlotOverNightExtremes = yes;

input coeff_1 = .236;

input coeff_2 = .327;

# gmh: added the rest of the Fibs 

input coeff_3 = .500;

input coeff_4 = .618;

input coeff_5 = .789;

input coeff_6 = .882;



def o = open;

def h = high;

def l = low;

def c = close;

def v = volume;

def bar = BarNumber();

def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());

def vol = if GlobeX and !Globex[1]

          then v

          else if GlobeX

               then vol[1] + v

               else Double.NaN;

def GlobeX_Volume = vol;

def ONhigh = if GlobeX and !Globex[1]

             then h

             else if Globex and

                     h > ONhigh[1]

                     then h

                  else ONhigh[1];

def ONhighBar = if GlobeX and h == ONhigh

                then Bar

                else double.nan;

def ONlow = if GlobeX and !GlobeX[1]

            then l

            else if GlobeX and

                    l < ONlow[1]

            then l

                 else ONlow[1];

def ONlowBar = if GlobeX and l == ONlow

               then Bar

               else double.nan;

def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)

                    then ONhigh

                    else OverNightHigh[1];

def OverNightLow = if BarNumber() == HighestAll(ONlowBar)

                   then ONlow

                   else OverNightLow[1];

plot ONH = if OverNightHigh > 0

           then OverNightHigh

           else Double.NaN;

     ONH.SetHiding(!PlotOverNightExtremes);

     ONH.SetPaintingStrategy(PaintingStrategy.SQUARES);

     ONH.SetDefaultColor(Color.BLUE);

     ONH.HideBubble();

     ONH.HideTitle();

plot ONL = if OverNightLow > 0

           then OverNightLow

           else Double.NaN;

     ONL.SetHiding(!PlotOverNightExtremes);

     ONL.SetPaintingStrategy(PaintingStrategy.SQUARES);

     ONL.SetDefaultColor(Color.LIGHT_GRAY);

     ONL.HideBubble();

     ONL.HideTitle();



def MaxBar = Max(HighestAll(ONhighBar), HighestAll(ONlowBar));



plot coeff1 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_1) + OverNightLow

              else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_1)

              else double.nan;

plot coeff2 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_2) + OverNightLow

               else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_2)

              else double.nan;

plot coeff3 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_3) + OverNightLow

              else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_3)

              else double.nan;

plot coeff4 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_4) + OverNightLow

              else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_4)

              else double.nan;

plot coeff5 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_5) + OverNightLow

              else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_5)

              else double.nan;

plot coeff6 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_6) + OverNightLow

              else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_6)

              else double.nan;

# 

# End Code GlobeX High Low with Fibs 

Shareable Link

 
Last edited:
T

Tom4235

New member
hey! can you help create a script so a h and l are automatically drawn out? thanks!
 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@Tom4235 I think this is what you're talking about.

Rich (BB code):
# Archive Name: GlobeX or Overnight High / Low v.07.2017
# Archive Section: Support Resistance
# Suggested Tos Name: GlobeX_HighLow_v2017_Mobius
# Archive Date: 5.06.2018 May 6, 2018
# Archive Notes: This looks to be a second version

# GlobeX or Overnight High / Low
# Mobius
# V01.2012
# V07.2017 Replaced Time Brackets with GetTime() function which works better with Mobile

input PlotOverNightExtremes = yes;

def h = high;
def l = low;
def bar = BarNumber();
def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());
def ONhigh = if GlobeX and !Globex[1]
             then h
             else if Globex and
                     h > ONhigh[1]
                  then h
                  else ONhigh[1];
def ONhighBar = if GlobeX and h == ONhigh
                then Bar
                else double.nan;
def ONlow = if GlobeX and !GlobeX[1]
            then l
            else if GlobeX and 
                    l < ONlow[1]
                 then l
                 else ONlow[1];
def ONlowBar = if GlobeX and l == ONlow
               then Bar
               else double.nan;
def OverNightHigh = if BarNumber() == HighestAll(ONhighBar) 
                    then ONhigh
                    else OverNightHigh[1];
def OverNightLow = if BarNumber() == HighestAll(ONlowBar) 
                   then ONlow
                   else OverNightLow[1];
plot ONH = if OverNightHigh > 0
           then OverNightHigh
           else Double.NaN;
ONH.SetHiding(!PlotOverNightExtremes);
ONH.SetPaintingStrategy(PaintingStrategy.SQUARES);
ONH.SetDefaultColor(Color.BLUE);
ONH.HideBubble();
ONH.HideTitle();
plot ONL = if OverNightLow > 0
           then OverNightLow
           else Double.NaN;
ONL.SetHiding(!PlotOverNightExtremes);
ONL.SetPaintingStrategy(PaintingStrategy.SQUARES);
ONL.SetDefaultColor(Color.GRAY);
ONL.HideBubble();
ONL.HideTitle();
AddLabel(GlobeX, "GlobeX Range = " + AsDollars(ONH - ONL), color.white);
AddChartBubble(bar == ONhighBar and PlotOverNightExtremes, ONH, "ONH", Color.BLUE);
AddChartBubble(bar == ONlowBar and PlotOverNightExtremes, ONL, "ONL", Color.GRAY, 0);
Alert((close crosses above ONH) or (close crosses below ONL), "", Alert.Bar, Sound.Bell);
# End Code GlobeX or Overnight High / Low v.07.2017
 
Last edited:
T

thinky

Member
@Tom4235 The labels are hard coded in the script, but you can remove them by commenting ('#' in front) lines 59 and 60:

59 # AddChartBubble(bar == ONhighBar and PlotOverNightExtremes, ONH, "ONH", Color.BLUE);
60 # AddChartBubble(bar == ONlowBar and PlotOverNightExtremes, ONL, "ONL", Color.GRAY, 0);
 
M

Mlentsch0

New member
VIP
tried to make it work. does it only work on a certain time frame? when I put it in I just dont see any changed to chart
 
BenTen

BenTen

Administrative
Staff
VIP
@tenacity11 @Mlentsch0 Working for me. Did you guys turn on extended market hours? It's in the Settings page under Equities.

 
R

RandyR

New member
FYI, both of the above scripts only include overnight prices starting at midnight Eastern time. In other words, they do not include prices from the after market trading up until midnight. In other words, they do not include the entire Globex session.

hey! thank you so much, I am very grateful for your help! just seeing if there's a way to get rid of the ONH/ONL label on the chart and have a label top left corner instead so I can read something like "ONH = 20.89" "ONL = 17.82". Looks really great as is, so if this is not possible, I will be more than happy!!
Replace:
Code:
AddChartBubble(bar == ONhighBar and PlotOverNightExtremes, ONH, "ONH", Color.BLUE);
AddChartBubble(bar == ONlowBar and PlotOverNightExtremes, ONL, "ONL", Color.GRAY, 0);
with:
Code:
AddLabel(yes, "ONH = " + ONH, ONH.TakeValueColor());
AddLabel(yes, "ONL = " + ONL, ONL.TakeValueColor());
 
BenTen

BenTen

Administrative
Staff
VIP
@RandyR Here is code for entire Globex

Code:
# Globex, RTH and prior RTH High and Low
# Request for JQ 11.8.18
# v0.02 11.12.18 will plot prior RTH during current RTH
# Nube

    # inputs
input bubbles = yes;

    # univerals
def na = Double.NaN;
def bn = BarNumber();
def h  = high;
def l  = low;

Script prior {
# subscript for getting prior value of a BarNumber() defined variable
    input prior = close;
    def   priorOf = if prior != prior[1] then prior[1] else priorOf[1];
    plot  priorBar = priorOf;
}
  
   # variables
def cb   = HighestAll(if !IsNaN(h) then bn else na);
def time = GetTime();
def rts  = RegularTradingStart(GetYYYYMMDD());
def rte  = RegularTradingEnd(GetYYYYMMDD());

def RTH = if   time crosses above rts
          then bn else RTH[1];
def globex = if   time crosses below rte
             then bn else globex[1];
# If you want to include the extended session in Globex, then use globex def below
#def globex = if   time crosses above rte
 #            then bn else globex[1];

def priorRTH    = prior(RTH);
def priorGlobex = prior(globex);
def hRTH  = HighestAll(RTH);
def hGX   = HighestAll(globex);
def hPRTH = HighestAll(priorRTH);
def hPGX  = HighestAll(priorGlobex);

def gXhigh = HighestAll(if   bn >= hGX && bn < hRTH
                        then h else if hRTH < hGX && bn >= hGX
                                    then h else na);
def gXlow = LowestAll(if   bn >= hGX && bn < hRTH
                      then l else if hRTH < hGX && bn >= hGX
                                  then l else na);
def RTHhigh = HighestAll(if   bn >= hRTH && bn < hGX
                         then h else if hGX < hRTH && bn >= hRTH
                                    then h else na);
def RTHlow = LowestAll(if   bn >= hRTH && bn < hGX
                       then l else if hGX < hRTH && bn >= hRTH
                                   then l else na);

def priorRTHhigh = HighestAll(if   bn >= hPRTH
                              &&   bn <  if   hGX < hRTH
                                         then hGX
                                         else hPGX
                              then h else na);
def priorRTHlow = LowestAll(if   bn >= hPRTH
                            &&   bn <  if   hGX < hRTH
                                       then hGX
                                       else hPGX
                            then l else na);
                                  
plot
GlobexHigh = gXhigh;
GlobexHigh.SetDefaultColor(Color.Light_Green);
plot
GlobexLow = gXlow;
GlobexLow.SetDefaultColor(Color.Pink);

plot
HighRTH = RTHhigh;
HighRTH.SetDefaultColor(Color.Green);
plot
LowRTH  = RTHlow;
LowRTH.SetDefaultColor(Color.Red);

plot
PreviousHighRTH = priorRTHhigh;
PreviousHighRTH.SetDefaultColor(Color.Dark_Green);
plot
PreviousLowRTH  = priorRTHlow;
PreviousLowRTH.SetDefaultColor(Color.Dark_Red);

AddChartBubble(bubbles && bn == cb, gXhigh, "Globex High", Color.Light_Green);
AddChartBubble(bubbles && bn == cb, RTHhigh, "RTH High", Color.Green);
AddChartBubble(bubbles && bn == cb, priorRTHhigh, "Previous\n RTH High", Color.Dark_Green);
AddChartBubble(bubbles && bn == cb, gXlow, "Globex Low", Color.Pink,0);
AddChartBubble(bubbles && bn == cb, RTHlow, "RTH Low", Color.Red,0);
AddChartBubble(bubbles && bn == cb, priorRTHlow, "Previous\n RTH Low", Color.Dark_Red,0);
# f/ Globex, RTH and prior RTH High and Low
 
R

RandyR

New member
@BenTen thanks. As is above, that doesn't work. I put it on an AMZN 15m chart and the Globex Low and High lines do not include prices from after hours trading until midnight ET. I also put it on an INTC 15m chart with the same results. I also tried /ES, /NQ, and /YM and it didn't plot any Globex High/Low lines on those charts.

I then found the comment and the alternate def of globex and tried that, which seems to work.
 
B

Barak13

New member
@BenTen Hi new user here! This is really cool! Is there a way to get an alert for a specific coefficient? specifically the 50%. I tried to set an alert in ugaz but got an error message. This is what I would like to be able to do:
Be alerted for all stocks that close above the 50% level, I use the 1, 2, and 5min chart, so I would set up a watchlist and they all pop up in there, so I can go through them in more detail
 
J

Johnnyboyeh

New member
Hey, I have a similar question to the poster above me who is asking if there is a way to set an alert for this study based on a specific coefficient be broken above or below. I would like to be alerted if the stock breaks the premarket high or low in this study. Thanks.
 
T

tomsk

Well-known member
VIP
@Johnnyboyeh This study has the following coefficients defined:

Code:
input coeff_1 = .236;
input coeff_2 = .327;
input coeff_3 = .500;
input coeff_4 = .618;
input coeff_5 = .789;
input coeff_6 = .882;
Note that some of these coefficients are not fibonacci ratios e.g. .327, .789, .882
I imagine that the author might have wanted those levels for reasons known to him.

Suppose you want to be alerted if the price closes above/below the 50% coefficient, just add the following lines to the end of the study

Alert(close crosses below coeff3, "Below 50% Fib", Alert.Bar, Sound.Ring);
Alert(close crosses above coeff3, "Above 50% Fib", Alert.Bar, Sound.Ding);

Hope this helps
 
Last edited:
Thread starter Similar threads Forum Replies Date
W Pre-market scanner for stocks moving sideways? Questions 2
V Pre-Market Change PMO to PMC/RTCO Questions 1
B Pre Market Range Questions 7
I Receive alerts pre and post market? Questions 5
S Pre-Market Volume Question Questions 0
Top