♥ 0 |
Hello, How would I create a custom column that displays the number of consecutive increasing earnings or decreasing earnings? I was thinking the number of consecutive increasing earnings would be displayed as a positive number and the number of consecutive decreasing earnings would be displayed as a negative number. I thought it was going to be easy, but I keep running into challenges. Thanks! -Charles
Marked as spam
|
Private answer
#This custom column displays the number of consecutive increasing earnings or decreasing earnings looking back four earnings reports #Feel free to make this code more elegent and look back further then four earnings reports def ActualEarnings1 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, -1)); def ActualEarnings2 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, -2)); def ActualEarnings3 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, -3)); def ActualEarnings4 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, -4)); def ConsecIncDec = if ActualEarnings1 > ActualEarnings2 then (if ActualEarnings2 > ActualEarnings3 then (if ActualEarnings3 > ActualEarnings4 then 3 else 2) else 1) else (if ActualEarnings1 < ActualEarnings2 then (if ActualEarnings2 < ActualEarnings3 then (if ActualEarnings3 < ActualEarnings4 then -3 else -2) else -1) else 0); plot x = ConSecIncDec; AssignBackgroundColor(if x is greater than 0 then Color.BLUE else (if x is less than 0 then Color.RED else Color.GRAY)); Marked as spam
|
|||||||||||
Private answer
After receiving a bit more detail in the comments section above I can provide a solution to this request. SetupIt is crucial everyone understand that this solution requires the custom column to be set to a daily time frame or higher. Furthermore, the time frame selected will directly impact the amount of historical data that can be included. For example a daily time frame will include only a signal year of earnings data while a weekly time frame will include 3 years of earnings data. Full details here: https://toslc.thinkorswim.com/center/howToTos/thinkManual/MarketWatch/Quotes/customquotes IMPORTANT NOTE: Despite this code working for the vast majority of stocks I tested there are some stocks that do not display accurate values. Case in point is the ticker symbol HES set to a weekly time frame. The code is 100% accurate when added to a custom chart study and plotted on the lower subgraph of the chart. However in the custom watchlist column the values are not computed accurately. There is no explanation for this. I suspect this is a bug in the platform that will need to be addressed by one of the developers at TD Ameritrade.The ToolsThe main tools we are going to use are a function named GetActualEarnings() and we are going to use recursion to count the number of instances. You can get all the details about that built-in function here: Recursion is when we create a variable and assign its current value based on its previous values. We prefer that recursive variables are defined using the keyword "rec" instead of "def" so that we can easily identify where recursion is being applied. The SpecificationsBefore we present the solution it's important to examine your specification and understand how to implement this. You requested a custom watchlist column that will display both the number of negative earnings as well as the number of positive earnings. Well we know that each column in a watchlist can only display a single values. So I will be splitting this into two separate columns. It is possible to take these values and concatenate them into a text string and thereby display both values in the same column. However doing so will remove the ability to sort by that column so for most applications I don't believe that is the best solution. SolutionSo here is the code to display the number of positive earnings reports:
And here is the code to display the number of negative earnings reports:
Marked as spam
|
Please log in to post questions.