How to plot a horizontal line at the mid point of the high and low of 1st 15 minute candle

Manfrom1968

New member
How to plot a horizontal line at the mid point of the high and low of 1st 15 minute candle of the day? What I've tried is not working and any help is appreciated. Thank you.

Code:
# Define the time frame for the first 15-minute candle
input marketOpenTime = 0930;
input firstCandleDuration = 15; ## 15 minutes

def is_first_candle = if SecondsFromTime(marketOpenTime) == 0 then 1 else 0;

def firstCandleHigh = high(period="DAY");
def firstCandleLow = low(period="DAY");
def firstCandleMidpoint = (firstCandleHigh + firstCandleLow) / 2;

def isFirstCandleClose = if is_first_candle and !is_first_candle[1] then close else Double.NaN;

# Plot the line on the chart
plot firstCandleCloseLine = if !IsNaN(isFirstCandleClose) then isFirstCandleClose else Double.NaN;
firstCandleCloseLine.SetDefaultColor(Color.GREEN);
firstCandleCloseLine.SetLineWeight(2);

# Plot the midpoint on the chart
plot firstCandleMidpointLine = if !IsNaN(isFirstCandleClose) then firstCandleMidpoint else Double.NaN;
firstCandleMidpointLine.SetDefaultColor(Color.BLUE);
firstCandleMidpointLine.SetLineWeight(2);
 
How to plot a horizontal line at the mid point of the high and low of 1st 15 minute candle of the day? What I've tried is not working and any help is appreciated. Thank you.

Code:
# Define the time frame for the first 15-minute candle
input marketOpenTime = 0930;
input firstCandleDuration = 15; ## 15 minutes

def is_first_candle = if SecondsFromTime(marketOpenTime) == 0 then 1 else 0;

def firstCandleHigh = high(period="DAY");
def firstCandleLow = low(period="DAY");
def firstCandleMidpoint = (firstCandleHigh + firstCandleLow) / 2;

def isFirstCandleClose = if is_first_candle and !is_first_candle[1] then close else Double.NaN;

# Plot the line on the chart
plot firstCandleCloseLine = if !IsNaN(isFirstCandleClose) then isFirstCandleClose else Double.NaN;
firstCandleCloseLine.SetDefaultColor(Color.GREEN);
firstCandleCloseLine.SetLineWeight(2);

# Plot the midpoint on the chart
plot firstCandleMidpointLine = if !IsNaN(isFirstCandleClose) then firstCandleMidpoint else Double.NaN;
firstCandleMidpointLine.SetDefaultColor(Color.BLUE);
firstCandleMidpointLine.SetLineWeight(2);

Replying from phone but try replacing the code defining the first 15m candle and the high and low of that with this:

Code:
def first15m_start = 0930;
def first15m_end = 0945;
def isfirst15m = secondsfromtime(first15m_start)>=0 and secondstilltime(first15m_end)<=0;
def first15m_low = if isfirst15m and low<=low[1] then low else if isfirst15m then first15m_low[1] else if secondsfromtime(first15m_start)>0 then first15m_low[1] else double.nan;
def first15m_high = if isfirst15m and high>=high[1] then high else if isfirst15m then first15m_high[1] else if secondsfromtime(first15m_start)>0 then first15m_high[1] else double.nan;

I think that will work if you update the code based on those replacements.
 

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

Replying from phone but try replacing the code defining the first 15m candle and the high and low of that with this:

Code:
def first15m_start = 0930;
def first15m_end = 0945;
def isfirst15m = secondsfromtime(first15m_start)>=0 and secondstilltime(first15m_end)<=0;
def first15m_low = if isfirst15m and low<=low[1] then low else if isfirst15m then first15m_low[1] else if secondsfromtime(first15m_start)>0 then first15m_low[1] else double.nan;
def first15m_high = if isfirst15m and high>=high[1] then high else if isfirst15m then first15m_high[1] else if secondsfromtime(first15m_start)>0 then first15m_high[1] else double.nan;

I think that will work if you update the code based on those replacements.
Thanks for the help Imk99.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
356 Online
Create Post

Similar threads

Similar threads

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