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

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

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: 87
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
 
Hello,

I am attempting to plot a cloud between the high and low of any given candle at any given period. I have modified the code, which @SleepyZ originally developed, to add cloud. I have attached the code below. I want the cloud to start from high and low and extend right. The issue with my modified code is that it does not start from the high and low points of a candle but references from something. I have attached the image with red arrows indicating the unknown references at which the cloud is extending. Can anyone please help me with this code such that it starts from high and low only from a desired candle.

Thank you very much

1720339779355.png

Code:
input mode     = {default Period, Date};
input lookback = 1;
@Date
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 a1 = if mode == mode.Date and GetYYYYMMDD() < dateback then Double.NaN else H;
plot a2 = if mode == mode.Date and GetYYYYMMDD() < dateback then Double.NaN else L;

a1.SetDefaultColor(CreateColor(204, 51, 255));
a1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

a2.SetDefaultColor(CreateColor(255, 126, 156));
a2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);



AddLabel(yes, Concat("TPH: ", a1), CreateColor(204, 51, 255));
AddLabel(yes, Concat("TPL: ", a2), CreateColor(255, 126, 156));


def xdate = if mode == mode.Date then dateback else if mode == mode.Period and cond1 then GetYYYYMMDD() else xdate[1];
AddCloud(a1,a2, color.GRay,color.gray);
AddLabel(yes, AsPrice(xdate) + " @" + AsPrice(time) + "  H: " + a1 + "  L: " + a2, color.lime);
 
Last edited by a moderator:
Hello,

I am attempting to plot a cloud between the high and low of any given candle at any given period. I have modified the code, which @SleepyZ originally developed, to add cloud. I have attached the code below. I want the cloud to start from high and low and extend right. The issue with my modified code is that it does not start from the high and low points of a candle but references from something. I have attached the image with red arrows indicating the unknown references at which the cloud is extending. Can anyone please help me with this code such that it starts from high and low only from a desired candle.

Thank you very much

View attachment 22315
Code:
input mode     = {default Period, Date};
input lookback = 1;
@Date
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 a1 = H;
plot a2 = L;

a1.SetDefaultColor(CreateColor(204, 51, 255));
a1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

a2.SetDefaultColor(CreateColor(255, 126, 156));
a2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);



AddLabel(yes, Concat("TPH: ", a1), CreateColor(204, 51, 255));
AddLabel(yes, Concat("TPL: ", a2), CreateColor(255, 126, 156));


def xdate = if mode == mode.Date then dateback else if mode == mode.Period and cond1 then GetYYYYMMDD() else xdate[1];
AddCloud(a1,a2, color.GRay,color.gray);
AddLabel(yes, AsPrice(xdate) + " @" + AsPrice(time) + "  H: " + a1 + "  L: " + a2, color.lime);

Changing this part of the code should get rid of those lines.

Screenshot 2024-07-07 111106.png
Code:
plot a1 = if mode == mode.Date and GetYYYYMMDD() < dateback then Double.NaN else H;
plot a2 = if mode == mode.Date and GetYYYYMMDD() < dateback then Double.NaN else L;
 
One request, please, @SleepyZ . Could you please add bubbles to the lines?

Bubbles added

Screenshot 2024-07-08 082418.png
Code:
input mode     = {default Period, Date};
input lookback = 1;
@Date
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 a1 = if mode == mode.Date and GetYYYYMMDD() < dateback then Double.NaN else H;
plot a2 = if mode == mode.Date and GetYYYYMMDD() < dateback then Double.NaN else L;

a1.SetDefaultColor(CreateColor(204, 51, 255));
a1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

a2.SetDefaultColor(CreateColor(255, 126, 156));
a2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);



AddLabel(yes, Concat("TPH: ", a1), CreateColor(204, 51, 255));
AddLabel(yes, Concat("TPL: ", a2), CreateColor(255, 126, 156));


def xdate = if mode == mode.Date then dateback else if mode == mode.Period and cond1 then GetYYYYMMDD() else xdate[1];
AddCloud(a1,a2, color.GRay,color.gray);
AddLabel(yes, AsPrice(xdate) + " @" + AsPrice(time) + "  H: " + a1 + "  L: " + a2, color.lime);

input showbubbles = yes;
input bubblemover = 2;
def b=bubblemover;
def mover = isnan(close[b]) and !isnan(close[b+1]) and showbubbles;
addchartBubble(mover, a1, Concat("TPH: ", a1), CreateColor(204, 51, 255));
addchartBubble(mover, a2, Concat("TPL: ", a2), CreateColor(255, 126, 156), no);

#
 
Bubbles added
Hi @SleepyZ , I am trying to add a bubble "EBM" which equals TPH minus TPL. I wish to add the bubble next to the "TPH" bubble, but I cannot. I have tried to do so with the following code. Can you please help to fix it? Thank you so much
Code:
input mode     = {default Date, Period};
input lookback = 1;
@Date
input dateback = 20240401;
input time     = 930;
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 a1 = if mode == mode.Date and GetYYYYMMDD() < dateback then Double.NaN else H;
plot a2 = if mode == mode.Date and GetYYYYMMDD() < dateback then Double.NaN else L;
def EBM = a1-a2;

a1.SetDefaultColor(CreateColor(255, 51, 51));
a1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

a2.SetDefaultColor(CreateColor(51, 255, 51));
a2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);



AddLabel(yes, Concat("TPH: ", a1), CreateColor(255, 51, 51));
AddLabel(yes, Concat("TPL: ", a2), CreateColor(51, 255, 51));
AddLabel(yes, Concat("EBM: ", EBM), CreateColor(255, 153, 102));

def xdate = if mode == mode.Date then dateback else if mode == mode.Period and cond1 then GetYYYYMMDD() else xdate[1];
AddCloud(a1,a2, color.GRay,color.gray);
AddLabel(yes, AsPrice(xdate) + " @" + AsPrice(time) + "  H: " + a1 + "  L: " + a2, color.lime);

input showbubbles = yes;
input bubblemover = 2;
input distance_from_TPH_for_EBM = -2;
def b=bubblemover;
def b1= distance_from_TPH_for_EBM;
def mover = isnan(close[b]) and !isnan(close[b+1]) and showbubbles;
def mover1 = isnan(close[b1]) and !isnan(close[b1+1]) and showbubbles;
addchartBubble(mover, a1, Concat("TPH: ", a1), CreateColor(255, 51, 51));
addchartBubble(mover, EBM, Concat("EBM: ", EBM), CreateColor(255, 153, 102));
addchartBubble(mover, a2, Concat("TPL: ", a2), CreateColor(51, 255, 51), no);

#
 
Hi @SleepyZ , I am trying to add a bubble "EBM" which equals TPH minus TPL. I wish to add the bubble next to the "TPH" bubble, but I cannot. I have tried to do so with the following code. Can you please help to fix it? Thank you so much
Code:
input mode     = {default Date, Period};
input lookback = 1;
@Date
input dateback = 20240401;
input time     = 930;
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 a1 = if mode == mode.Date and GetYYYYMMDD() < dateback then Double.NaN else H;
plot a2 = if mode == mode.Date and GetYYYYMMDD() < dateback then Double.NaN else L;
def EBM = a1-a2;

a1.SetDefaultColor(CreateColor(255, 51, 51));
a1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

a2.SetDefaultColor(CreateColor(51, 255, 51));
a2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);



AddLabel(yes, Concat("TPH: ", a1), CreateColor(255, 51, 51));
AddLabel(yes, Concat("TPL: ", a2), CreateColor(51, 255, 51));
AddLabel(yes, Concat("EBM: ", EBM), CreateColor(255, 153, 102));

def xdate = if mode == mode.Date then dateback else if mode == mode.Period and cond1 then GetYYYYMMDD() else xdate[1];
AddCloud(a1,a2, color.GRay,color.gray);
AddLabel(yes, AsPrice(xdate) + " @" + AsPrice(time) + "  H: " + a1 + "  L: " + a2, color.lime);

input showbubbles = yes;
input bubblemover = 2;
input distance_from_TPH_for_EBM = -2;
def b=bubblemover;
def b1= distance_from_TPH_for_EBM;
def mover = isnan(close[b]) and !isnan(close[b+1]) and showbubbles;
def mover1 = isnan(close[b1]) and !isnan(close[b1+1]) and showbubbles;
addchartBubble(mover, a1, Concat("TPH: ", a1), CreateColor(255, 51, 51));
addchartBubble(mover, EBM, Concat("EBM: ", EBM), CreateColor(255, 153, 102));
addchartBubble(mover, a2, Concat("TPL: ", a2), CreateColor(51, 255, 51), no);

#

This will place an EBM bubble above The TPH bubble
Screenshot 2024-07-21 073852.png
Code:
addchartBubble(mover, a1, Concat("EBM: ", EBM), CreateColor(255, 153, 102));
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
258 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