Swingtrade
New member
Dear all
I am trying to draw a line at the high and low of the 3-4PM EST price action. The challenge i am facing is the line is being drawn when extended hours is on, when i switch it off the line is now shown. How can i have the line with extended hours switched off. Below is my script
#========================================== #
#
HIGHEST & LOWEST LEVEL FROM 3-4 PM EST #
# - Draws solid yellow lines at 4 PM #
# - Compares High, 8SMA, 20SMA, 200SMA #
# - The lines remain visible PERMANENTLY #
# ========================================== #
#
Define Market Timings
def newDay = GetDay() != GetDay()[1];
def is4PM = SecondsFromTime(1600) == 0; # EXACTLY 4 PM
def isMarketHours = SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) > 0;
#
Track High & Low Between 3 PM - 4 PM
def rangeTime = SecondsFromTime(1500) >= 0 and SecondsTillTime(1600) >= 0;
rec high3to4PM = if newDay then Double.NaN
else if rangeTime[1] == 0 and rangeTime then high
else if rangeTime then Max(high, high3to4PM[1])
else high3to4PM[1];
rec low3to4PM = if newDay then Double.NaN
else if rangeTime[1] == 0 and rangeTime then low
else if rangeTime then Min(low, low3to4PM[1])
else low3to4PM[1];
#
Lock High & Low at 4 PM
rec lockedHigh4PM = if is4PM then high3to4PM else lockedHigh4PM[1];
rec lockedLow4PM = if is4PM then low3to4PM else lockedLow4PM[1];
#
Define SMAs (Only Update During Market Hours)
def sma8 = Average(close, 8);
def sma20 = Average(close, 20);
def sma200 = Average(close, 200);
#
Lock SMA Values at 4 PM
rec lockedSMA8_4PM = if is4PM then sma8 else lockedSMA8_4PM[1];
rec lockedSMA20_4PM = if is4PM then sma20 else lockedSMA20_4PM[1];
rec lockedSMA200_4PM = if is4PM then sma200 else lockedSMA200_4PM[1];
#
Determine the Highest Value at 4 PM
def highestAt4PM = Max(Max(lockedHigh4PM, lockedSMA8_4PM), Max(lockedSMA20_4PM, lockedSMA200_4PM));
#
Determine the Lowest Value at 4 PM
def lowestAt4PM = Min(Min(lockedLow4PM, lockedSMA8_4PM), Min(lockedSMA20_4PM, lockedSMA200_4PM));
#
Plot Solid Yellow Line at the Highest Value
plot HighestLevel4PM = highestAt4PM;
HighestLevel4PM.SetDefaultColor(Color.YELLOW);
HighestLevel4PM.SetStyle(Curve.FIRM);
HighestLevel4PM.SetLineWeight(2);
#
Plot Solid Yellow Line at the Lowest Value
plot LowestLevel4PM = lowestAt4PM;
LowestLevel4PM.SetDefaultColor(Color.YELLOW);
LowestLevel4PM.SetStyle(Curve.FIRM);
LowestLevel4PM.SetLineWeight(2);
#
Add Labels for Debugging
input showLabel = yes;
AddLabel(showLabel, "
3-4PM HIGH: " + lockedHigh4PM + " LOW: " + lockedLow4PM, Color.YELLOW);
AddLabel(showLabel, "
SMA 8 at 4PM: " + lockedSMA8_4PM, Color.BLUE);
AddLabel(showLabel, "
SMA 20 at 4PM: " + lockedSMA20_4PM, Color.RED);
AddLabel(showLabel, "
SMA 200 at 4PM: " + lockedSMA200_4PM, Color.ORANGE);
AddLabel(showLabel, "
HIGHEST VALUE @ 4PM: " + highestAt4PM, Color.YELLOW);
AddLabel(showLabel, "
LOWEST VALUE @ 4PM: " + lowestAt4PM, Color.YELLOW);
#
Add Chart Bubbles for Highest & Lowest Levels
#AddChartBubble(is4PM, highestAt4PM, "HIGHEST @ 4PM", Color.YELLOW, yes);
#AddChartBubble(is4PM, lowestAt4PM, "LOWEST @ 4PM", Color.YELLOW, no);
I am trying to draw a line at the high and low of the 3-4PM EST price action. The challenge i am facing is the line is being drawn when extended hours is on, when i switch it off the line is now shown. How can i have the line with extended hours switched off. Below is my script
#========================================== #
#

# - Draws solid yellow lines at 4 PM #
# - Compares High, 8SMA, 20SMA, 200SMA #
# - The lines remain visible PERMANENTLY #
# ========================================== #
#

def newDay = GetDay() != GetDay()[1];
def is4PM = SecondsFromTime(1600) == 0; # EXACTLY 4 PM
def isMarketHours = SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) > 0;
#

def rangeTime = SecondsFromTime(1500) >= 0 and SecondsTillTime(1600) >= 0;
rec high3to4PM = if newDay then Double.NaN
else if rangeTime[1] == 0 and rangeTime then high
else if rangeTime then Max(high, high3to4PM[1])
else high3to4PM[1];
rec low3to4PM = if newDay then Double.NaN
else if rangeTime[1] == 0 and rangeTime then low
else if rangeTime then Min(low, low3to4PM[1])
else low3to4PM[1];
#

rec lockedHigh4PM = if is4PM then high3to4PM else lockedHigh4PM[1];
rec lockedLow4PM = if is4PM then low3to4PM else lockedLow4PM[1];
#

def sma8 = Average(close, 8);
def sma20 = Average(close, 20);
def sma200 = Average(close, 200);
#

rec lockedSMA8_4PM = if is4PM then sma8 else lockedSMA8_4PM[1];
rec lockedSMA20_4PM = if is4PM then sma20 else lockedSMA20_4PM[1];
rec lockedSMA200_4PM = if is4PM then sma200 else lockedSMA200_4PM[1];
#

def highestAt4PM = Max(Max(lockedHigh4PM, lockedSMA8_4PM), Max(lockedSMA20_4PM, lockedSMA200_4PM));
#

def lowestAt4PM = Min(Min(lockedLow4PM, lockedSMA8_4PM), Min(lockedSMA20_4PM, lockedSMA200_4PM));
#

plot HighestLevel4PM = highestAt4PM;
HighestLevel4PM.SetDefaultColor(Color.YELLOW);
HighestLevel4PM.SetStyle(Curve.FIRM);
HighestLevel4PM.SetLineWeight(2);
#

plot LowestLevel4PM = lowestAt4PM;
LowestLevel4PM.SetDefaultColor(Color.YELLOW);
LowestLevel4PM.SetStyle(Curve.FIRM);
LowestLevel4PM.SetLineWeight(2);
#

input showLabel = yes;
AddLabel(showLabel, "

AddLabel(showLabel, "

AddLabel(showLabel, "

AddLabel(showLabel, "

AddLabel(showLabel, "

AddLabel(showLabel, "

#

#AddChartBubble(is4PM, highestAt4PM, "HIGHEST @ 4PM", Color.YELLOW, yes);
#AddChartBubble(is4PM, lowestAt4PM, "LOWEST @ 4PM", Color.YELLOW, no);