Input Date and Time, Use GetYYYYMMDD and GetTime as default possible?

The pseudo-code that I'd like to work is:

Code:
input signalDate = GetYYYYMMDD();
input signalTime = GetTime();

...however it says invalid statement for these inputs. You aren't allowed to use the Get functions for inputs. I'd like to have default values load into these inputs with the current date and time.

You CAN do:

Code:
def signalDate = GetYYYYMMDD();
def signalTime = GetTime();

...however those values don't remain constant, they change with time. You CAN also do:

Code:
input signalDate = 20220727;
input signalTime = 1300;

...however I'd like to NOT have to enter the current date and time manually every time.

Can we set a default value for date/time inputs to the current date/time, or how can I define them as def's and make sure they remain static/don't change once the script is added to a chart?
 
Solution
Thanks for the reply. No this doesn't work because when you add a label to inspect the time value, like so:

Code:
AddLabel(visible=yes, text=signalTime);

...and throw that script on, say, the EUR/USD, 1-minute chart, you'll see that signalTime changes with each passing minute, because the GetYYYYMMDD and GetTime are called each time the minute changes.

Essentially what I'm trying to do is store the current date and time into static variables as soon as the study is added to a chart. That way, I can monitor BarNumbers() from when I added the script to a chart, through to the current bar. I could do this by manually defining date and time variables as inputs, but I'd rather just have it as an automatic thing, where the date/times do...
The pseudo-code that I'd like to work is:

Code:
input signalDate = GetYYYYMMDD();
input signalTime = GetTime();

...however it says invalid statement for these inputs. You aren't allowed to use the Get functions for inputs. I'd like to have default values load into these inputs with the current date and time.

You CAN do:

Code:
def signalDate = GetYYYYMMDD();
def signalTime = GetTime();

...however those values don't remain constant, they change with time. You CAN also do:

Code:
input signalDate = 20220727;
input signalTime = 1300;

...however I'd like to NOT have to enter the current date and time manually every time.

Can we set a default value for date/time inputs to the current date/time, or how can I define them as def's and make sure they remain static/don't change once the script is added to a chart?

is this what you are looking for?
this will let the user enter a date and time.
if the date is 0 then it reads the current values for them.

Code:
input date = 0;
input time = 0;

def signalDate;
def signalTime;
if date == 0 then {
def signalDate = GetYYYYMMDD(); 
def signalTime = GetTime();
} else {
def signalDate = date; 
def signalTime = time;
}
 
Thanks for the reply. No this doesn't work because when you add a label to inspect the time value, like so:

Code:
AddLabel(visible=yes, text=signalTime);

...and throw that script on, say, the EUR/USD, 1-minute chart, you'll see that signalTime changes with each passing minute, because the GetYYYYMMDD and GetTime are called each time the minute changes.

Essentially what I'm trying to do is store the current date and time into static variables as soon as the study is added to a chart. That way, I can monitor BarNumbers() from when I added the script to a chart, through to the current bar. I could do this by manually defining date and time variables as inputs, but I'd rather just have it as an automatic thing, where the date/times do not change as time goes on.

Hope that helps?
 
Solution
Thanks for the reply. No this doesn't work because when you add a label to inspect the time value, like so:

Code:
AddLabel(visible=yes, text=signalTime);

...and throw that script on, say, the EUR/USD, 1-minute chart, you'll see that signalTime changes with each passing minute, because the GetYYYYMMDD and GetTime are called each time the minute changes.

Essentially what I'm trying to do is store the current date and time into static variables as soon as the study is added to a chart. That way, I can monitor BarNumbers() from when I added the script to a chart, through to the current bar. I could do this by manually defining date and time variables as inputs, but I'd rather just have it as an automatic thing, where the date/times do not change as time goes on.

Hope that helps?

can't do that.
there are no study file attributes , nothing for thinkscript to read, to tell when a study was created or modified ( like dos has).
 

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