Daily range including pre-market hours

Daily range including pre-market hours.

Hi Robert

I have a code on ToS that is able to show daily range,what i did is to split this range to 1/2 and 1/4 in this way I have 100% 75% 50% 25% of the daily range.So far so good smiling smiley,my problem is I that I want to be able to measure this range from pre market lets say from 8am to 4pm.In this chart [prnt.sc] u will see what I mean,daily range is measured just on regular mkt hours not from premkt

This is the code I’m using now:

plot yesterdayHigh = High(period = AggregationPeriod.DAY)[1]; 

plot yesterdayLow= Low(period = AggregationPeriod.DAY)[1]; 

plot hod = High(period = AggregationPeriod.DAY); 

plot lod = Low(period = AggregationPeriod.DAY); 

def range = hod - lod; 

plot hod764 = (range * 0.75) + lod; 

plot lod236 = (range * 0.25) + lod; 

plot mid50 = (range * 0.5) + lod; 

I would appreciate any hint
Thanks in advance

Copy and paste the code below. Note that “Show extended hours” must be checked under the chart settings panel in order for this to work properly.

# +--------------------------------------------------+
# | Example: Daily range including pre-market hours. |
# |                   robert payne                   |
# |              funwiththinkscript.com              |
# +--------------------------------------------------+

input TimeToStart = 0800;
input TimeToStop = 1600;

def nMinutes = GetAggregationPeriod() / 60000;
def startTime = SecondsFromTime(TimeToStart) >= 0 and SecondsFromTime(TimeToStart) < nMinutes * 60;
def endTime = SecondsFromTime(TimeToStop) >= 0;

# set the initial high / low as the high / low at the start time
# if it is past the end time, then just remember what the previous values were
# if a new high or low is reached, remember that new value
# otherwise, just keep the old value ( H[1] or L[1] )

def H = if startTime then high else if endtime then h[1] else if high > H[1] then high else H[1];
def L = if startTime then low else if low < L[1] then low else L[1];

# calculate the range
def range = H - L;

# display the range in a label
AddLabel(yes, "Range: " + range, Color.YELLOW);

Leave a comment