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:
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: