Plot % change from open between 9:30am-9:45am


Category:
0
0

Hey Pete, I need helping modding some code below. How do I lock the bubble plot so it only shows from the 9:30 am candle to the 9:45 am candle. After 9:45 if the price keeps making a new high, I don’t want this script to record or any new values Right now its plotting all day. Thanks

 

 

 

def dailyOpen = open(period = “DAY”);

def afterOpen = secondsFromTime(930) >= 0;

def isToday = GetDay() == GetLastDay();

 

def rthHigh = if isToday and afterOpen and high > rthHigh[1] then high else rthHigh[1];

plot plotHigh = HighestAll(rthHigh);

plotHigh.Hide();

 

#percent change from open to current bar

def openPctChange = Round(((high – dailyOpen) / dailyOpen) * 100, 2);

 

 

#count the number of times the high of day is reached

def highReached = isToday and afterOpen and high == plotHigh;

def highCount = if highReached then highCount[1] + 1 else highCount[1];

 

AddChartBubble(highReached, high, openPctChange + “%”, if highCount > 1 and openPctChange > 60 then Color.RED else Color.YELLOW, yes);

Marked as spam
Posted by (Questions: 6, Answers: 4)
Asked on April 12, 2020 2:27 pm
182 views
0
Private answer

I can point you in the right direction and we'll let you see if you can incorporate this into your code to get the job done:

input startTime = 930;
input endTime = 944;
def targetTimeSpan = SecondsFromTime(startTime) >= 0 and SecondsTillTime(endTime) >= 0;

On a 1 min chart, this will give you a variable named targetTimeSpan that is true for every bar within your specified time span. Each bar on the chart is marked with the start time. So on a 1 min chart we need to decrement the endTime input by 1 minute. If you apply to some other time frame you will need to adjust the user input named "endTime" to match the time stamp on the last bar you want included in the computations.

If you want a variable that will be true on the very first bar of this time span you can add the following to the code above:

def targetStartTime = targetTimeSpan and !targetTimeSpan[1];

These two variables should give you the tools needed to compute the remainder of your study.

HINT: Create a custom chart study using those lines of code and add plot this on a lower subgraph to see how they display their true/false values in graphical form. Here is the code, set to plot those two variable on a lower subgraph:

declare lower;
input startTime = 930;
input endTime = 944;
plot targetTimeSpan = SecondsFromTime(startTime) >= 0 and SecondsTillTime(endTime) >= 0;
plot targetStartTime = targetTimeSpan and !targetTimeSpan[1];

Edit: A comment was added asking for some clarification on how to prevent the chart bubble from plotting outside the selected time frame

For the AddChartBubble() statement the first parameter sets the "time condition". Details here:

https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AddChartBubble

So if you wanted a chart bubble to display only on candles which fall within your selected time frame you would add the following line of code to the section of code I provided above:

AddChartBubble(targetTimeSpan, high, "Test", Color.WHITE, yes);

And if you wanted to include another requirement to that "time condition" so that the chart bubble only plots on the candles which fall within the selected time span AND only on those candles in which your variable named "highReached" is true:

AddChartBubble(targetTimeSpan and highReached, high, "High Reached", Color.WHITE, yes);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on April 12, 2020 7:11 pm
0
Thank you for the help Pete but from trying this out I could not get the bubble to stop plotting past the 9:45 candle. Can you please post the complete solution so I can compare the results. Thanks.
( at April 12, 2020 8:42 pm)
0
I have updated my answer to include the additional examples you requested.
( at April 13, 2020 7:25 am)