How to create a watch list that calculates %change in last 5 minutes


Category:
0
0

Hello Hahn,

For traders who are looking for very quick moves in stock prices I wanted to know if you could provide a watchlist code for Percent change in last 5 minutes.

In terms of coloring If the percent change is greater than 7%, in the last 5 minute window color the percentage text will turn red and the background will turn yellow.

Best

Marked as spam
Posted by (Questions: 22, Answers: 63)
Asked on May 14, 2018 12:16 pm
4060 views
0
If possible this needs to be a rolling 5 minute window. The displayed output percentage of this code should trigger off of the reference price which is the average price over the last 5 minutes
( at May 14, 2018 12:22 pm)
0
Private answer

Well we can write the code to do the job but you will find there is approximately 3-5 min time delay for watchlist updates. There is no point in trying to do the “rolling 5 min” and averaging. The value will be old, stale and useless. If this is mission critical I suggest you move to a more advanced platform.

So we just do a few lines of code that checks current close to previous close. Then you apply that to a 5 min column in a watchlist. The data will still be 3-5 minutes old. Nothing can be done to address that.

plot data = 100 * (close / close[1] - 1);
data.AssignValueColor(if data > 7.0 then Color.RED else Color.CURRENT);
AssignBackgroundColor(if data > 7.0 then Color.YELLOW else Color.CURRENT);

This second piece of code appends a percent sign to the end of the value. This allows applies a rounding function to reduce the value to one decimal place. If you want to add/remove decimals you will change the numeric value in this section of code: Round(data, 1).

def data = 100 * (close / close[1] - 1);
AddLabel(yes, Concat(Round(data, 1), "%"), if data > 7.0 then Color.RED else Color.CURRENT);
AssignBackgroundColor(if data > 7.0 then Color.YELLOW else Color.CURRENT);

Marked as spam
Posted by (Questions: 37, Answers: 4117)
Answered on May 14, 2018 2:02 pm
0
The rolling 5 minutes is critical and averaging of the 5-minute prices are critical !!!! Also, why not use the previous bars close to the current bars current price (last)? The reason is because I have found a neat workaround in thinkorswim for the lagging 3-5 minute updates and make the watchlist items realtime Please let me know if the rolling 5-minute window for the average price is possible. Best
( at May 14, 2018 2:42 pm)
0

Also, the code did not work and would not save. It says invalid statement.

Best

( at May 14, 2018 2:47 pm)
0

The errors have been corrected in the answer and the code will now work correctly. In Thinkscript, the close() function takes three price types. Last, Ask, Bid and Mark. The default value is Last. So if you feel you have found a workaround by using Last instead of Close then this code does exactly that. But I am certain this does not escape the lagging updates.

( at May 14, 2018 3:25 pm)
0

We should talk about how I found a work around to the lagging updates on day soon. Its simpler than we ever thought lol.

I have been on the phone with TOS weekly just to get an ETA on what they are doing about this.

I will test code now ? thanks

( at May 14, 2018 3:31 pm)
0

The code works so far, i haven’t made any changes based on what has been posted. I just wanted to ask if this can be displayed as a percent? 

( at May 14, 2018 3:36 pm)
0

You mean add a percent sign at the end of the value? Yes, but then you loose the ability to sort numerically.

( at May 14, 2018 3:53 pm)
0

that’s fine, yes add the percent sign.

I will be using another column to sort by anyway.

Just some context, I am trying to use this the code to indicate when the current moving price is growing rapidly over a very small period of time. I will be testing this some more live tomorrow. ?

( at May 14, 2018 3:59 pm)
0

I updated my answer to include a version of the code to display the percent sign.

( at May 14, 2018 4:30 pm)
0

Very nice, cant wait to test this during the market open tomorrow.

Just a quick question, what does the close() function even mean lol?
In this differnt from the close price or is this programming jargon?

I just want to read this line plot data = 100 * (close / close[1] – 1);

in human terms lol

great work !!!!!!

( at May 14, 2018 4:43 pm)
0

The technical answer is that “close” is one of many “fundamental types”. Fundamental meaning, fundamental data. Open, High, Low, Close, Volume. These are all fundamental data types. You see them all and full details here: http://toslc.thinkorswim.com/center/reference/thinkScript/Constants/FundamentalType.html

The english version of that line of code: “divide the current value of close by it’s previous value, subtract 1 from the result and multiply that by 100 to move the decimal point to the left.”

( at May 14, 2018 5:23 pm)
0
Well since determining the close price is “slower” aka takes longer to be determined than the last price on a moving chart. Is there a way we can modify the code to read “divide the current value of LAST by the previous bars close value, subtract 1 from the result and multiply that by 100 to move the decimal point to the left.” If last isnt an option, how about using the current bars high or even MARK Price (Mark is the mid point between the bid and the ask.)? So maybe the code can also read “divide the current value of HIGH by THE PRVIOUS BARS CLOSE, subtract 1 from the result and multiply that by 100 to move the decimal point to the left.” “divide the current value of mark by THE PREVIOUS BARS close VALUE, subtract 1 from the result and multiply that by 100 to move the decimal point to the left.”
( at May 14, 2018 5:50 pm)
0

Before I even read past this line: “Is there a way we can modify the code to read divide the current value of LAST by the previous bars close value,”

I have already explained this. Last is the default price type of the close fundamental data. Did you read the link I provided? Did you see Last anywhere in that list? No, you did not. Because from within Thinkscript, Close is one and the same as Last.

( at May 14, 2018 6:07 pm)
0

Yes, I read it, sorry I am still new to the coding language.

So what is the impact if the code said this

“divide the current value of HIGH by THE PREVIOUS BARS CLOSE, subtract 1 from the result and multiply that by 100 to move the decimal point to the left.” “divide the current value of mark by THE PREVIOUS BARS close VALUE, subtract 1 from the result and multiply that by 100 to move the decimal point to the left.”

( at May 14, 2018 6:14 pm)
0

‘Close price – The close is the last price traded during the candlestick, indicated by either the top or bottom of the body.”

my thinking was flawed as to what close was /…. thank you

( at May 14, 2018 7:14 pm)
0

I think you go it, yeah. As I said. Within Thinkscript language, close and last are one and the same. I understand they are different things when selecting standard fields in a watchllst. But they are identical from within the Thinkscript language.

( at May 14, 2018 7:17 pm)