I'm trying to create a script that will plot the midpoint in real-time as the opening range develops. Here is what I have so far. For some reason it is creating the midpoint line above the current opening range high which is obviously incorrect. Any ideas as to what is wrong in this script?
Code:
# Real-time midpoint of 9:00am–9:15am price range
input startHour = 9;
input startMinute = 0;
input endHour = 9;
input endMinute = 15;
def startTime = startHour * 60 + startMinute;
def endTime = endHour * 60 + endMinute;
def currentMinutes = SecondsFromTime(0) / 60;
def inRange = currentMinutes >= startTime and currentMinutes <= endTime;
def reset = SecondsTillTime(0) == 0; # resets at midnight
def highSoFar = CompoundValue(1,
if reset then high
else if inRange then Max(high, highSoFar[1])
else highSoFar[1],
high);
def lowSoFar = CompoundValue(1,
if reset then low
else if inRange then Min(low, lowSoFar[1])
else lowSoFar[1],
low);
def midpoint = (highSoFar + lowSoFar) / 2;
plot MidpointLine = if inRange or currentMinutes > endTime then midpoint else Double.NaN;
MidpointLine.SetDefaultColor(Color.WHITE);
MidpointLine.SetLineWeight(2);
Last edited by a moderator: