# I need the HOD from Opening not premarket

##### New member
I have this study that calculates the Percentage from Previous close-Open, Open to LAst, Open to HOD, Pullback from HOD,
but it always takes the High of PRemarket if I have premarket data open..... Im getting frustrated.... I hope someone can help

my code is:
Code:
``````#Created by Arlette Rosario
#Display percentage change from yesterday and from open

#- Certain time from 9:30-16:00
def alertPeriodStart = 0930;
def alertPeriodEnd = 1600;
def startCounter = SecondsFromTime(alertPeriodStart);
def endCounter = SecondsTillTime(alertPeriodEnd);
def alertPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;

#-------------------------------------------------------

input length=10;
input period= aggregationPeriod.DAY;
input displaylabel=yes;

#-------------------------------------------------------------------------
#This calculaes Percentage change From High to current until Close of the Day
#In other words Percentage Retracement or pullback
#input percentGain = 20.0;

#plot priorDayClose = close(period = AggregationPeriod.DAY)[1]
def percentRetrace = 10.0;
plot priorDayClose = close(period = AggregationPeriod.DAY)[1];
priorDayClose.SetDefaultColor(Color.GRAY);
priorDayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
def newDay = GetDay() <> GetDay()[1];
rec trackHighOfDay = if newDay then open(period = period)[0] else if high[0] > trackHighOfDay[1] then high else trackHighOfDay[1];
plot highOfDay = trackHighOfDay[0];
highOfDay.SetDefaultColor(Color.CYAN);
highOfDay.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
def gain = 100 * (high / priorDayClose - 1);
def retrace = 100*((close(period=period)[0]-HighOfDay)/HighOfDay);

rec hasRetraced = if newDay then 0 else if retrace < -percentRetrace then 1 else hasRetraced[1];
def signal = hasRetraced and !hasRetraced[1] and alertPeriod; #AddChartBubble(signal, low, Concat(retrace, "% Pullback"), Color.RED, no);

#This Calculated percentage retracement from High to current pullback including after market
#AddLabel(alertPeriod , "% PullBack from High :" + Round(percentRetrace, 2)+ " %",color.LiGHT_ORANGE);

#----------------------------------------------------
#percentage change from Close to Open
def changeclose= ((open(period = period)[0]- close(period = period)[1])/close(period = period)[1])*100;

#percentage change from Open to current
def changeOpen= ((close(period = period)[0]- open(period = period)[0])/open(period = period)[0])*100;

#def changeFromHigh to current pullback
def retrace2=100*((close(period=period)[0]-HighOfDay[0])/HighOfDay[0]);

#def Changeclose From Open to HOD
def OpenHOD=((HighOfDay- open(period = period)[0])/open(period = period)[0])*100;

#current volume today
def dayvolume = volume(period = period)[0];
def dayavgvolume= average(volume(period= period)[1],length);

#------------ Displays----------
#Display Changeclose percentage from Prev Day close until current (premarket)
addlabel(displaylabel ,"PRevClose-Open:" + round(changeclose,2) + "%",if
changeclose<0 then color.RED else color.GREEN);

#Display Percentage change from Open to current or close
addlabel(displaylabel ,"Open-Last :" + round(changeopen,2) + "%",if
changeopen<0 then color.RED else color.GREEN);

#Dispplay percentage changeclose from Open to HOD
addlabel(displaylabel ,"Open-HOD :" + round(OpenHOD,2) + "%", color.CYAN);

#Dispplay percentage changeclose from Open to HOD
AddLabel(displaylabel , "PullBack from HOD:" + Round(retrace2, 2)+ " %",color.LiGHT_ORANGE);

#Display Average Volume from a period of time default is 10(Days) you can change it
addlabel(displaylabel ,"Avg Vol"+length + "Days: " + round(dayavgvolume,0), color.yellow);``````

Last edited by a moderator:
@adarty73 I have this study that calculates the Percentage from Previous close-Open, Open to LAst, Open to HOD, Pullback from HOD,but it always takes the High of PRemarket if I have premarket data open..... Im getting frustrated.... I hope someone can help

This hopefully will help you as a new member to see where the calculations come from and are what you want. I have reorganized the script to help you accomplish this.

There is a debug input that will show where some of the data originates. You can hide the debug labels by selecting NO at the input.

Also, an input to choose DAY (which includes non regular trading hours) and RTH (regular trading hours 0930 - 1600). This will allow you to see the computations in the labels done by your selection (... and to determine if the are accurate).

Ruby:
``````#Created by Arlette Rosario
#Display percentage change from yesterday and from open

input volumelength   = 10;
input period         = AggregationPeriod.DAY;
input displaylabel   = yes;
input percentRetrace = 10.0;
input debug          = yes;
#-------------------------------------------------------------------------

#- Certain time from 9:30-16:00
def alertPeriodStart = 0930;
def alertPeriodEnd   = 1600;
def startCounter     = SecondsFromTime(alertPeriodStart);
def endCounter       = SecondsTillTime(alertPeriodEnd);
def alertPeriod      = if startCounter >= 0 and endCounter >= 0 then 1 else 0;

def openofRTH        = if startcounter == 0 then open else openofRTH[1];
def HighOfRTH        = if startcounter == 0 then high else if endcounter>= 0 then max(high, HighOfRTH[1]) else HighOfRTH[1];
addlabel(debug, "OpenRTH: " + openofRTH + " HighofRTH: " + HighofRTH, color.white);
#-------------------------------------------------------

#- Certain time non-RTH
def priorDayClose    = close(period = AggregationPeriod.DAY)[1];

def newDay           = GetDay() <> GetDay()[1];
def openofDay          = if newDay then open else openofday[1];
def trackHighOfDay   = if newDay then high else if high[0] > trackHighOfDay[1] then high else trackHighOfDay[1];
def highOfDay        = trackHighOfDay[0];

def gain             = 100 * (high / priorDayClose - 1);
def retrace          = 100 * ((close - highOfDay) / highOfDay);
def hasRetraced      = if newDay then 0 else if retrace < -percentRetrace then 1 else hasRetraced[1];
def signal           = hasRetraced and !hasRetraced[1] and alertPeriod;

addlabel(debug, "PriorClose: " +priordayClose + " OpenDay: " + openofDay + " HighofDay: " + " " + highofday, color.white);
#-------------------------------------------------------

input method = {default RTH, DAY};
def changeclose;
def changeopen;
def retrace2;
def openHOD;

switch (method) {
#----------------------------------------------------
case DAY:
changeclose = ((openofDay - priordayclose) / priordayClose) * 100;
changeopen = ((close - openofDay) / openofday) * 100;
retrace2 = 100 * ((close - highOfDay) / highOfDay);
openHOD = ((HighOfRTH - openofday) / openofday) * 100;
#----------------------------------------------------

case RTH:
changeclose = ((openofRTH - priordayClose) / priordayClose) * 100;
changeopen = ((close - openofRTH) / openofRTH) * 100;
retrace2 = 100 * ((close - HighOfRTH) / HighOfRTH);
openHOD = ((HighOfRTH - openofRTH) / openofRTH) * 100;
}
#End Switch---------------------------------------------

#current volume today
def dayvolume = volume(period = period)[0];
def dayavgvolume = Average(volume(period = period)[1], volumelength);

#------------ Displays----------
#Display Changeclose percentage from Prev Day close until current (premarket)
AddLabel(displaylabel , "PRevClose-Open:" + Round(changeclose, 2) + "%", if
changeclose < 0 then Color.RED else Color.GREEN);

#Display Percentage change from Open to current or close
AddLabel(displaylabel , "Open-Last :" + Round(changeopen, 2) + "%", if
changeopen < 0 then Color.RED else Color.GREEN);

#Dispplay percentage changeclose from Open to HOD
AddLabel(displaylabel , "Open-HOD :" + Round(openHOD, 2) + "%", Color.CYAN);

#Dispplay percentage changeclose from Open to HOD
AddLabel(displaylabel , "PullBack from HOD:" + Round(retrace2, 2) + " %", Color.LIGHT_ORANGE);

#Display Average Volume from a period of time default is 10(Days) you can change it
AddLabel(displaylabel , "Avg Vol" + volumelength + "Days: " + Round(dayavgvolume, 0), Color.YELLOW);

#This Calculated percentage retracement from High to current pullback including after market
#AddChartBubble(signal, low, Concat(retrace, "% Pullback"), Color.RED, no);
#AddLabel(alertPeriod , "% PullBack from High :" + Round(percentRetrace, 2)+ " %",color.LiGHT_ORANGE);``````

### Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
303 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• 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?