Plot 1hr high close

shakib3585

Active member
VIP
Greetings,

I'm seeking the high and close values of the very last one-hour bar from the trading session two days ago and would like to represent them as horizontal lines on a chart. If there was a post-market session for a specific ticker symbol on that day, then that data will be included as well.

Your help is much appreciated.

Thank you.
 
Hello @SleepyZ , I tried the attached code to scan stocks based on a month aggregation, but none appeared. I see that the tikr IVVD satisfied the criteria but was not caught by the filter even though it satisfied. Can you please suggest.

Thank you
Code:
def ymd      =  GetMonth();
def candles  = !IsNaN(close);
def capture  = candles and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay  = (HighestAll(dayCount) - dayCount) ;

def poc      = if IsNaN(close)
               then poc[1]
               else if thisDay == 1 then reference VolumeProfile("time per profile" = "Month", "on expansion" = no)
               else poc[1];
def vahigh   = if IsNaN(close)
               then vahigh[1]
               else if thisDay == 1 then reference VolumeProfile("time per profile" = "Month", "on expansion" = no).VAHigh
               else vahigh[1];
def valow    = if IsNaN(close)
               then valow[1]
               else if thisDay == 1 then reference VolumeProfile("time per profile" = "Month", "on expansion" = no).VALow
                else valow[1];

def poc1    =  poc;
def vahigh1 =  vahigh;
def valow1  =  valow;


def tph = vahigh1;
def pvo = poc1;
def tpl = valow1;
 

plot scan = close>=pvo;

I have made a better version for the scanner, but it only works on a chart (see Match in image). But it is not producing the same values in the scanner. It appears to not work accurately for the scans you want.

Also, the scan would not work against all stocks or other large lists. For example, it woud run against the Russel 1000, but not the Russell 2000 or 3000 (TOS overflow error).

Screenshot 2023-12-18 085702.png

Code:
input getback   = 0;
input timeframe = {Day, Week, default Month};

def cond     = if timeframe == timeframe."Month"
               then GetMonth() != GetMonth()[1]
               else if timeframe == timeframe."Week"
               then GetWeek() != GetWeek()[1]
               else GetYYYYMMDD() != GetYYYYMMDD();

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 10, "value area percent" = 70);

def vah =  vol.GetHighestValueArea();
def vah1 = if vah != vah[1]
           then vah[1]
           else vah1[1];
def vah2 = if vah1 != vah1[1]
           then vah1[1]
           else vah2[1];

def poc =  vol.GetPointOfControl();
def Poc1 = if poc != poc[1]
           then poc[1]
           else Poc1[1];
def Poc2 = if Poc1 != Poc1[1]
           then Poc1[1]
           else Poc2[1];

def val =  vol.GetLowestValueArea();
def val1 = if val != val[1]
           then val[1]
           else val1[1];
def val2 = if val1 != val1[1]
           then val1[1]
           else val2[1];


AddLabel(getback == 0, getback+" "+timeframe+"s Back: VAH " + vah + " POC: " + poc + " VAL: " + val, Color.YELLOW);
AddLabel(getback == 1, getback+" "+timeframe+"s Back: VAH " + vah1 + " POC: " + Poc1 + " VAL: " + val1, Color.MAGENTA);
AddLabel(getback == 2, getback+" "+timeframe+"s Back: VAH " + vah2 + " POC: " + Poc2 + " VAL: " + val2, Color.WHITE);

#plot scan = close >= round(poc);
#
 
I have made a better version for the scanner, but it only works on a chart (see Match in image). But it is not producing the same values in the scanner. It appears to not work accurately for the scans you want.

Also, the scan would not work against all stocks or other large lists. For example, it woud run against the Russel 1000, but not the Russell 2000 or 3000 (TOS overflow error).

View attachment 20453
Code:
input getback   = 0;
input timeframe = {Day, Week, default Month};

def cond     = if timeframe == timeframe."Month"
               then GetMonth() != GetMonth()[1]
               else if timeframe == timeframe."Week"
               then GetWeek() != GetWeek()[1]
               else GetYYYYMMDD() != GetYYYYMMDD();

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 10, "value area percent" = 70);

def vah =  vol.GetHighestValueArea();
def vah1 = if vah != vah[1]
           then vah[1]
           else vah1[1];
def vah2 = if vah1 != vah1[1]
           then vah1[1]
           else vah2[1];

def poc =  vol.GetPointOfControl();
def Poc1 = if poc != poc[1]
           then poc[1]
           else Poc1[1];
def Poc2 = if Poc1 != Poc1[1]
           then Poc1[1]
           else Poc2[1];

def val =  vol.GetLowestValueArea();
def val1 = if val != val[1]
           then val[1]
           else val1[1];
def val2 = if val1 != val1[1]
           then val1[1]
           else val2[1];


AddLabel(getback == 0, getback+" "+timeframe+"s Back: VAH " + vah + " POC: " + poc + " VAL: " + val, Color.YELLOW);
AddLabel(getback == 1, getback+" "+timeframe+"s Back: VAH " + vah1 + " POC: " + Poc1 + " VAL: " + val1, Color.MAGENTA);
AddLabel(getback == 2, getback+" "+timeframe+"s Back: VAH " + vah2 + " POC: " + Poc2 + " VAL: " + val2, Color.WHITE);

#plot scan = close >= round(poc);
#
Thanks a ton, @SleepyZ . For the scan, other than removing the "#" sign before the "plot scan" , do I need to change anything else.
 
Thanks a ton, @SleepyZ . For the scan, other than removing the "#" sign before the "plot scan" , do I need to change anything else.

That works on a chart. Note that geback is just used for label display in that code.

The below works in the scanner, but with you knowing that it does not match with the actual volumeprofile.

Also, I now understand what your MAX:W means. For a best match of the scan to a chart, it is best to use a the same timeframe as your scan setting and code setting, ie: day, week, or month, POC is the current profile, POC1 is 1 day back and POC2 is 2 days back.

Screenshot 2023-12-18 113547.png
Code:
input timeframe = {Day, Week, default Month};

def cond     = if timeframe == timeframe."Month"
               then GetMonth() != GetMonth()[1]
               else if timeframe == timeframe."Week"
               then GetWeek() != GetWeek()[1]
               else GetYYYYMMDD() != GetYYYYMMDD();

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 10, "value area percent" = 70);

def vah =  vol.GetHighestValueArea();
def vah1 = if vah != vah[1]
           then vah[1]
           else vah1[1];
def vah2 = if vah1 != vah1[1]
           then vah1[1]
           else vah2[1];

def poc =  vol.GetPointOfControl();
def Poc1 = if poc != poc[1]
           then poc[1]
           else Poc1[1];
def Poc2 = if Poc1 != Poc1[1]
           then Poc1[1]
           else Poc2[1];

def val =  vol.GetLowestValueArea();
def val1 = if val != val[1]
           then val[1]
           else val1[1];
def val2 = if val1 != val1[1]
           then val1[1]
           else val2[1];

#input getback   = 0;
#AddLabel(getback == 0, getback+" "+timeframe+"s Back: VAH " + vah + " POC: " + poc + " VAL: " + val, Color.YELLOW);
#AddLabel(getback == 1, getback+" "+timeframe+"s Back: VAH " + vah1 + " POC: " + Poc1 + " VAL: " + val1, Color.MAGENTA);
#AddLabel(getback == 2, getback+" "+timeframe+"s Back: VAH " + vah2 + " POC: " + Poc2 + " VAL: " + val2, Color.WHITE);

plot scan = close >= round(poc);
#
 
That works on a chart. Note that geback is just used for label display in that code.

The below works in the scanner, but with you knowing that it does not match with the actual volumeprofile.

Also, I now understand what your MAX:W means. For a best match of the scan to a chart, it is best to use a the same timeframe as your scan setting and code setting, ie: day, week, or month, POC is the current profile, POC1 is 1 day back and POC2 is 2 days back.
Thank you king @SleepyZ
 
THis program is display every day. I need help to adjust it to display in one day (today only). THank you!!!


input aggperiod = AggregationPeriod.HOUR;
input ORopentime = 1515;
input ORendtime = 1600;
input ORextendtime = 2000;
input showtodayonly = yes;

def na = Double.NaN;

#Find range of bars during aggperiod; Current day's OR excluded
def ORActive = if showtodayonly and GetDay() != GetlastDay() and
SecondsFromTime(ORopentime) >= 0 and SecondsFromTime(ORendtime) < 0
then 1 else 0;
#Extended bars plot from ORActive Aggperiod that are stopped at ORendtime
def ORExtend = if GetDay() != GetlastDay() and
SecondsFromTime(ORopentime) >= 0 and SecondsFromTime(ORExtendtime) <= 0
then 1 else 0;

#ORActive plots are Extended
def high1 = if ORActive then high(period = aggperiod) else high1[1];
def low1 = if ORActive then low(period = aggperiod) else low1[1];
def close1 = if ORActive then close(period = aggperiod) else close1[1];

#Extended ORActive plots are stopped at ORExtend time
def high1ext = if ORExtend then high1 else na;
def low1ext = if ORExtend then low1 else na;
def close1ext = if ORExtend then close1 else na;

plot high1_2000 = high1;
high1_2000.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot close1_2000 = close1ext;
close1_2000.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot low1_2000 = low1;
low1_2000.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
THis program is display every day. I need help to adjust it to display in one day (today only). THank you!!!


input aggperiod = AggregationPeriod.HOUR;
input ORopentime = 1515;
input ORendtime = 1600;
input ORextendtime = 2000;
input showtodayonly = yes;

def na = Double.NaN;

#Find range of bars during aggperiod; Current day's OR excluded
def ORActive = if showtodayonly and GetDay() != GetlastDay() and
SecondsFromTime(ORopentime) >= 0 and SecondsFromTime(ORendtime) < 0
then 1 else 0;
#Extended bars plot from ORActive Aggperiod that are stopped at ORendtime
def ORExtend = if GetDay() != GetlastDay() and
SecondsFromTime(ORopentime) >= 0 and SecondsFromTime(ORExtendtime) <= 0
then 1 else 0;

#ORActive plots are Extended
def high1 = if ORActive then high(period = aggperiod) else high1[1];
def low1 = if ORActive then low(period = aggperiod) else low1[1];
def close1 = if ORActive then close(period = aggperiod) else close1[1];

#Extended ORActive plots are stopped at ORExtend time
def high1ext = if ORExtend then high1 else na;
def low1ext = if ORExtend then low1 else na;
def close1ext = if ORExtend then close1 else na;

plot high1_2000 = high1;
high1_2000.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot close1_2000 = close1ext;
close1_2000.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot low1_2000 = low1;
low1_2000.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

This will display only the last plots if showonlylast == yes

Screenshot 2024-04-10 071102.png
Code:
#HLC_Showlastonly

input aggperiod = AggregationPeriod.HOUR;
input ORopentime = 1515;
input ORendtime = 1600;
input ORextendtime = 2000;
input showtodayonly = yes;

def na = Double.NaN;

#Find range of bars during aggperiod; Current day's OR excluded
def ORActive = if SecondsFromTime(ORopentime) >= 0 and SecondsFromTime(ORendtime) < 0
then 1 else 0;
#Extended bars plot from ORActive Aggperiod that are stopped at ORendtime
def ORExtend = if SecondsFromTime(ORopentime) >= 0 and SecondsFromTime(ORextendtime) <= 0
then 1 else 0;

#ORActive plots are Extended
def high1  = if ORActive then high(period = aggperiod) else high1[1];
def low1   = if ORActive then low(period = aggperiod) else low1[1];
def close1 = if ORActive then close(period = aggperiod) else close1[1];

#Extended ORActive plots are stopped at ORExtend time
def high1ext  = if ORExtend then high1 else high1ext[1];
def low1ext   = if ORExtend then low1 else low1ext[1];
def close1ext = if ORExtend then close1 else close1ext[1];

input showonlylast = yes;
def count = if !IsNaN(close) and high1ext != high1ext[1] then count[1] + 1 else count[1];
def cond = HighestAll(count) - count + 1;

plot high1_2000 = if showonlylast and cond > 1 then na else high1;
high1_2000.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot close1_2000 = if showonlylast and cond > 1 then na else close1ext;
close1_2000.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot low1_2000 = if showonlylast and cond > 1 then na else low1;
low1_2000.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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