TOS %Change custom watchlist column


Category:
0
0

I was looking for a way to create a custom column in the TOS watchlist that would give me the % change from the current days open to the current day market price. TOS has a %Change column but it calculates from the previous days close. I found a question by Two Way Trader about a month ago that you answered in the TOS watchlist forum . I was able to modify the code you gave him (or her, not sure) to achieve the results I was looking for. Not completely sure how the code works but it does. I also added some code to give color to the back ground and numbers. Please see below the code I came up with. If you would be kind enough I would like to hear an explanation to how my changes made this work and/or suggest a better code solution? Thanks.

def startTime = 0900;

def regularSessionstart = SecondsTillTime(startTime) == 0;

rec dailyOpen = if regularSessionstart then close else dailyOpen[1];

plot percentChange = 100 * (dailyOpen / open – 1);

PercentChange. AssignValueColor(if percentChange > 0 then Color.GREEN else if percentChange < 0 then Color.RED else Color.BLACK);

Marked as spam
Posted by (Questions: 1, Answers: 2)
Asked on April 28, 2020 10:22 am
723 views
0
Private answer

If this is the previous solution you are referring to....

https://www.hahn-tech.com/ans/show-change-since-open-in-column/

Then your solution does not exactly do the same thing. The default value you set for the "startTime" input is not the regular session open. That would be 930 instead of 900. But perhaps you had a reason to use a different time than the regular session open.

In regards to the assignment of color, that seems be applied correctly.

In the solution I linked at the top if my response, the solution was to apply a daily time frame to the watchlist column. Which does not require the use of a session start time. So if you wanted to apply the color changes to my previous solution, it would look like this:

plot data = Round(100 * (close / open - 1), 1);
data.AssignValueColor(if data > 0 then Color.GREEN else if data < 0 then Color.RED else Color.BLACK);

Set that to a daily time frame it you are automatically assured of getting the open of the regular session.

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on April 28, 2020 1:01 pm
0
Thanks Pete!
( at April 29, 2020 2:46 pm)
0
Just a quick update to acknowledge that I could have provided a much more helpful response to this question. I must have been in a hurry in my original response and did not realize you were asking for feedback on your modifications. I hope my updated response will better serve your request.
( at September 2, 2023 8:57 am)