thinkScript "showOnlyToday" display indicator on current chart

AntMan

New member
I am having difficulty getting the "ShowOnlyToday" & "ShowOnlyLastPeriod" functions to work.. simply put, when I set it to "Yes", the indicator ignores the command and still displays on all the prior days.. I only want the study to display on only the current day and/or only the prior day, depending on the application.. below is the code.. this example has the "ShowOnlyToday" command in it, however if help could be provided for both "ShowOnlyToday" & "ShowOnlyLastPeriod" commands, it would be greatly appreciated, as I am having the issue with both commands..

Code:
declare hide_on_daily;

input time = 0930;
input price = open;
input showOnlyToday = yes;
rec time_value = If(SecondsTillTime(time) == 0, price, time_value[1]);
plot open = If(time_value == 0, Double.NaN, time_value);
open.SetDefaultColor(Color.WHITE);
open.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
open.setStyle(curve.SHORT_DASH);
open.SetLineWeight(2);

Thanks in advance!
 
Solution
Here is the modified script taken from this indicator to meet your request:

Code:
# 5 min opening range
# Robert Payne
#Plot opening range high / low
input ShowTodayOnly = yes;

def Today = if GetDay() == GetLastDay() then 1 else 0;

#Plot yesterday's high / low
plot Yhigh = if ShowTodayOnly and !Today then Double.NaN else high(period = "day" )[1];
plot Ylow = if ShowTodayOnly and !Today then Double.NaN else low(period = "day" )[1];

Hopefully that helps.
Here is the modified script taken from this indicator to meet your request:

Code:
# 5 min opening range
# Robert Payne
#Plot opening range high / low
input ShowTodayOnly = yes;

def Today = if GetDay() == GetLastDay() then 1 else 0;

#Plot yesterday's high / low
plot Yhigh = if ShowTodayOnly and !Today then Double.NaN else high(period = "day" )[1];
plot Ylow = if ShowTodayOnly and !Today then Double.NaN else low(period = "day" )[1];

Hopefully that helps.
 
Solution

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

I need to add a "showonlytoday" function to this study below because i only want the lines to be plotted on the current day, can someone help me add the code?

Code:
#Plot Vertical Lines at specified time
script IsTime {
    input time = 0000;
    plot IsTime = SecondsFromTime(time)[1] < 0 and SecondsFromTime(time) >= 0;
}

input time1 = 0930;

DefineGlobalColor("Time1", Createcolor(120,120,120));

AddVerticalLine(IsTime(time1), Floor(time1 / 100) + ":" + AsText(time1 % 100, "%02.0f"), GlobalColor("Time1"));
 
I need to add a "showonlytoday" function to this study below because i only want the lines to be plotted on the current day, can someone help me add the code?

Code:
#Plot Vertical Lines at specified time
script IsTime {
    input time = 0000;
    plot IsTime = SecondsFromTime(time)[1] < 0 and SecondsFromTime(time) >= 0;
}

input time1 = 0930;

DefineGlobalColor("Time1", Createcolor(120,120,120));

AddVerticalLine(IsTime(time1), Floor(time1 / 100) + ":" + AsText(time1 % 100, "%02.0f"), GlobalColor("Time1"));
Try this
Code:
#Plot Vertical Lines at specified time

input ShowTodayOnly={"No", default "Yes"};
def Today = if GetLastDay() == GetDay() then 1 else 0;

script IsTime {
    input time = 0000;
    plot IsTime = SecondsFromTime(time)[1] < 0 and SecondsFromTime(time) >= 0;
}

input time1 = 0930;

DefineGlobalColor("Time1", Createcolor(120,120,120));

AddVerticalLine(if showTodayOnly and !today
                then double.nan
                else IsTime(time1),
                Floor(time1 / 100) + ":" + AsText(time1 % 100, "%02.0f"),
                GlobalColor("Time1"));
 
This is off the topic but anyone know where to find the descriptions of AsText format specifiers like %02.0f as used in the code above? The only ones I can find online are DOLLAR , THREE_DECIMAL_PLACES , and TWO_DECIMAL_PLACES. Thank you.
 
This is off the topic but anyone know where to find the descriptions of AsText format specifiers like %02.0f as used in the code above? The only ones I can find online are DOLLAR , THREE_DECIMAL_PLACES , and TWO_DECIMAL_PLACES. Thank you.
I looked this up through a google search and it appears to be JAVA script. I assume since TOS uses JAVA, if you know the JAVA coding it will accept it. https://stackoverflow.com/questions...r-0-9-to-display-with-2-digits-its-not-a-date
 
I looked this up through a google search and it appears to be JAVA script. I assume since TOS uses JAVA, if you know the JAVA coding it will accept it. https://stackoverflow.com/questions...r-0-9-to-display-with-2-digits-its-not-a-date

That's assuming that TOS will accept injecting Javascript and I find that doubtful from a security perspective because it that were the case then one could use Javascript to make/accept calls to Java which opens Pandora's Box... But, yes, TOS is written in Java which is not only a programming language but also an operating system in and of itself...
 
I looked this up through a google search and it appears to be JAVA script. I assume since TOS uses JAVA, if you know the JAVA coding it will accept it. https://stackoverflow.com/questions...r-0-9-to-display-with-2-digits-its-not-a-date

Thank you for shedding some light on this. I tried the C printf formating strings at first unsuccessfully and that would explain why.

Another method of using AsText() is to combine it with Round()... While undocumented, you can use AsText(Round(price, 0)) to eliminate decimal points altogether...

I find the printf(?) style format useful because I can pad numbers with leading or trailing zeros which round() truncates.

TOS is written in Java which is not only a programming language but also an operating system in and of itself...

Incidentally I use the Java version TOS with Azul Zulu build of JRE under Ubuntu and the performance is mediocre at best. I don't know if it's an implementation or a platform issue but the user interface lags terribly, much worse than the windows version under Wine emulator. If anyone has a suggestion on how to improve performance on the java version, I would appreciate it.
 
Incidentally I use the Java version TOS with Azul Zulu build of JRE under Ubuntu and the performance is mediocre at best. I don't know if it's an implementation or a platform issue but the user interface lags terribly, much worse than the windows version under Wine emulator. If anyone has a suggestion on how to improve performance on the java version, I would appreciate it.

I haven't installed TOS on Ubuntu yet but it has been on my ToDo list for a while now... I know the support for Linux based installs is virtually nonexistent... I also need to find space at my desk for a new Ubuntu Desktop PC as mine has been collecting dust for longer than I can remember... Ubuntu used to be main workstation environment but when I set my work area back up after I moved I switched to Windows considering that's what I support as an IT Consultant... I used to eat, sleep, and breathe Linux, PHP, Javascript, MySQL, Perl, RegExp, XHTML, CSS, and whatever else... But I digress...

At some point perhaps we can setup a subforum for TOS on Linux...
 
Does this still work? I am using astext(round(variable, 0)) in an alert and it prints with 2 dps. I am looking to eliminate the dps.

edit: using astext/round(variable) combo does not remove the dps. just using "variable" prints without any decimals.


@zendude Another method of using AsText() is to combine it with Round()... While undocumented, you can use AsText(Round(price, 0)) to eliminate decimal points altogether...
 
Last edited:
Does this still work? I am using astext(round(variable, 0)) in an alert and it prints with 2 dp. I am looking to eliminate the dp.

Screenshot-2022-10-27-133830.png
Ruby:
def variable = 14.067;
addlabel(1,astext(round(variable, 0)));#Astext creates 2 DP everytime. Useful when you want 14.1 to be 14.10
addlabel(1,round(variable,0));#Does what you requested
 
Help needed to set the showonlytoday Function for previous month high/low indicator when set to yes to show plot only previous month & next month high/low based on current month high/low. Below is my code. Would highly appreciate if anyone can help on the same.


input aggregationPeriod = AggregationPeriod.Month;
def prev_high = high(period = aggregationPeriod)[1];
def prev_low = low(period = aggregationPeriod)[1];

plot ph = prev_high;
plot pc = prev_low;

#AddCloud(ph, pc, color.green, color.green);
ph.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

input showBubble = yes;
input ShiftBubble = 5;
def n1 = ShiftBubble+1;

def cond = showBubble and IsNaN(close[ShiftBubble]) and !IsNaN(close[n1]) ;

AddChartBubble(cond, ph, Concat("PrevMonthHigh: ", Round(ph)), Color.MAGENTA);

AddChartBubble(cond, pc, Concat("PrevMonthLow: ", Round(pc)), Color.MAGENTA);
 
Help needed to set the showonlytoday Function for previous month high/low indicator when set to yes to show plot only previous month & next month high/low based on current month high/low. Below is my code. Would highly appreciate if anyone can help on the same.


input aggregationPeriod = AggregationPeriod.Month;
def prev_high = high(period = aggregationPeriod)[1];
def prev_low = low(period = aggregationPeriod)[1];

plot ph = prev_high;
plot pc = prev_low;

#AddCloud(ph, pc, color.green, color.green);
ph.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

input showBubble = yes;
input ShiftBubble = 5;
def n1 = ShiftBubble+1;

def cond = showBubble and IsNaN(close[ShiftBubble]) and !IsNaN(close[n1]) ;

AddChartBubble(cond, ph, Concat("PrevMonthHigh: ", Round(ph)), Color.MAGENTA);

AddChartBubble(cond, pc, Concat("PrevMonthLow: ", Round(pc)), Color.MAGENTA);

See if this helps

Screenshot 2023-06-11 134626.png
Code:
#Month_HL_PriorMonth_HL_ShowTodayOnly
#Based upon TOS aggregationperiod.month which only uses Regular Trading Hours

input showtodayonly = yes;

plot monhigh = if IsNaN(close) or showtodayonly and !IsNaN(close(period = AggregationPeriod.MONTH)[-1])
                     then Double.NaN
                     else high(period = AggregationPeriod.MONTH)
               ;
monhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
monhigh.SetDefaultColor(Color.GREEN);
plot monlow = if IsNaN(close) or
                 showtodayonly and !IsNaN(close(period = AggregationPeriod.MONTH)[-1])
              then Double.NaN
              else low(period = AggregationPeriod.MONTH);
monlow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
monlow.SetDefaultColor(Color.RED);

plot priormonhigh =  if IsNaN(close) or
                        showtodayonly and !IsNaN(close(period = AggregationPeriod.MONTH)[-1])
                     then Double.NaN
                     else high(period = AggregationPeriod.MONTH)[1]
               ;
priormonhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
priormonhigh.SetDefaultColor(Color.GREEN);
plot priormonlow = if IsNaN(close) or
                 showtodayonly and !IsNaN(close(period = AggregationPeriod.MONTH)[-1])
              then Double.NaN
              else low(period = AggregationPeriod.MONTH)[1];
priormonlow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
priormonlow.SetDefaultColor(Color.RED);

input showbubbles = yes;
input bubblemover = 3;
def b  = bubblemover;
def b1 = b + 1;

AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), monhigh[b1], "MH", Color.GREEN);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), priormonhigh[b1], "PMH", Color.GREEN);

AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), monlow[b1], "ML", Color.RED);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), priormonlow[b1], "PML", Color.RED);
 
See if this helps
Thanks a lot really helps. just wanted to check is it possible to populate the price values on the chart bubbles along with names. like PMH 240.5. Also I notice the previous month high and low lines do to extend to the end of month in the chart. where if you check the code i shared the line extends to the end of the month. would be great if you can assist. thanks a lot once again.
 
Thanks a lot really helps. just wanted to check is it possible to populate the price values on the chart bubbles along with names. like PMH 240.5. Also I notice the previous month high and low lines do to extend to the end of month in the chart. where if you check the code i shared the line extends to the end of the month. would be great if you can assist. thanks a lot once again.

Note: The image shows your original code in the upper panel, the middle shows that code modified and the modified post #14 code

Here is the above code post #14 modified as I think you want.
Code:
#Month_HL_PriorMonth_HL_ShowTodayOnly
#Based upon TOS aggregationperiod.month which only uses Regular Trading Hours

input showlastonly = yes;
input showcurrentmonth = yes;

def mohigh = if !showcurrentmonth then double.nan else high(period = AggregationPeriod.MONTH);
def molow  = if !showcurrentmonth then double.nan else low(period = AggregationPeriod.MONTH);
plot monhigh = if showlastonly and !IsNaN(high(period = AggregationPeriod.MONTH)[-1])
                     then Double.NaN
                     else  mohigh;
               ;
monhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
monhigh.SetDefaultColor(Color.GREEN);

plot monlow = if showlastonly and !IsNaN(close(period = AggregationPeriod.MONTH)[-1])
              then Double.NaN
              else molow;
monlow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
monlow.SetDefaultColor(Color.RED);

plot priormonhigh =  if showlastonly and !IsNaN(close(period = AggregationPeriod.MONTH)[-1])
                     then Double.NaN
                     else high(period=aggregationPeriod.MONTH)[1]
               ;
priormonhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
priormonhigh.SetDefaultColor(Color.GREEN);
plot priormonlow = if showlastonly and !IsNaN(close(period = AggregationPeriod.MONTH)[-1])
              then Double.NaN
              else low(period = AggregationPeriod.MONTH)[1];
priormonlow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
priormonlow.SetDefaultColor(Color.RED);

input showbubbles = yes;
input bubblemover = 5;
def b  = bubblemover;
def b1 = b + 1;

AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), monhigh[b1], "MH: " + astext(monhigh[b1]), Color.GREEN);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), priormonhigh[b1], "PMH: " + astext(priormonhigh[b1]), Color.GREEN);

AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), monlow[b1], "ML: " + astext(monlow[b1]), Color.RED);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), priormonlow[b1], "PML: " + astext(priormonlow[b1]), Color.RED);
I did not use your code as I thought that you wanted the current month displayed also. Now here is that code modified to only show the last plot
Code:
input showlastonly = yes;
input lookback = 1;
input aggregationPeriod = AggregationPeriod.Month;
def prev_high = if isnan(high(period = aggregationPeriod)) then double.nan else high(period = aggregationPeriod)[lookback];
def prev_low  = if isnan(low(period = aggregationPeriod)) then double.nan else low(period = aggregationPeriod)[lookback];

plot ph = if showlastonly and !isnan(close(period=aggregationPeriod)[-1]) then double.nan else prev_high;
plot pc = if showlastonly and !isnan(close(period=aggregationPeriod)[-1]) then double.nan else prev_low;

#AddCloud(ph, pc, color.green, color.green);
ph.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

input showBubble = yes;
input ShiftBubble = 5;
def n1 = ShiftBubble+1;

def cond = showBubble and IsNaN(close[ShiftBubble]) and !IsNaN(close[n1]) ;

AddChartBubble(cond, ph, Concat("PMH: ", astext(ph)), Color.MAGENTA);

AddChartBubble(cond, pc, Concat("PML: ", astext(pc)), Color.MAGENTA);
Screenshot 2023-07-13 084431.png
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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