Percent change from specific time in watchlist column


Category:
0
0

Pete, first thank for your guidance in this community you are extremely helpful.

I have a custom column that measures %change from open (below)

“PLOT ChangefromOpen = round(100 * (close / open – 1), 2);
AssignBackgroundColor(if ChangefromOpen > 0 then CreateColor(73, 122, 93) else if ChangefromOpen < 0 then CreateColor(129, 53, 57) else color.WHITE);”

This code is great for calculating change from open, however I was looking to calculate a change from 1030am. I tinkered with the code but its not working for me. I can change the time in the watchlist but calculations seem off and doesnt match my trading style like being able to trade from a certain time. thanks again for what you do 🙂

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on June 1, 2024 8:03 pm
95 views
0
Private answer

At this time (Saturday 6/1/24 @ 11 pm Eastern), Thinkorswim is having some issues displaying the data. So I was not able to test this on the custom watchlist column. But I did test it as a chart study and that worked. Please let me know if you find anything that doesn't seem right, once Thinkorswim gets their temporary outage cleared up.

On Thinkorswim, each candle is marked with the starting time of each bar. So when we reference a time of 10:00 it will be the bar the opens at that time. And this also is going to be impacted by the time frame you select for the watchlist column.

Which means you must select a time frame which evenly divides into the target time you have selected. For example, a target time of 10 am will work on a 1 min, 2, min, 5 min, 10 min and 30 min time frame. But it will not work if the time frame is set to 3 min, 4 min or 15 min time frame. That is not a complete list, but it should help yo understand the limitation of using this type of tool.

Here is the solution you requested:

input targetTime = 1000;
def targetBar = SecondsFromTime(targetTime) == 0;
rec targetPrice = if targetBar then open else if SecondsFromTime(targetTime) >= 0 then targetPrice[1] else Double.NaN;
plot percentChange = 100 * (close / targetPrice - 1);
AssignBackGroundColor(if percentChange > 0 then Color.GREEN else if percentChange < 0 then Color.RED else Color.CURRENT);

Please note I have this set to display "NaN" until the target time has been exceeded. Otherwise the value it would display prior to 10 am would be computed from the 10 am bar of the previous trading session.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on June 1, 2024 8:11 pm