Only plot on the current day

Robb

New member
More of a thinkscript question but how do I only plot on the current day? I have the following code that plots yesterday's high, low, open and close and it works fine, but it also plots on all the prior days as well. The chart bubble only shows up for the current day, but I can't duplicate that same functionality for the horizontal lines. Thanks in advance!


Code:
input higherTimeFrame = AggregationPeriod.DAY;
input Lookback = 1;
input first_day_of_week = {default Monday};
def should_hide_close = GetDayofWeek(GetYYYYMMDD()) == first_day_of_week + 1;

plot PREvLOW =  low(period = higherTimeFrame)[Lookback];
PREvLOW.SetLineWeight(1);
PREvLOW.SetDefaultColor(Color.UPTICK);
PREvLOW.SetPaintingStrategy(PaintingStrategy.DASHES);

plot PREvHIGH =  high(period = higherTimeFrame)[Lookback];
PREvHIGH.SetLineWeight(1);
PREvHIGH.SetDefaultColor(Color.DOWNTICK);
PREvHIGH.SetPaintingStrategy(PaintingStrategy.DASHES);

plot PREvCLOSE = if should_hide_close then double.NaN else close(period = higherTimeFrame)[Lookback];
PREvCLOSE.SetLineWeight(1);
PREvCLOSE.SetDefaultColor(Color.YELLOW);
PREvCLOSE.SetPaintingStrategy(PaintingStrategy.DASHES);

def shouldPlot = BarNumber() == HighestAll(BarNumber());

plot open = open(period = higherTimeFrame)[Lookback];
open.SetLineWeight(1);
open.SetDefaultColor(Color.white);
open.SetPaintingStrategy(PaintingStrategy.DASHES);

AddChartBubble(BarNumber() == HighestAll(BarNumber()) and YES, Round(open), "PD Open: " + Round(open), Color.WHITE);

AddChartBubble(BarNumber() == HighestAll(BarNumber()) and YES, Round(PREvHIGH), "PD High: " + Round(PREvHIGH), Color.RED);

AddChartBubble(BarNumber() == HighestAll(BarNumber()) and YES, Round(PREvLOW), "PD Low: " + Round(PREvLOW), Color.GREEN);

AddChartBubble(BarNumber() == HighestAll(BarNumber()) and YES, Round(PREvCLOSE), "PD Close: " + Round(PREvCLOSE), Color.YELLOW);

1696262130797.png
 
More of a thinkscript question but how do I only plot on the current day? I have the following code that plots yesterday's high, low, open and close and it works fine, but it also plots on all the prior days as well. The chart bubble only shows up for the current day, but I can't duplicate that same functionality for the horizontal lines. Thanks in advance!


Code:
input higherTimeFrame = AggregationPeriod.DAY;
input Lookback = 1;
input first_day_of_week = {default Monday};
def should_hide_close = GetDayofWeek(GetYYYYMMDD()) == first_day_of_week + 1;

plot PREvLOW =  low(period = higherTimeFrame)[Lookback];
PREvLOW.SetLineWeight(1);
PREvLOW.SetDefaultColor(Color.UPTICK);
PREvLOW.SetPaintingStrategy(PaintingStrategy.DASHES);

plot PREvHIGH =  high(period = higherTimeFrame)[Lookback];
PREvHIGH.SetLineWeight(1);
PREvHIGH.SetDefaultColor(Color.DOWNTICK);
PREvHIGH.SetPaintingStrategy(PaintingStrategy.DASHES);

plot PREvCLOSE = if should_hide_close then double.NaN else close(period = higherTimeFrame)[Lookback];
PREvCLOSE.SetLineWeight(1);
PREvCLOSE.SetDefaultColor(Color.YELLOW);
PREvCLOSE.SetPaintingStrategy(PaintingStrategy.DASHES);

def shouldPlot = BarNumber() == HighestAll(BarNumber());

plot open = open(period = higherTimeFrame)[Lookback];
open.SetLineWeight(1);
open.SetDefaultColor(Color.white);
open.SetPaintingStrategy(PaintingStrategy.DASHES);

AddChartBubble(BarNumber() == HighestAll(BarNumber()) and YES, Round(open), "PD Open: " + Round(open), Color.WHITE);

AddChartBubble(BarNumber() == HighestAll(BarNumber()) and YES, Round(PREvHIGH), "PD High: " + Round(PREvHIGH), Color.RED);

AddChartBubble(BarNumber() == HighestAll(BarNumber()) and YES, Round(PREvLOW), "PD Low: " + Round(PREvLOW), Color.GREEN);

AddChartBubble(BarNumber() == HighestAll(BarNumber()) and YES, Round(PREvCLOSE), "PD Close: " + Round(PREvCLOSE), Color.YELLOW);

View attachment 19850

The input showtodayonly and corresponding code in the plot statements should work how you want.

Screenshot 2023-10-16 103413.png
Code:
#Only plot on the current day

input higherTimeFrame = AggregationPeriod.DAY;
input Lookback = 1;
input first_day_of_week = {default Monday};
def should_hide_close = GetDayOfWeek(GetYYYYMMDD()) == first_day_of_week + 1;

input showtodayonly = yes;
plot PREvLOW =  if showtodayonly and GetDay() != GetLastDay() then Double.NaN else low(period = higherTimeFrame)[Lookback];
PREvLOW.SetLineWeight(1);
PREvLOW.SetDefaultColor(Color.UPTICK);
PREvLOW.SetPaintingStrategy(PaintingStrategy.DASHES);

plot PREvHIGH = if showtodayonly and GetDay() != GetLastDay() then Double.NaN else high(period = higherTimeFrame)[Lookback];
PREvHIGH.SetLineWeight(1);
PREvHIGH.SetDefaultColor(Color.DOWNTICK);
PREvHIGH.SetPaintingStrategy(PaintingStrategy.DASHES);

plot PREvCLOSE = if showtodayonly and GetDay() != GetLastDay() or should_hide_close then Double.NaN else close(period = higherTimeFrame)[Lookback];
PREvCLOSE.SetLineWeight(1);
PREvCLOSE.SetDefaultColor(Color.YELLOW);
PREvCLOSE.SetPaintingStrategy(PaintingStrategy.DASHES);
PREvCLOSE.SetHiding(!should_hide_close);

def shouldPlot = BarNumber() == HighestAll(BarNumber());

plot open = if showtodayonly and GetDay() != GetLastDay() then Double.NaN else open(period = higherTimeFrame)[Lookback];
open.SetLineWeight(1);
open.SetDefaultColor(Color.WHITE);
open.SetPaintingStrategy(PaintingStrategy.DASHES);

AddChartBubble(BarNumber() == HighestAll(BarNumber()) and yes, Round(open), "PD Open: " + Round(open), Color.WHITE);

AddChartBubble(BarNumber() == HighestAll(BarNumber()) and yes, Round(PREvHIGH), "PD High: " + Round(PREvHIGH), Color.RED);

AddChartBubble(BarNumber() == HighestAll(BarNumber()) and yes, Round(PREvLOW), "PD Low: " + Round(PREvLOW), Color.GREEN);

AddChartBubble(BarNumber() == HighestAll(BarNumber()) and yes, Round(PREvCLOSE), "PD Close: " + Round(PREvCLOSE), Color.YELLOW);
 

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