candle value at x hour

shakib3585

Active member
VIP
Hello All,

Identify the High, Low, and Close values of a one-hour candle formed between 16:00 and 17:00 (EST)

I am looking for a ThinkScript code that can identify the high, low, and close values of a one-hour candle formed between 16:00 and 17:00 (EST) and plot them as horizontal lines. I also intend to utilize this script for scanning purposes with a one-hour aggregation period, enabling it to scan stocks where the closing price has crossed below the low of the 16:00–17:00 candle. Please help.

Thank you very much

Bumping up the post again for attention
 
Last edited by a moderator:
Hello @SleepyZ, apologies for bothering you again..I once made a relative volume study based on my needs which I have attached below. Will it be possible to include the same label color for the relative volume in your study as mine?

Thank you very much
Code:
declare lower;
declare zerobase;

input length = 60;
input numDev = 2.0;
input label = yes;
input allowNegativeValues = no;
def vol = volume;
def rawRelVol = (vol - Average(vol, length)) / StDev(vol, length);
plot RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);
plot StDevLevel = numDev;


RelVol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RelVol.SetLineWeight(3);
Relvol.AssignValueColor(if RelVol>=numdev and close>close[1] then color.green else if RelVol<numdev and close>close[1] then color.dark_green else if RelVol>=numdev and close<close[1] then color.red else color.dark_red);
StDevLevel.SetDefaultColor(GetColor(7));
StDevLevel.SetStyle(Curve.SHORT_DASH);

AddLabel(label,"RVol: "+RelVol,if RelVol>=numdev and close>close[1] then color.green else if RelVol<numdev and close>close[1] then color.dark_green else if RelVol>=numdev and close<close[1] then color.red else color.dark_red);
 
Hello @SleepyZ, apologies for bothering you again..I once made a relative volume study based on my needs which I have attached below. Will it be possible to include the same label color for the relative volume in your study as mine?

Thank you very much
Code:
declare lower;
declare zerobase;

input length = 60;
input numDev = 2.0;
input label = yes;
input allowNegativeValues = no;
def vol = volume;
def rawRelVol = (vol - Average(vol, length)) / StDev(vol, length);
plot RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);
plot StDevLevel = numDev;


RelVol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RelVol.SetLineWeight(3);
Relvol.AssignValueColor(if RelVol>=numdev and close>close[1] then color.green else if RelVol<numdev and close>close[1] then color.dark_green else if RelVol>=numdev and close<close[1] then color.red else color.dark_red);
StDevLevel.SetDefaultColor(GetColor(7));
StDevLevel.SetStyle(Curve.SHORT_DASH);

AddLabel(label,"RVol: "+RelVol,if RelVol>=numdev and close>close[1] then color.green else if RelVol<numdev and close>close[1] then color.dark_green else if RelVol>=numdev and close<close[1] then color.red else color.dark_red);

The label now uses your coloring scheme

Code:
#HLC_Lookback_Periods_Time_or_Date

input mode     = {default Period, Date};
input lookback = 1;
input dateback = 20240401;
input time     = 1700;
input agg      = AggregationPeriod.HOUR;

def cond   = SecondsFromTime(time)[1] < 0 and SecondsFromTime(time) >= 0 or SecondsFromTime(time) == 0;

def ymd    = GetYYYYMMDD();
def count  = if !IsNaN(close) and ymd != ymd[1] then count[1] + 1 else count[1];
def cond1  = HighestAll(count) - count ;

def H = if
        if mode == mode.Date
        then GetYYYYMMDD() == dateback and cond
        else cond1 == lookback and cond
        then high(period = agg)
        else H[1];
def L = if
        if mode == mode.Date
        then GetYYYYMMDD() == dateback and cond
        else cond1 == lookback and cond
        then low(period = agg)
        else L[1];
def C = if
        if mode == mode.Date
        then GetYYYYMMDD() == dateback and cond
        else cond1 == lookback and cond
        then close(period = agg)
        else C[1];

plot Hi = H;
plot Lo = L;
plot Cl = C;

Hi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Cl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

input troubleshoot = no;
AddChartBubble(troubleshoot, low, cond + "\n" + cond1 + "\n" + GetDay() + "\n" + cond + "\n" + Hi, Color.GRAY, no);

########### RelativeVolume @Stdev Level Label

input showlabel = yes;
input length = 60;
input numDev = 2.0;
input allowNegativeValues = no;

def rawRelVol = (volume(period = agg) - Average(volume(period = agg), length)) / StDev(volume(period = agg), length);
plot RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);
plot StDevLevel = numDev;

def r = if
        if mode == mode.Date
        then GetYYYYMMDD() == dateback and cond
        else cond1 == lookback and cond
        then RelVol
        else r[1];

def xdate = if mode == mode.Date then dateback else if mode == mode.Period and cond1 then GetYYYYMMDD() else xdate[1];
AddLabel(showlabel, AsPrice(xdate) + " @" + AsPrice(time) + "  RVOL: " + r,
if RelVol >= numDev and close(period = agg) > close(period = agg)[1] then Color.GREEN else if RelVol < numDev and close(period = agg) > close(period = agg)[1] then Color.DARK_GREEN else if RelVol >= numDev and close(period = agg) < close(period = agg)[1] then Color.RED else Color.DARK_RED);
 
The label now uses your coloring scheme
I have attached an image for the ticker INVO for the previous day at 1657 EST. The aggregation is 3 minute. The color comparison between mine and yours are not matching
 

Attachments

  • image.png
    image.png
    370.3 KB · Views: 28
I have attached an image for the ticker INVO for the previous day at 1657 EST. The aggregation is 3 minute. The color comparison between mine and yours are not matching

Did you change the agg period in my script to match the agg of your chart. Mine was set to 1hr.
I could not check your example as it is not available in Ondemand. However, I did test mine and it seems to work in sync with yours at 3m on INVO
 
Did you change the agg period in my script to match the agg of your chart. Mine was set to 1hr.
I could not check your example as it is not available in Ondemand. However, I did test mine and it seems to work in sync with yours at 3m on INVO
yes, I am sending you again with highlighted parts focusing my use of aggregation period based off your script
1713390509351.png
 
Thank you to the extreme, @SleepyZ !
Hello @SleepyZ . I hope you are doing great ! I have a request with this code. Instead of going back to previous days and fetching the high, low and close, can you please modify the code so it does the same thing except now it will do for the previous candles for the same day. For example, if I choose a given day, I would like to plot the high, low and close of any previous candle for that same given day only, based on a lookback input. The aggregation should be based on choice starting from 1 minute till 4 hours.

Thank you very much
 
Hello @SleepyZ . I hope you are doing great ! I have a request with this code. Instead of going back to previous days and fetching the high, low and close, can you please modify the code so it does the same thing except now it will do for the previous candles for the same day. For example, if I choose a given day, I would like to plot the high, low and close of any previous candle for that same given day only, based on a lookback input. The aggregation should be based on choice starting from 1 minute till 4 hours.

Thank you very much
If you set the date, then change the time and agg, it seems to already do what you requested
 

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
387 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