How do I change the background color based on time of day


0
0

I find that time sneaks up on me during the day. The market acts differently near the close. I want to change the background color from 15:45 to 16:15 so that it is a visual reminder to me. How do I do that?

RESOLVED
Marked as spam
Posted by (Questions: 7, Answers: 11)
Asked on May 26, 2018 1:09 pm
366 views
1
Private answer

Here is the final version:

 

input alertPeriodStart = 1530;
input alertPeriodEnd = 1615;
input minimumRange = 1;
def startCounter = SecondsFromTime(alertPeriodStart);
def endCounter = SecondsTillTime(alertPeriodEnd);
def alertPeriod = if startCounter >= 0 and endCounter >= 0
then 1 else 0;

plot a = alertperiod;
AddCloud(if alertPeriod then Double.POSITIVE_INFINITY else Double.NaN, if alertPeriod then Double.NEGATIVE_INFINITY else Double.NaN, Color.YELLOW, Color.BLACK);

Marked as spam
Posted by (Questions: 7, Answers: 11)
Answered on May 27, 2018 3:56 pm
0

There is no need for the minimumrange input right?
I should have deleted that… It works though

( at May 27, 2018 5:26 pm)
0

That is correct. Nice work!

( at May 27, 2018 6:07 pm)
0
Private answer

Have a look at the code we provide with the video titled: Thinkorswim Overnight Range Alert

The chart study has two inputs, one for the start time and another for the end time. Those inputs are later used to define an alert period that is shaded. If you read the study you will find this is accomplished in 6 lines of code.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 26, 2018 1:18 pm
0

This is what I came up with but there is an error in the last line of code?
input alertPeriodStart = 1530;
input alertPeriodEnd = 1615;
input minimumRange = 1;
def startCounter = SecondsFromTime(alertPeriodStart);
def endCounter = SecondsTillTime(alertPeriodEnd);
def alertPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;

plot alertperiod = if alertPeriod >= minimumRange else no;

( at May 27, 2018 9:44 am)
0

Ok, good effort. Here is what you missed. Notice the comment within the code:
#———- Highlight the alert period

The line that immediately follows:
AddCloud(if okToPlot and alertPeriod then Double.POSITIVE_INFINITY else Double.NaN, if okToPlot and alertPeriod then Double.NEGATIVE_INFINITY else Double.NaN, Color.YELLOW, Color.BLACK);

I have no idea where the minimumRange came from. That must be something you felt was needed. I would be curious to understand your thoughts on that. Just delete it as well as this:
plot alertperiod = if alertPeriod >= minimumRange else no;

The reason there was an error on that line is that you had an incomplete if-then-else statement. Can you guess which component was missing?

( at May 27, 2018 10:02 am)