draw a high and low line based on 3-4PM price action

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);
 
HI

I am planning to have two lines , high and low line based on price action from 3-4PM. and the 8, 20 and 200 SMA on 2Min.

For high line, the high price validated with 8 and 20 and 200SMA which ever is high that is the high line, opp of that is low line. I want this line to be drawn at 4PM and be visible till next day 9:45AM

the problem i am seeing is when i have the extended price action switched off the lines dont show. I can only see line when extended is swithched on. Also on 1, 3 ,5 the lines are drawn from 4pm but on 2, 4, 6, 8 the lines is continuing across the time

this is my current script

# ========================================== #
# 📌 HIGHEST & LOWEST LEVEL FROM 3-4 PM EST #
# - Draws solid yellow lines at 4 PM #
# - Compares High, 8SMA, 20SMA, 200SMA #
# - Resets Lines at 9:45 AM Across ALL TFs #
# ========================================== #

# ✅ Define Market Timings
def newDay = GetDay() != GetDay()[1];
def is4PM = SecondsFromTime(1600) == 0; # EXACTLY 4 PM
def isResetTime = SecondsFromTime(0945) == 0; # EXACTLY 9:45 AM NEXT DAY
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 isResetTime then Double.NaN # Reset at 9:45 AM across all timeframes
else 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 isResetTime then Double.NaN # Reset at 9:45 AM across all timeframes
else 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 isResetTime then Double.NaN # Ensures reset at 9:45 AM
else if is4PM then high3to4PM
else lockedHigh4PM[1];

rec lockedLow4PM = if isResetTime then Double.NaN # Ensures reset at 9:45 AM
else 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 isResetTime then Double.NaN # Reset at 9:45 AM
else if is4PM then sma8
else lockedSMA8_4PM[1];

rec lockedSMA20_4PM = if isResetTime then Double.NaN # Reset at 9:45 AM
else if is4PM then sma20
else lockedSMA20_4PM[1];

rec lockedSMA200_4PM = if isResetTime then Double.NaN # Reset at 9:45 AM
else if is4PM then sma200
else lockedSMA200_4PM[1];

# ✅ Determine the Highest Value at 4 PM
def highestAt4PM = if isResetTime then Double.NaN # Ensures reset at 9:45 AM across all timeframes
else Max(Max(lockedHigh4PM, lockedSMA8_4PM), Max(lockedSMA20_4PM, lockedSMA200_4PM));

# ✅ Determine the Lowest Value at 4 PM
def lowestAt4PM = if isResetTime then Double.NaN # Ensures reset at 9:45 AM across all timeframes
else Min(Min(lockedLow4PM, lockedSMA8_4PM), Min(lockedSMA20_4PM, lockedSMA200_4PM));

# ✅ Ensure lines RESET AT 9:45 AM ON ALL TIMEFRAMES
def showLine = !isResetTime; # This removes the lines after 9:45 AM

# ✅ Plot Solid Yellow Line at the Highest Value (Resets at 9:45 AM)
plot HighestLevel4PM = if showLine then highestAt4PM else Double.NaN;
HighestLevel4PM.SetDefaultColor(Color.YELLOW);
HighestLevel4PM.SetStyle(Curve.FIRM);
HighestLevel4PM.SetLineWeight(2);

# ✅ Plot Solid Yellow Line at the Lowest Value (Resets at 9:45 AM)
plot LowestLevel4PM = if showLine then lowestAt4PM else Double.NaN;
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);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
603 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • 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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top