Initial Balance Indicator for ThinkorSwim

Hi guys,

I found an Initial Balance indicator that plots the high and low of the initial balance for those who are interested. I'm wondering if someone can help add extensions to the initial Balance?

I'm looking for 50% and 100% extensions on each side of the Initial Balance. Currently, I'm stuck doing it manually, and it's really annoying.


Code:
input opentime = 0930;
input ORend = 1030;
input opacity = 1;
def na = Double.NaN;
#
# Check if the opening range time is now
#
def ORActive = if GetLastDay() == GetDay() and SecondsFromTime(opentime) >= 0 and SecondsFromTime(ORend) <
0 then 1 else 0;
#
# Track the OR high and low
#
def ORHigh = if ORActive then high else na;
def ORLow = if ORActive then low else na;
#
# Plot the OR high and low
#
plot ORAH = if GetLastDay() != GetDay() or !ORActive then na else HighestAll(ORHigh);
plot ORAL = if GetLastDay() != GetDay() or !ORActive then na else LowestAll(ORLow);
plot ORH = if GetLastDay() != GetDay() or SecondsFromTime(ORend) < 0 then na else HighestAll(ORHigh);
plot ORL = if GetLastDay() != GetDay() or SecondsFromTime(ORend) < 0 then na else LowestAll(ORLow);
#
# Formatting
#
ORAH.SetStyle(Curve.SHORT_DASH);
ORAL.SetStyle(Curve.SHORT_DASH);
ORAH.SetDefaultColor(Color.GREEN);
ORAL.SetDefaultColor(Color.RED);
ORH.SetStyle(Curve.SHORT_DASH);
ORL.SetStyle(Curve.SHORT_DASH);
ORH.SetDefaultColor(Color.GREEN);
ORL.SetDefaultColor(Color.RED);
 

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

Code:
input opentime = 0930;
input ORend = 1030;
input opacity = 1;
def na = Double.NaN;
#
# Check if the opening range time is now
#
def ORActive = if GetLastDay() == GetDay() and SecondsFromTime(opentime) >= 0 and SecondsFromTime(ORend) <
0 then 1 else 0;
#
# Track the OR high and low
#
def ORHigh = if ORActive then high else na;
def ORLow = if ORActive then low else na;

#
# Plot the OR high and low
#
plot ORAH = if GetLastDay() != GetDay() or !ORActive then na else HighestAll(ORHigh);
plot ORAL = if GetLastDay() != GetDay() or !ORActive then na else LowestAll(ORLow);
plot ORH = if GetLastDay() != GetDay() or SecondsFromTime(ORend) < 0 then na else HighestAll(ORHigh);
plot ORL = if GetLastDay() != GetDay() or SecondsFromTime(ORend) < 0 then na else LowestAll(ORLow);


plot o50h = ORH + 0.5*(ORH-ORL);
plot o50l = ORL - 0.5*(ORH-ORL);
plot o100h = ORH + 1*(ORH-ORL);
plot o100l = ORL - 1*(ORH-ORL);

#
# Formatting
#
ORAH.SetStyle(Curve.SHORT_DASH);
ORAL.SetStyle(Curve.SHORT_DASH);
ORAH.SetDefaultColor(Color.GRAY);
ORAL.SetDefaultColor(Color.GRAY);
ORH.SetStyle(Curve.SHORT_DASH);
ORL.SetStyle(Curve.SHORT_DASH);
ORH.SetDefaultColor(Color.GRAY);
ORL.SetDefaultColor(Color.GRAY);

AddCloud(ORAH, ORAL, Color.light_GRAY, Color.light_GRAY);
AddCloud(ORH, ORL, Color.light_GRAY, Color.light_GRAY);


o50h.SetStyle(Curve.SHORT_DASH);
o50l.SetStyle(Curve.SHORT_DASH);
o100h.SetStyle(Curve.SHORT_DASH);
o100l.SetStyle(Curve.SHORT_DASH);
o50h.SetDefaultColor(Color.GREEN);
o50l.SetDefaultColor(Color.GREEN);
o100h.SetDefaultColor(Color.RED);
o100l.SetDefaultColor(Color.RED);

Here you go! Green is 50% extension and Red is 100% extension of IB.
 
Code:
declare Hide_On_Daily;
declare Once_per_bar;

input OrMeanS  = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.
input OrMeanE  = 0935.0; #hint OrMeanE: End Mean period. Usually End of first bar.
input OrBegin  = 0930.0; #hint OrBegin: Beginning for Period of Opening Range Breakout.
input OrEnd    = 1000.0; #hint OrEnd: End of Period of Opening Range Breakout.
input CloudOn  = no;     #hint CloudOn: Clouds Opening Range.
input AlertOn  = yes;    #hint AlertOn: Alerts on cross of Opening Range.
input ShowTodayOnly = {"No", default "Yes"}; 
input nAtr = 4;          #hint nATR: Lenght for the ATR Risk and Target Lines.
input AtrTargetMult = 2.0; #hint ATRmult: Multiplier for the ATR calculations.

  def h = high;
  def l = low;
  def c = close;
  def bar = barNumber();
  def s = ShowTodayOnly;
  def ORActive = if secondsTillTime(OrMeanE) > 0 and
                    secondsFromTime(OrMeanS) >= 0
                 then 1
                 else 0;
  def today = if s == 0
              or getDay() == getLastDay() and
                 secondsFromTime(OrMeanS) >= 0
              then 1
              else 0;
  def ORHigh = if ORHigh[1] == 0
               or ORActive[1] == 0 and
                  ORActive == 1
               then h
               else if ORActive and
                       h > ORHigh[1]
               then h
               else ORHigh[1];
  def ORLow = if ORLow[1] == 0
              or ORActive[1] == 0 and
                 ORActive == 1
              then l
              else if ORActive and
                      l < ORLow[1]
              then l
              else ORLow[1];
  def ORWidth = ORHigh - ORLow;
  def na = double.nan;
  def ORHA = if ORActive
             or today < 1
             then na
             else ORHigh;
  def ORLA = if ORActive
             or today < 1
             then na
             else ORLow;
  def O = ORHA - Round(((ORHA - ORLA) / 2) / TickSize(), 0) * TickSize();
  def ORActive2 = if secondsTillTime(OREnd) > 0 and
                     secondsFromTime(ORBegin) >= 0
                  then 1
                  else 0;
  def ORHigh2 = if ORHigh2[1] == 0
                  or ORActive2[1] == 0 and
                     ORActive2 == 1
                then h
                else if ORActive2 and
                        h > ORHigh2[1]
                then h
                else ORHigh2[1];
  def ORLow2 = if ORLow2[1] == 0
                or ORActive2[1] == 0 and
                   ORActive2 == 1
               then l
               else if ORActive2 and
                       l < ORLow2[1]
               then l
               else ORLow2[1];
  def ORWidth2 = ORHigh2 - ORLow2;
  def TimeLine = if secondsTillTime(OREnd) == 0
                 then 1
                 else 0;
  def ORmeanBar = if !ORActive and ORActive[1]
                  then barNumber()
                  else ORmeanBar[1];
  def ORendBar = if !ORActive2 and ORActive2[1]
                 then barNumber()
                 else ORendBar[1];
  def ORL = if (o == 0 , na, o);
plot ORLext = if barNumber() >= highestAll(ORmeanBar)
              then HighestAll(if isNaN(c[-1])
                              then ORL[1]
                              else double.nan)
              else double.nan;
     ORLext.SetDefaultColor(color.Yellow);
     ORLext.SetStyle(curve.Long_DASH);
     ORLext.SetLineWeight(3);
     ORLext.HideTitle();
  def ORH2 = if ORActive2
             or today < 1
             then na
             else ORHigh2;
plot ORH2ext = if barNumber() >= highestAll(ORendBar)
               then HighestAll(if isNaN(c[-1])
                               then ORH2[1]
                               else double.nan)
               else double.nan;
     ORH2ext.SetDefaultColor(color.Green);
     ORH2ext.SetStyle(curve.Long_DASH);
     ORH2ext.SetLineWeight(3);
     ORH2ext.HideTitle();
  def ORL2 = if ORActive2
               or today < 1
             then na
             else ORLow2;
plot ORL2ext = if barNumber() >= highestAll(ORendBar)
               then HighestAll(if isNaN(c[-1])
                               then ORL2[1]
                               else double.nan)
               else double.nan;
     ORL2ext.SetDefaultColor(color.Red);
     ORL2ext.SetStyle(curve.Long_DASH);
     ORL2ext.SetLineWeight(3);
     ORL2ext.HideTitle();
  def RelDay = (ORL - ORL2) / (ORH2 - ORL2);
  def dColor = if RelDay > .5
               then 5
               else if RelDay < .5
                    then 6
               else 4;
  def pos = (ORH2 - ORL2)/10;
addCloud(if CloudOn == yes
         then orl
         else double.nan
       , orl2,createColor(244,83,66), createColor(244,83,66));
addCloud(if CloudOn == yes
         then orl
         else double.nan
       , orh2,createColor(66,244,131), createColor(66,244,131));

plot o50h = orh2 + 0.5 * (orwidth2);
plot o50l = orl2 - 0.5 * (orwidth2);
plot o100h = orh2 + 1 * (orwidth2);
plot o100l = orl2 - 1 * (orwidth2);


o50h.SetStyle(Curve.SHORT_DASH);
o50l.SetStyle(Curve.SHORT_DASH);
o100h.SetStyle(Curve.SHORT_DASH);
o100l.SetStyle(Curve.SHORT_DASH);
o50h.SetDefaultColor(Color.GREEN);
o50l.SetDefaultColor(Color.GREEN);
o100h.SetDefaultColor(Color.RED);
o100l.SetDefaultColor(Color.RED);

This code shows IB of all days and was adapted from the opening range breakout indicator posted in the forum.
 
heres another one


Code:
#Start Script
#Declarations
input Begin = 0930;
input End = 1030;
input extendleft = no;
input show_vwap = yes;
input Level_Midline = 0.0;
input Level_1 = 1.00;
input Level_2 = -1.00;
input Level_3 = 1.50;
input Level_4 = -1.50;
input Level_5 = 2.00;
input Level_6 = -2.00;
input Level_7 = 2.50;
input Level_8 = -2.50;
input Level_9 = 3.00;
input Level_10 = -3.00;

#VWAP Addition For Beta
def VMID = if show_vwap == yes then reference VWAP() else Double.NaN;

plot PVMID = if extendleft == yes then VMID else if extendleft == no and SecondsTillTime(Begin) > 0 then Double.NaN else VMID;
#End VWAP Addition

#Conditions
def active = if SecondsTillTime(End) > 0 and SecondsFromTime(Begin) >= 0 then yes else no;

def highest= if highest[1] == 0 or active[1] == 0 and active == 1 then high else if active and high > highest[1] then high else highest[1];
plot Phighest= if extendleft == yes then highest else if extendleft == no and SecondsTillTime(Begin) > 0 then Double.NaN else Highest;

def lowest= if lowest[1] == 0 or active[1] == 0 and active == 1 then low else if active and low < lowest[1] then low else lowest[1];
plot Plowest= if extendleft == yes then lowest else if extendleft == no and SecondsTillTime(Begin) > 0 then Double.NaN else lowest;

#Calculations
def midline =  ((highest - lowest) / 2) + lowest;

def f1 = ((highest - lowest) * Level_1) + midline;
def f2 = ((highest - lowest) * Level_2) + midline;
def f3 = ((highest - lowest) * Level_3) + midline;
def f4 = ((highest - lowest) * Level_4) + midline;
def f5 = ((highest - lowest) * Level_5) + midline;
def f6 = ((highest - lowest) * Level_6) + midline;
def f7 = ((highest - lowest) * Level_7) + midline;
def f8 = ((highest - lowest) * Level_8) + midline;
def f9 = ((highest - lowest) * Level_9) + midline;
def f10 = ((highest - lowest) * Level_10) + midline;

#Plotting
plot mid = if extendleft == yes then midline else if extendleft == no and SecondsTillTime(Begin) > 0 then Double.NaN else midline;
plot fib1 = if extendleft == yes then f1 else if extendleft == no and SecondsTillTime(Begin) > 0 then Double.NaN else f1;
plot fib2 = if extendleft == yes then f2 else if extendleft == no and SecondsTillTime(Begin) > 0 then Double.NaN else f2;
plot fib3 = if extendleft == yes then f3 else if extendleft == no and SecondsTillTime(Begin) > 0 then Double.NaN else f3;
plot fib4 = if extendleft == yes then f4 else if extendleft == no and SecondsTillTime(Begin) > 0 then Double.NaN else f4;

plot fib5 = if extendleft == yes then f5 else if extendleft == no and SecondsTillTime(Begin) > 0 then Double.NaN else f5;
plot fib6 = if extendleft == yes then f6 else if extendleft == no and SecondsTillTime(Begin) > 0 then Double.NaN else f6;
plot fib7 = if extendleft == yes then f7 else if extendleft == no and SecondsTillTime(Begin) > 0 then Double.NaN else f7;
plot fib8 = if extendleft == yes then f8 else if extendleft == no and SecondsTillTime(Begin) > 0 then Double.NaN else f8;
plot fib9 = if extendleft == yes then f9 else if extendleft == no and
SecondsTillTime(Begin) > 0 then Double.NaN else f9;
plot fib10 = if extendleft == yes then f10 else if extendleft == no and SecondsTillTime(Begin) > 0 then Double.NaN else f10;


#secondaryclouding
def sch= if active then highest else double.nan;
def scl= if active then lowest else double.nan;

#Styling
PVMID.SetDefaultColor(Color.ORANGE);

phighest.SetLineWeight(1);
phighest.SetDefaultColor(Color.GREEN);
plowest.SetLineWeight(1);
plowest.SetDefaultColor(Color.RED);

fib1.SetDefaultColor(Color.CYAN);
fib2.SetDefaultColor(Color.CYAN);
fib3.SetDefaultColor(Color.CYAN);
fib4.SetDefaultColor(Color.CYAN);
fib5.SetDefaultColor(Color.CYAN);
fib6.SetDefaultColor(Color.CYAN);
fib7.SetDefaultColor(Color.CYAN);
fib8.SetDefaultColor(Color.CYAN);
fib9.SetDefaultColor(Color.CYAN);
fib10.SetDefaultColor(Color.CYAN);

AddCloud(phighest, plowest, CreateColor(13, 24, 24));
AddCloud(sch, scl, createcolor(60,110,110));
#End Script
Code:
 
A friend just sent me this, he cleaned up an earlier part of the code

Code:
input OpenRangeStart = 0930;
input OpenRangeEnd = 1030;

def na = Double.NaN;
#
# Check if the opening range time is now
#

def ORActive = if GetLastDay() == GetDay() and SecondsFromTime(OpenRangeStart) >= 0 and SecondsFromTime(OpenRangeEnd) <
0 then 1 else 0;
#
# Track the OR high and low
#
def ORHigh = if ORActive then high else na;
def ORLow = if ORActive then low else na;
def plotting = if GetLastDay() == GetDay() and SecondsFromTime(OpenRangeStart) >= 0 then 1 else 0;
def range = HighestAll(ORHigh) - LowestAll(ORLow);

def ORHx100 = HighestAll(ORHigh) + range;
def ORHx50 = HighestAll(ORHigh) + (range * 0.5);

def ORLx100 = LowestAll(ORLow) - range;
def ORLx50 = LowestAll(ORLow) - (range * 0.5);

#
# Plot the OR high and low
#
plot ORAH = if plotting then HighestAll(ORHigh) else na;
ORAH.SetStyle(Curve.SHORT_DASH);
ORAH.SetDefaultColor(Color.GREEN);

plot ORAL = if plotting then LowestAll(ORLow) else na;
ORAL.SetStyle(Curve.SHORT_DASH);
ORAL.SetDefaultColor(Color.RED);

plot ORAHx100 = if plotting then ORHx100 else na;
ORAHx100.SetStyle(Curve.SHORT_DASH);
ORAHx100.SetDefaultColor(Color.GREEN);

plot ORALx100 = if plotting then ORLx100 else na;
ORALx100.SetStyle(Curve.SHORT_DASH);
ORALx100.SetDefaultColor(Color.RED);

plot ORAHx50 = if plotting then ORHx50 else na;
ORAHx50.SetStyle(Curve.SHORT_DASH);
ORAHx50.SetDefaultColor(Color.GREEN);

plot ORALx50 = if plotting then ORLx50 else na;
ORALx50.SetStyle(Curve.SHORT_DASH);
ORALx50.SetDefaultColor(Color.RED);
 
Hey everyone, can someone please help add the "show today only" to this code thanks!

Code:
input opentime = 0930;
input ORend = 1000;
input opacity = .7;
def na = Double.NaN;
#
# Check if the opening range time is now
#
def ORActive = if GetLastDay() == GetDay() and SecondsFromTime(opentime) >= 0 and SecondsFromTime(ORend) <
0 then 1 else 0;
#
# Track the OR high and low
#
def ORHigh = if ORActive then high else na;
def ORLow = if ORActive then low else na;
#
# Plot the OR high and low
#
plot ORAH = if GetLastDay() != GetDay() or !ORActive then na else HighestAll(ORHigh);
plot ORAL = if GetLastDay() != GetDay() or !ORActive then na else LowestAll(ORLow);
plot ORH = if GetLastDay() != GetDay() or SecondsFromTime(ORend) < 0 then na else HighestAll(ORHigh);
plot ORL = if GetLastDay() != GetDay() or SecondsFromTime(ORend) < 0 then na else LowestAll(ORLow);
#
# Formatting
#

ORAH.SetStyle(Curve.SHORT_DASH);
ORAL.SetStyle(Curve.SHORT_DASH);
ORAH.SetDefaultColor(Color.GREEN);
ORAL.SetDefaultColor(Color.RED);
ORH.SetStyle(Curve.SHORT_DASH);
ORL.SetStyle(Curve.SHORT_DASH);
ORH.SetDefaultColor(Color.GREEN);
ORL.SetDefaultColor(Color.RED);
#
# Add Cloud creates the shading
#

#
# Alerts:

#
def alerttrigger = if (high >= ORH and low <= ORH) or (high >= ORL and low <= ORL) then 1 else 0; #replace the 1 with


input alerttext = "OR Breakout!";
input UseAlerts = {false, default true};
input AlertType = {default "BAR", "ONCE", "TICK"};
def at = AlertType;
input AlertSound = {"Bell", "Chimes", default "Ding", "NoSound", "Ring"};
Alert(alerttrigger and UseAlerts, alerttext, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR,
AlertSound);
 
Last edited:
Below is an opening range script I'm using but having difficulty modifying it to do the following once the market time of 9:45 is active:
  • Show the start of the transparent cloud from 9:30 ~ 9:45 but not follow the market time beyond 9:45.
  • Show the start of the 0%, 50%, and 100% opening range horizontal lines from 9:30 and follow market time until market close
Code:
def na=double.nan;

input CloudOn  = yes;

# Define time that OR begins (in hhmm format,
# 0930 is the default):
input ORBegin = 0930;

# Define time that OR is finished (in hhmm format,
# 10:00 is the default):
input OREnd = 0945;

# Show Today only? (Default Yes)
input ShowTodayOnly={"No", default "Yes"};
def s=ShowTodayOnly;

# Create logic for OR definition:
Def ORActive = if secondstilltime(OREnd)>0 AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Create logic to paint only current day post-open:
def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Track OR High:
Rec ORHigh = if ORHigh[1]==0 or ORActive[1]==0 AND ORActive==1 then high else if ORActive AND high>ORHigh[1] then high else ORHigh[1];

# Track OR Low:
Rec ORLow = if ORLow[1]==0 or ORActive[1]==0 AND ORActive==1 then low else if ORActive AND low<ORLow[1] then low else ORLow[1];

# Define all the plots:
Plot ORH=if ORActive OR today<1 then na else ORHigh;
Plot ORL=if ORActive OR today<1 then na else ORLow;

# Formatting:
ORH.setdefaultcolor(color.green);
ORH.setStyle(curve.Short_DASH);
ORH.setlineweight(1);
ORL.setdefaultcolor(color.red);
ORL.setStyle(curve.Short_DASH);
ORL.setlineweight(1);

addCloud(if CloudOn == yes
         then orl
         else double.nan
       , ORH,createColor(41,98,255), createColor(41,98,255));

Below are the results I am trying to achieve but this is from Tradingview.
amvDrz0.png
 
Below is an opening range script I'm using but having difficulty modifying it to do the following once the market time of 9:45 is active:
  • Show the start of the transparent cloud from 9:30 ~ 9:45 but not follow the market time beyond 9:45.
  • Show the start of the 0%, 50%, and 100% opening range horizontal lines from 9:30 and follow market time until market close
Code:
def na=double.nan;

input CloudOn  = yes;

# Define time that OR begins (in hhmm format,
# 0930 is the default):
input ORBegin = 0930;

# Define time that OR is finished (in hhmm format,
# 10:00 is the default):
input OREnd = 0945;

# Show Today only? (Default Yes)
input ShowTodayOnly={"No", default "Yes"};
def s=ShowTodayOnly;

# Create logic for OR definition:
Def ORActive = if secondstilltime(OREnd)>0 AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Create logic to paint only current day post-open:
def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Track OR High:
Rec ORHigh = if ORHigh[1]==0 or ORActive[1]==0 AND ORActive==1 then high else if ORActive AND high>ORHigh[1] then high else ORHigh[1];

# Track OR Low:
Rec ORLow = if ORLow[1]==0 or ORActive[1]==0 AND ORActive==1 then low else if ORActive AND low<ORLow[1] then low else ORLow[1];

# Define all the plots:
Plot ORH=if ORActive OR today<1 then na else ORHigh;
Plot ORL=if ORActive OR today<1 then na else ORLow;

# Formatting:
ORH.setdefaultcolor(color.green);
ORH.setStyle(curve.Short_DASH);
ORH.setlineweight(1);
ORL.setdefaultcolor(color.red);
ORL.setStyle(curve.Short_DASH);
ORL.setlineweight(1);

addCloud(if CloudOn == yes
         then orl
         else double.nan
       , ORH,createColor(41,98,255), createColor(41,98,255));

Below are the results I am trying to achieve but this is from Tradingview.
amvDrz0.png

This uses an offset, [-(orend-orbegin)] to show the cloud during the opening range between orbegin and orend. A mid (50%) line was also added.

Screenshot-2022-10-23-162937.png
Ruby:
def na=double.nan;

input CloudOn  = yes;

# Define time that OR begins (in hhmm format,
# 0930 is the default):
input ORBegin = 0930;

# Define time that OR is finished (in hhmm format,
# 10:00 is the default):
input OREnd = 0945;

# Show Today only? (Default Yes)
input ShowTodayOnly={"No", default "Yes"};
def s=ShowTodayOnly;

# Create logic for OR definition:
Def ORActive = if secondstilltime(OREnd)>0 AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Create logic to paint only current day post-open:
def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Track OR High:
Rec ORHigh = if ORHigh[1]==0 or ORActive[1]==0 AND ORActive==1 then high else if ORActive AND high>ORHigh[1] then high else ORHigh[1];

# Track OR Low:
Rec ORLow = if ORLow[1]==0 or ORActive[1]==0 AND ORActive==1 then low else if ORActive AND low<ORLow[1] then low else ORLow[1];

# Define all the plots:
Plot ORH=if ORActive OR today<1 then na else ORHigh;
Plot ORL=if ORActive OR today<1 then na else ORLow;
Plot ORM=if ORActive OR today<1 then na else (ORHigh + ORLow) / 2;

# Formatting:
ORH.setdefaultcolor(color.green);
ORH.setStyle(curve.Short_DASH);
ORH.setlineweight(1);
ORL.setdefaultcolor(color.red);
ORL.setStyle(curve.Short_DASH);
ORL.setlineweight(1);

addCloud(if CloudOn == yes and secondsfromTime(orbegin)>=0 and secondsfromTime(orend)<=0
         then orl[-(orend-orbegin)]
         else double.nan
       , ORH[-(orend-orbegin)],createColor(41,98,255), createColor(41,98,255));
 
@SleepyZ thank you so much for modifying this. Is there a way to make this work for futures? I mainly trade /ES and when I load your modified code, the indicator does not appear. However it does appear when I disable extended hours.
 
@SleepyZ thank you so much for modifying this. Is there a way to make this work for futures? I mainly trade /ES and when I load your modified code, the indicator does not appear. However it does appear when I disable extended hours.

Sorry, just saw this question.

The above seems to work on /ES with or without extended hours enabled

Here are 2 charts without extended hours in the upper chart and with extended hours in the lower chart, both for /ES 1m charts

 
I have a quick ask, is there a chance to make this available in the 5 minute timeframe, it seems to work only on 1 minute
 
Some additional help, i modified this to draw two boxes, one from 9:30am to 10:30am from high to low and the other one on the same time from opening to closing price, and the lines to show the high, low, opening and closing of the 9:30 to 10:30 range, can someone help? im getting some weird results:


def na=double.nan;

input CloudOn = yes;

# Define time that OR begins (in hhmm format,
# 0930 is the default):
input ORBegin = 0930;

# Define time that OR is finished (in hhmm format,
# 10:00 is the default):
input OREnd = 1030;

# Show Today only? (Default Yes)
input ShowTodayOnly={"Yes", default "No"};
def s=ShowTodayOnly;

# Create logic for OR definition:
Def ORActive = if secondstilltime(OREnd)>0 AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Create logic to paint only current day post-open:
def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Track OR High:
Rec ORHigh = if ORHigh[1]==0 or ORActive[1]==0 AND ORActive==1 then high else if ORActive AND high>ORHigh[1] then high else ORHigh[1];

# Track OR Low:
Rec ORLow = if ORLow[1]==0 or ORActive[1]==0 AND ORActive==1 then low else if ORActive AND low<ORLow[1] then low else ORLow[1];

# Define all the plots:
Plot ORH=if ORActive OR today<1 then na else ORHigh;
Plot ORL=if ORActive OR today<1 then na else ORLow;

# Formatting:
ORH.setdefaultcolor(color.green);
ORH.setStyle(curve.Firm);
ORH.setlineweight(1);
ORL.setdefaultcolor(color.red);
ORL.setStyle(curve.Firm);
ORL.setlineweight(1);

addCloud(if CloudOn == yes and secondsfromTime(orbegin)>=0 and secondsfromTime(orend)<=0
then orl[-(orend-orbegin)]
else double.nan
, ORH[-(orend-orbegin)],createColor(41,98,255), createColor(41,98,255));

# Track OR Open:
Rec OROpen = if OROpen[1]==0 or ORActive[1]==0 AND ORActive==1 then open else if ORActive AND open>OROpen[1] then open else OROpen[1];

# Track OR Close:
Rec ORClose = if ORClose[1]==0 or ORActive[1]==0 AND ORActive==1 then close else if ORActive AND close<ORClose[1] then close else ORClose[1];

# Define all the plots:
Plot ORO=if ORActive OR today<1 then na else OROpen;
Plot ORC=if ORActive OR today<1 then na else ORClose;

# Formatting:
ORO.setdefaultcolor(color.green);
ORO.setStyle(curve.Short_DASH);
ORO.setlineweight(1);
ORC.setdefaultcolor(color.red);
ORC.setStyle(curve.Short_DASH);
ORC.setlineweight(1);

addCloud(if CloudOn == yes and secondsfromTime(orbegin)>=0 and secondsfromTime(orend)<=0
then orc[-(orend-orbegin)]
else double.nan
, ORO[-(orend-orbegin)],createColor(41,98,255), createColor(41,98,255));

This is what im looking for


 
Last edited:
I have a quick ask, is there a chance to make this available in the 5 minute timeframe, it seems to work only on 1 minute

I think this will fix that situation by adding a divisor to the offset of getaggregationperiod()/60000. See the code below.

Screenshot-2022-11-27-065344.png
Ruby:
def na=double.nan;

input CloudOn  = yes;

# Define time that OR begins (in hhmm format,
# 0930 is the default):
input ORBegin = 0930;

# Define time that OR is finished (in hhmm format,
# 10:00 is the default):
input OREnd = 0945;

# Show Today only? (Default Yes)
input ShowTodayOnly={"No", default "Yes"};
def s=ShowTodayOnly;

# Create logic for OR definition:
Def ORActive = if secondstilltime(OREnd)>0 AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Create logic to paint only current day post-open:
def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Track OR High:
Rec ORHigh = if ORHigh[1]==0 or ORActive[1]==0 AND ORActive==1 then high else if ORActive AND high>ORHigh[1] then high else ORHigh[1];

# Track OR Low:
Rec ORLow = if ORLow[1]==0 or ORActive[1]==0 AND ORActive==1 then low else if ORActive AND low<ORLow[1] then low else ORLow[1];

# Define all the plots:
Plot ORH=if ORActive OR today<1 then na else ORHigh;
Plot ORL=if ORActive OR today<1 then na else ORLow;
Plot ORM=if ORActive OR today<1 then na else (ORHigh + ORLow) / 2;

# Formatting:
ORH.setdefaultcolor(color.green);
ORH.setStyle(curve.Short_DASH);
ORH.setlineweight(1);
ORL.setdefaultcolor(color.red);
ORL.setStyle(curve.Short_DASH);
ORL.setlineweight(1);

addCloud(if CloudOn == yes and secondsfromTime(orbegin)>=0 and secondsfromTime(orend)<=0
         then orl[-(orend-orbegin)/(getaggregationPeriod()/60000)]
         else double.nan
       , ORH[-(orend-orbegin)/(getaggregationPeriod()/60000)],createColor(41,98,255), createColor(41,98,255));
 
Some additional help, i modified this to draw two boxes, one from 9:30am to 10:30am from high to low and the other one on the same time from opening to closing price, and the lines to show the high, low, opening and closing of the 9:30 to 10:30 range, can someone help? im getting some weird results:


def na=double.nan;

input CloudOn = yes;

# Define time that OR begins (in hhmm format,
# 0930 is the default):
input ORBegin = 0930;

# Define time that OR is finished (in hhmm format,
# 10:00 is the default):
input OREnd = 1030;

# Show Today only? (Default Yes)
input ShowTodayOnly={"Yes", default "No"};
def s=ShowTodayOnly;

# Create logic for OR definition:
Def ORActive = if secondstilltime(OREnd)>0 AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Create logic to paint only current day post-open:
def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Track OR High:
Rec ORHigh = if ORHigh[1]==0 or ORActive[1]==0 AND ORActive==1 then high else if ORActive AND high>ORHigh[1] then high else ORHigh[1];

# Track OR Low:
Rec ORLow = if ORLow[1]==0 or ORActive[1]==0 AND ORActive==1 then low else if ORActive AND low<ORLow[1] then low else ORLow[1];

# Define all the plots:
Plot ORH=if ORActive OR today<1 then na else ORHigh;
Plot ORL=if ORActive OR today<1 then na else ORLow;

# Formatting:
ORH.setdefaultcolor(color.green);
ORH.setStyle(curve.Firm);
ORH.setlineweight(1);
ORL.setdefaultcolor(color.red);
ORL.setStyle(curve.Firm);
ORL.setlineweight(1);

addCloud(if CloudOn == yes and secondsfromTime(orbegin)>=0 and secondsfromTime(orend)<=0
then orl[-(orend-orbegin)]
else double.nan
, ORH[-(orend-orbegin)],createColor(41,98,255), createColor(41,98,255));

# Track OR Open:
Rec OROpen = if OROpen[1]==0 or ORActive[1]==0 AND ORActive==1 then open else if ORActive AND open>OROpen[1] then open else OROpen[1];

# Track OR Close:
Rec ORClose = if ORClose[1]==0 or ORActive[1]==0 AND ORActive==1 then close else if ORActive AND close<ORClose[1] then close else ORClose[1];

# Define all the plots:
Plot ORO=if ORActive OR today<1 then na else OROpen;
Plot ORC=if ORActive OR today<1 then na else ORClose;

# Formatting:
ORO.setdefaultcolor(color.green);
ORO.setStyle(curve.Short_DASH);
ORO.setlineweight(1);
ORC.setdefaultcolor(color.red);
ORC.setStyle(curve.Short_DASH);
ORC.setlineweight(1);

addCloud(if CloudOn == yes and secondsfromTime(orbegin)>=0 and secondsfromTime(orend)<=0
then orc[-(orend-orbegin)]
else double.nan
, ORO[-(orend-orbegin)],createColor(41,98,255), createColor(41,98,255));

This is what im looking for



The same fix for the above post seems to work for your revision getting higher opens and lower closes than the opening bars open/close

Screenshot-2022-11-27-072417.png
Ruby:
def na=double.nan;

input CloudOn = yes;

# Define time that OR begins (in hhmm format,
# 0930 is the default):
input ORBegin = 0930;

# Define time that OR is finished (in hhmm format,
# 10:00 is the default):
input OREnd = 1030;

# Show Today only? (Default Yes)
input ShowTodayOnly={"Yes", default "No"};
def s=ShowTodayOnly;

# Create logic for OR definition:
Def ORActive = if secondstilltime(OREnd)>0 AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Create logic to paint only current day post-open:
def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Track OR High:
Rec ORHigh = if ORHigh[1]==0 or ORActive[1]==0 AND ORActive==1 then high else if ORActive AND high>ORHigh[1] then high else ORHigh[1];

# Track OR Low:
Rec ORLow = if ORLow[1]==0 or ORActive[1]==0 AND ORActive==1 then low else if ORActive AND low<ORLow[1] then low else ORLow[1];

# Define all the plots:
Plot ORH=if ORActive OR today<1 then na else ORHigh;
Plot ORL=if ORActive OR today<1 then na else ORLow;

# Formatting:
ORH.setdefaultcolor(color.green);
ORH.setStyle(curve.Firm);
ORH.setlineweight(1);
ORL.setdefaultcolor(color.red);
ORL.setStyle(curve.Firm);
ORL.setlineweight(1);

addCloud(if CloudOn == yes and secondsfromTime(orbegin)>=0 and secondsfromTime(orend)<=0
then orl[-(orend-orbegin)/(getaggregationPeriod()/60000)]
else double.nan
, ORH[-(orend-orbegin)/(getaggregationPeriod()/60000)],createColor(41,98,255), createColor(41,98,255));

# Track OR Open:
Rec OROpen = if OROpen[1]==0 or ORActive[1]==0 AND ORActive==1 then open else if ORActive AND open>OROpen[1] then open else OROpen[1];

# Track OR Close:
Rec ORClose = if ORClose[1]==0 or ORActive[1]==0 AND ORActive==1 then close else if ORActive AND close<ORClose[1] then close else ORClose[1];

# Define all the plots:
Plot ORO=if ORActive OR today<1 then na else OROpen;
Plot ORC=if ORActive OR today<1 then na else ORClose;

# Formatting:
ORO.setdefaultcolor(color.green);
ORO.setStyle(curve.Short_DASH);
ORO.setlineweight(1);
ORC.setdefaultcolor(color.red);
ORC.setStyle(curve.Short_DASH);
ORC.setlineweight(1);

addCloud(if CloudOn == yes and secondsfromTime(orbegin)>=0 and secondsfromTime(orend)<=0
then orc[-(orend-orbegin)/(getaggregationPeriod()/60000)]
else double.nan
, ORO[-(orend-orbegin)/(getaggregationPeriod()/60000)],createColor(41,98,255), createColor(41,98,255));
 
Seems i wrote my reply on another thread, sorry

Thanks SleepyZ, this is great! really appreciate it, if i may ask for a couple of things, i put the script to work today at open and when 9:30 hit the boxes did not plot, i don't know if they'll plot at the end of the day but if there is a way to make them appear when the clock hits the 9:30 it would be great, the other thing is if the lines could plot all the way to the end of the day, right now they plot little by little, as soon as every candle closes, a bit of line appears, ideally when 9:30 hits the lines would plot all the way to the end of the session, Thank you!

Quick edit - Seems the boxes start drawing later, i checked my chart and the box started drawing after 9:30, seems like it will finish drawing at the end of the 12:10 candle if that makes sense
 
Last edited:
Seems i wrote my reply on another thread, sorry

Thanks SleepyZ, this is great! really appreciate it, if i may ask for a couple of things, i put the script to work today at open and when 9:30 hit the boxes did not plot, i don't know if they'll plot at the end of the day but if there is a way to make them appear when the clock hits the 9:30 it would be great, the other thing is if the lines could plot all the way to the end of the day, right now they plot little by little, as soon as every candle closes, a bit of line appears, ideally when 9:30 hits the lines would plot all the way to the end of the session, Thank you!

Quick edit - Seems the boxes start drawing later, i checked my chart and the box started drawing after 9:30, seems like it will finish drawing at the end of the 12:10 candle if that makes sense

See if this helps. I started to reply where you originally postes, so this looks similar to the code there.

Screenshot-2022-11-28-100120.png
Ruby:
input start = 0930;
input end   = 1600;
def   na    =  Double.NaN;
plot hitoday = if SecondsFromTime(start) >= 0 and SecondsFromTime(end) <= 0 then high(period = AggregationPeriod.DAY) else na;
plot lotoday = if SecondsFromTime(start) >= 0 and SecondsFromTime(end) <= 0 then low(period = AggregationPeriod.DAY) else na;
AddCloud(hitoday, lotoday, Color.DARK_GREEN, Color.DARK_GREEN );
AddVerticalLine(SecondsFromTime(start) == 0, "Start 0930", Color.CYAN);
AddVerticalLine(SecondsFromTime(end) == 0, "End 1600", Color.CYAN);
 
The same fix for the above post seems to work for your revision getting higher opens and lower closes than the opening bars open/close
@SleepyZ You actually revised another high low for me today but I really like the way this one is setup. I even added the 50 line divider plot from the code up above to really see the picture, for some strange reason it doesn't plot during market hours not sure what would be the reasoning.

def na=double.nan;

input CloudOn = yes;

# Define time that OR begins (in hhmm format,
# 0930 is the default):
input ORBegin = 0930;

# Define time that OR is finished (in hhmm format,
# 10:00 is the default):
input OREnd = 1030;

# Show Today only? (Default Yes)
input ShowTodayOnly={"Yes", default "No"};
def s=ShowTodayOnly;

# Create logic for OR definition:
Def ORActive = if secondstilltime(OREnd)>0 AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Create logic to paint only current day post-open:
def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Track OR High:
Rec ORHigh = if ORHigh[1]==0 or ORActive[1]==0 AND ORActive==1 then high else if ORActive AND high>ORHigh[1] then high else ORHigh[1];

# Track OR Low:
Rec ORLow = if ORLow[1]==0 or ORActive[1]==0 AND ORActive==1 then low else if ORActive AND low<ORLow[1] then low else ORLow[1];

# Define all the plots:
Plot ORH=if ORActive OR today<1 then na else ORHigh;
Plot ORL=if ORActive OR today<1 then na else ORLow;

# Formatting:
ORH.setdefaultcolor(color.green);
ORH.setStyle(curve.Firm);
ORH.setlineweight(1);
ORL.setdefaultcolor(color.red);
ORL.setStyle(curve.Firm);
ORL.setlineweight(1);

addCloud(if CloudOn == yes and secondsfromTime(orbegin)>=0 and secondsfromTime(orend)<=0
then orl[-(orend-orbegin)/(getaggregationPeriod()/60000)]
else double.nan
, ORH[-(orend-orbegin)/(getaggregationPeriod()/60000)],createColor(41,98,255), createColor(41,98,255));

# Track OR Open:
Rec OROpen = if OROpen[1]==0 or ORActive[1]==0 AND ORActive==1 then open else if ORActive AND open>OROpen[1] then open else OROpen[1];

# Track OR Close:
Rec ORClose = if ORClose[1]==0 or ORActive[1]==0 AND ORActive==1 then close else if ORActive AND close<ORClose[1] then close else ORClose[1];

# Define all the plots:
Plot ORO=if ORActive OR today<1 then na else OROpen;
Plot ORC=if ORActive OR today<1 then na else ORClose;
Plot ORM=if ORActive OR today<1 then na else (ORHigh + ORLow) / 2;

# Formatting:
ORO.setdefaultcolor(color.green);
ORO.setStyle(curve.Short_DASH);
ORO.setlineweight(1);
ORC.setdefaultcolor(color.red);
ORC.setStyle(curve.Short_DASH);
ORC.setlineweight(1);

addCloud(if CloudOn == yes and secondsfromTime(orbegin)>=0 and secondsfromTime(orend)<=0
then orc[-(orend-orbegin)/(getaggregationPeriod()/60000)]
else double.nan
, ORO[-(orend-orbegin)/(getaggregationPeriod()/60000)],createColor(41,98,255), createColor(41,98,255));
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
433 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