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.

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
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

zeek

Active member
2019 Donor
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"));
 

SleepyZ

Well-known member
VIP
Lifetime
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"));
 

zendude

New member
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.
 

SleepyZ

Well-known member
VIP
Lifetime
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
 

rad14733

Well-known member
VIP
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...
 

zendude

New member
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.
 

rad14733

Well-known member
VIP
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...
 

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.
Top