You ever notice how some stocks do better on specific days of the week, times of the day or months of the year? This displays the average returns as a histogram.
For instance MSFT typically has above average returns in April and October and does poorly in December:
For instance MSFT typically has above average returns in April and October and does poorly in December:
Code:
declare lower;
# Get the current chart's aggregation period
def timeFrame = GetAggregationPeriod();
# Define the length (number of periods) for calculating the average return
input length = 20;
# Calculate the return for the current time frame
def return = close(period = timeFrame) / close(period = timeFrame)[1] - 1;
# Calculate the average return for the current time frame
def averageReturn = Average(return, length);
# Plot the return as a histogram
plot ReturnHistogram = return;
ReturnHistogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
# Assign colors to the histogram bars based on the return and average return
ReturnHistogram.AssignValueColor(
if return > 0 and AbsValue(return) > AbsValue(averageReturn) then Color.GREEN else
if return > 0 and AbsValue(return) < AbsValue(averageReturn) then Color.BLUE else
if return < 0 and AbsValue(return) > AbsValue(averageReturn) then Color.RED else
Color.ORANGE);