Is there a way to color the background say 10 days before earnings up until earnings and then a different color 10 days after earnings.

Here you go. Bring up the settings window to change the number of days before / after earnings, whether to show the vertical lines and / or fill in the background colors, and to change the default colors for each component.

ThinkScript: settings pane

ThinkScript: settings pane

ThinkScript: chart without highlights

ThinkScript: chart without highlights

ThinkScript: chart with highlights

ThinkScript: chart with highlights

Hi Bob,
Can upcoming earnings date be plotted by this script?

Yes, just extend the time-axis to the right far enough to include future earnings dates.

ThinkScript: showing future earnings

ThinkScript: showing future earnings

ThinkScript: Chart Settings
ThinkScript: Chart Settings

This code is designed to work on a daily time frame.

# +--------------------------------------------------+
# |          Highlight days around earnings          |
# |                   Robert Payne                   |
# |           http://rrpayne.blogspot.com            |
# +--------------------------------------------------+
input daysBefore = 10;
input daysAfter = 10;

input showLines = yes;
input paintBackground = yes;

DefineGlobalColor("Before Earnings", Color.GREEN);
DefineGlobalColor("Earnings Release Date", Color.YELLOW);
DefineGlobalColor("After Earnings", Color.CYAN);
DefineGlobalColor("Fill Before", CreateColor(178, 216, 166));
DefineGlobalColor("Fill After", CreateColor(131, 191, 213));

AddVerticalLine(showLines and HasEarnings()[-daysBefore], Concat(daysBefore, " Days Before" ), GlobalColor("Before Earnings" ), Curve.FIRM);
AddVerticalLine(showLines and HasEarnings(), "Earnings!", GlobalColor("Earnings Release Date" ), Curve.FIRM);
AddVerticalLine(showLines and HasEarnings()[daysAfter], Concat(daysAfter, " Days After" ), GlobalColor("After Earnings" ), Curve.FIRM);

def before = Sum(HasEarnings(), daysBefore)[-daysBefore];
def after = Sum(HasEarnings(), daysAfter)[1];

def value1 = Double.Positive_Infinity;
def value2 = if paintBackground and before then Double.Negative_Infinity else Double.NaN;
def value3 = if paintBackground and after  then Double.Negative_Infinity else Double.NaN;

AddCloud(value1, value2, GlobalColor("Fill Before" ));
AddCloud(value1, value3, GlobalColor("Fill After" ));

Leave a Reply