Earnings bar range break


Category:
0
0

Hi,
I was wondering if there is a way to record the open close of the bar on earnings day and then paint the following first bar some color after the earnings day bar which satisfies the following criteria

1) The bar is before the next earnings
2) the Open and Close of the bar is > open (if the bar is red) or close (if the bar is green) of the earnings bar
OR
3) The Open and Close of the bar is < open (if the bar is red) or close (if the bar is green) of the earnings bar

For example:
Earnings bar opened at 4 and closed at 5, so its a green bar
3 bars later the bar which was formed had an open of 6 and close of 7
or
3 bars later the bar which was formed had an open of 3 and close of 2

Thank You in Advance

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on October 23, 2019 1:07 pm
81 views
0
Private answer

I'll admit that I had to read this several times before I felt like I had a good grasp of what you have requested. So I won't be surprised of I got it wrong.

This solution is extremely complex. Far too complex for something I typically provide for no charge in the Q&A forum. Fortunately for you I had already done most of the grunt work for this in a previous post:

https://www.hahn-tech.com/ans/tos-earnings-scan-with-prior-earnings-percentage-move/

Be sure to check that post because you need to understand this solution is complicated by the fact that sometimes earnings are reported before market open and other time they are reported after market close. And the code needs to account for that.

Here is most of what you have requested. It paints every bar that qualifies instead of just the first. If you really need it to only paint the first qualifying bar, that will need to be submitted as a custom project request.

Here is the code I came up with. Screenshot below shows the result.

rec postEarningsOpen = if HasEarnings(EarningTime.BEFORE_MARKET)[1] then open[1] else if HasEarnings(EarningTime.AFTER_MARKET)[1] then open else postEarningsOpen[1];
rec postEarningsClose = if HasEarnings(EarningTime.BEFORE_MARKET)[1] then close[1] else if HasEarnings(EarningTime.AFTER_MARKET)[1] then close else postEarningsClose[1];
plot earningsOpen = postEarningsOpen;
plot earningsClose = postEarningsClose;
def aboveEarningsRange = open > Max(postEarningsOpen, postEarningsClose) and close > Max(postEarningsOpen, postEarningsClose);
def belowEarningsRange = open < Min(postEarningsOpen, postEarningsClose) and close < Min(postEarningsOpen, postEarningsClose); def candleAboveRange = close > open and aboveEarningsRange;
def candleBelowRange = close < open and belowEarningsRange;
AssignPriceColor(if candleAboveRange then Color.GREEN else if candleBelowRange then Color.RED else Color.GRAY);

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on October 23, 2019 2:27 pm
0
Thank you so much for taking the time to do this for me. I would have liked only the first bar but I understand it will take more time thus the custom request.  I am really really appreciative of your willingness to help. I do have one question this should work in all time frames correct? Also is there a way to paint the earnings bar some other color?
( at October 23, 2019 4:28 pm)
0
Also, I was wondering if it will make it easier if we don't count the earnings bar itself rather just the bar after the earnings to calculate the range? so the next bar after the earnings will be our anchor point and then look for the bars which are above or below that range
( at October 23, 2019 5:17 pm)
0
Only the daily time frame is supported because earnings events are a a corporate event that takes place on a day of the week and not during market hours. The colors can be adjusted through the code. The code is already using the bar AFTER the earnings.
( at October 23, 2019 8:31 pm)