Extract the Previous Daily High value and use it on a 1-minute chart label

shakib3585

Active member
VIP
Greetings All,

On a given trading day, I am trying to extract the previous daily high of a given week and compare that with the current daily "open" price. I am trying to use that label on a 1-minute chart. The code I attempted is as follows,

Code:
# definition of previous current weekly high = PCWH
def newWeek = GetWeek() <> GetWeek()[1];
def PCWH = if NewWeek then High(period = aggregationPeriod.DAY)else if High(period = aggregationPeriod.DAY) [1] > PCWH[1] then High(period = aggregationPeriod.DAY)[1] else PCWH[1];
def PC_WH = PCWH ;
def open = Open(period = aggregationPeriod.DAY);
def p3 = Open(period = aggregationPeriod.DAY)< PC_WH;


AddLabel(yes, Concat("PCWH: ", PC_WH), Color.oraNGE);
AddLabel(yes, Concat("Open: ", Open(period = aggregationPeriod.DAY)), Color.cyan);
AddLabel(yes, "Status ", if p3 then color.green else color.red);

On a daily time frame, the above code locates the previous daily high of a given week exactly, but when I try to use it on a 1-minute chart, it messes up. Can anyone please help me to fix the code such that I can extract the correct "previous daily high" and use the exact value on a 1minute chart label

Thank you,

Fais
 
Solution
Greetings All,

On a given trading day, I am trying to extract the previous daily high of a given week and compare that with the current daily "open" price. I am trying to use that label on a 1-minute chart. The code I attempted is as follows,

Code:
# definition of previous current weekly high = PCWH
def newWeek = GetWeek() <> GetWeek()[1];
def PCWH = if NewWeek then High(period = aggregationPeriod.DAY)else if High(period = aggregationPeriod.DAY) [1] > PCWH[1] then High(period = aggregationPeriod.DAY)[1] else PCWH[1];
def PC_WH = PCWH ;
def open = Open(period = aggregationPeriod.DAY);
def p3 = Open(period = aggregationPeriod.DAY)< PC_WH;


AddLabel(yes, Concat("PCWH: ", PC_WH), Color.oraNGE);
AddLabel(yes, Concat("Open: ", Open(period...
Did you display enough data on your 1m chart? You're retrieving data from the weekly chart, so there must be at least one week of data available even when you're on the 1m chart.
 
Greetings All,

On a given trading day, I am trying to extract the previous daily high of a given week and compare that with the current daily "open" price. I am trying to use that label on a 1-minute chart. The code I attempted is as follows,

Code:
# definition of previous current weekly high = PCWH
def newWeek = GetWeek() <> GetWeek()[1];
def PCWH = if NewWeek then High(period = aggregationPeriod.DAY)else if High(period = aggregationPeriod.DAY) [1] > PCWH[1] then High(period = aggregationPeriod.DAY)[1] else PCWH[1];
def PC_WH = PCWH ;
def open = Open(period = aggregationPeriod.DAY);
def p3 = Open(period = aggregationPeriod.DAY)< PC_WH;


AddLabel(yes, Concat("PCWH: ", PC_WH), Color.oraNGE);
AddLabel(yes, Concat("Open: ", Open(period = aggregationPeriod.DAY)), Color.cyan);
AddLabel(yes, "Status ", if p3 then color.green else color.red);

On a daily time frame, the above code locates the previous daily high of a given week exactly, but when I try to use it on a 1-minute chart, it messes up. Can anyone please help me to fix the code such that I can extract the correct "previous daily high" and use the exact value on a 1minute chart label

Thank you,

Fais


your study displays numbers,
but, today, wed am before the normal opening, a higher high from friday is saved , not the previous day high.
so i don't know what data you want to read to get a high from.


it would help if you could clearly list the rules the study should follow.



i think there is some weird quirk happening with your code.
def PCWH = ...
your formula looks ok, but it is sometimes saving a higher high from last weeks friday...



issues
'messes up' doesn't tell us anything.
if you want help , tell us what is happening. what do you see? what stock? what chart time? after hours turned on?


i don't know what this is supposed to mean. you can't describe something as previous AND current.
# definition of previous current weekly...


why do you mention week, when you want to compare todays open to yesterdays high? what does week have to do with it?
from your formula, def PCWH = ,
on monday , you are comparing monday high to monday open.
then on the next 4 days, you compare the prev day high to the current day open.
on tuesday , you are comparing monday high to tuesday open.


you are defining open. open is a reserved word, it shouldn't be used as a variable name. you may see strange/unexpected values from doing things like this.
this variable isn't being used. when
def open = Open(period = aggregationPeriod.DAY);
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Fundamentals

don't need to use 2nd aggregation to find data in the past.

don't need to use concat(). use + to join text objects.


here is my version, to compare yesterdays high to todays open.

Code:
def newday = getday() <> getday()[1];
def daycnt = if bn == 1 then 1 else if newday then daycnt[1] + 1 else daycnt[1];
def currentday = getday() == getlastday();
def prevday = getday() + 1 == getlastday();

def prevdayhi = if !prevday then prevdayhi[1]
else if newday then high
else if high > prevdayhi[1] then high
else prevdayhi[1];

def currentdayopen = if newday and
currentday then open
else currentdayopen[1];

def openlower = (currentdayopen < prevdayhi);

AddLabel(1, " ", color.black);

AddLabel(1,
"prev day hi " + prevdayhi
, color.orange);

AddLabel(1,
"Open: " + currentdayopen
, Color.cyan);

AddLabel(1,
"Status" ,
( if openlower then color.green else color.red));
#
 
Solution
your study displays numbers,
but, today, wed am before the normal opening, a higher high from friday is saved , not the previous day high.
so i don't know what data you want to read to get a high from.


it would help if you could clearly list the rules the study should follow.



i think there is some weird quirk happening with your code.
def PCWH = ...
your formula looks ok, but it is sometimes saving a higher high from last weeks friday...



issues
'messes up' doesn't tell us anything.
if you want help , tell us what is happening. what do you see? what stock? what chart time? after hours turned on?


i don't know what this is supposed to mean. you can't describe something as previous AND current.
# definition of previous current weekly...


why do you mention week, when you want to compare todays open to yesterdays high? what does week have to do with it?
from your formula, def PCWH = ,
on monday , you are comparing monday high to monday open.
then on the next 4 days, you compare the prev day high to the current day open.
on tuesday , you are comparing monday high to tuesday open.


you are defining open. open is a reserved word, it shouldn't be used as a variable name. you may see strange/unexpected values from doing things like this.
this variable isn't being used. when
def open = Open(period = aggregationPeriod.DAY);
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Fundamentals

don't need to use 2nd aggregation to find data in the past.

don't need to use concat(). use + to join text objects.


here is my version, to compare yesterdays high to todays open.

Code:
def newday = getday() <> getday()[1];
def daycnt = if bn == 1 then 1 else if newday then daycnt[1] + 1 else daycnt[1];
def currentday = getday() == getlastday();
def prevday = getday() + 1 == getlastday();

def prevdayhi = if !prevday then prevdayhi[1]
else if newday then high
else if high > prevdayhi[1] then high
else prevdayhi[1];

def currentdayopen = if newday and
currentday then open
else currentdayopen[1];

def openlower = (currentdayopen < prevdayhi);

AddLabel(1, " ", color.black);

AddLabel(1,
"prev day hi " + prevdayhi
, color.orange);

AddLabel(1,
"Open: " + currentdayopen
, Color.cyan);

AddLabel(1,
"Status" ,
( if openlower then color.green else color.red));
#
Thank you @halcyonguy.
 
I was checking my code today and was unable to find my mistake for a given stock's daily price. The target of "PCWH" was to obtain the previous weekly high of the current week. The previous daily high of a given week may or may not be equal to the previous weekly high of the same week. I saw that if I plotted the code only on the daily chart, it worked fine for obtaining PCWH. I have attached the link of HSCS chart for reference .Please correct me if I am wrong @halcyonguy if I am just plotting at Daily timeframe only.

Much appreciated
 

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