The track price in MarketSmith can be used to view a stock’s price in relation to various moving averages. The downside is that the information is not displayed directly on the chart, you must right click for each symbol to view the stats.

I’ve written thinkscript that will display the distance above or below either the 21-day exponential moving average or the 10-week simple moving average. If you are viewing a daily chart you’ll see the former, when on a weekly chart, the latter.

I’ve also added information that indicates the price for a specific percentage below the moving average. The percent below can be configured using the Inputs and Options dialog in thinkorswim.


Two examples follow, the first shows the output for a daily chart. On the left is the MarketSmith track information, on the right, the output of the script as shown in thinkorswim.

The next example shows similar information, this time on a weekly chart.


Installing the Moving Average Script

If you have thinkorswim installed, click here to install the moving average stats from the thinkorswim Sharing Center.

You can also copy/paste the link into thinkorswim’s Open Shared Item feature, the link is: https://tos.mx/lMEuYgC.


Moving Average Stats thinkscript Code

# Moving Average Stats
#
# Written by:  @JohnMuchow http://twitter.com/JohnMuchow
# Website:     PlayTheTrade.com
#
# v1.0

def aggregationPeriod = GetAggregationPeriod();
def daily = if (aggregationPeriod >= aggregationPeriod.DAY and aggregationPeriod < aggregationPeriod.WEEK, 1, 0);
def lastPrice = close(priceType = PriceType.LAST);
def _10WeekMovingAverage = MovingAverage(AverageType.Simple, close, 10);
def _21DayMovingAverage = MovingAverage(AverageType.Exponential, close, 21);
def percentDiff10Week = (lastPrice/_10WeekMovingAverage) - 1;
def percentDiff21Day = (lastPrice/_21DayMovingAverage) - 1;

input percentBelowMA = 1;

AddLabel(daily AND percentDiff21Day > 0, " " + GetSymbol() + " is " + AsPercent(AbsValue((lastPrice/_21DayMovingAverage) - 1)) + " above 21-day value of " +  Round(_21DayMovingAverage, 2) + " ", Color.GRAY);

AddLabel(daily AND percentDiff21Day <= 0, " " + GetSymbol() + " is " + AsPercent(AbsValue((lastPrice/_21DayMovingAverage) - 1)) + " below 21-day value of " +  Round(_21DayMovingAverage, 2) + " ", Color.GRAY);

AddLabel(daily, " " + AsPercent(percentBelowMA/100) + " stop below 21-day: " + Round(_21DayMovingAverage * (1 - percentBelowMA/100), 2) + " ", CreateColor(90, 122, 176));

AddLabel(!daily AND percentDiff10Week > 0, " " + GetSymbol() + " is " + AsPercent(AbsValue((lastPrice/_10WeekMovingAverage) - 1)) + " above 10-week value of " +  Round(_10WeekMovingAverage, 2)  + " ", Color.GRAY);

AddLabel(!daily AND percentDiff10Week <= 0, " " + GetSymbol() + " is " + AsPercent(AbsValue((lastPrice/_10WeekMovingAverage) - 1)) + " below 10-week value of " +  Round(_10WeekMovingAverage, 2)  + " ", Color.GRAY);

AddLabel(!daily, " " + AsPercent(percentBelowMA/100) + " stop below 10-week: " + Round(_10WeekMovingAverage * (1 - percentBelowMA/100), 2) + " ", CreateColor(90, 122, 176));