What's New

Custom Columns – Bollinger Band Excursion %

I often get requests for custom column codes for the MarketWatch Quote tab in TOS. Pro Member Dennis requested something to identify stocks that are outside of their Bollinger Bands and specifically the 15 minute, 60 minute, and daily timeframes. The exercise is fairly easy if you are familiar with the custom column coding technique so I thought I’d throw together a quick tutorial for reference.

1) On the MarketWatch Quote tab click the very nondescript gray circle next to Symbol and chose Customize…

2) In the Customize Quotes dialog chose one of your unused custom formulas and click on the script icon with the lock.

3) Add code for your custom column definition, change the name to something suitable, choose your aggregation period, and set any study parameters required. Clicking on one of the pre-defined study names in the code window will bring up its parameters in the section on the right. (I repeated this same process for the 60 and daily aggregation periods as well)

4) Add your new custom columns to your layout.

The custom columns are now in your Quote page. You can sort various columns by clicking in the header.

Here is the code snippet used in the custom column definition. The custom column expects a single plot and its value is returned into the column. You can apply a custom background or font color as well. In this case I have colored the background red when the close has exceeded the upper Bollinger Band and green when below.

def closeAbove = close-BollingerBandsSMA().UpperBand;
def closeBelow = BollingerBandsSMA().LowerBand-close;
plot result = if closeAbove > 0 then (closeAbove/close)*100 else if closeBelow>0 then (closeBelow/close)*100 else 0;
assignBackgroundColor(if closeAbove>0 then color.red else if closeBelow>0 then color.green else color.current);
result.assignValueColor(if closeAbove > 0 or closeBelow > 0 then color.black else color.current);
Posted in Tutorial | Tagged , , , | 8 Comments

Option Spread Viewer

My primary trading focus is options and the thinkorswim platform is outstanding in this regard. However, I wanted a way to graphically depict the value of an option spread on my charts. I was particularly interested in watching the weekly options in high beta stocks like AAPL. In general, I try to avoid trading options during expiration week and prefer to sell theta 3-4 weeks prior to expiration. However, after experimenting with weekly options over the past few weeks, I see some intriguing opportunities.

The Option Spread Viewer allows you to display option spreads of up to four different contracts or as few as one (i.e. a single naked contract). You must enter the individual contract symbols and a multiplier for each contract (e.g. .AAPL110225C360 with a multiplier of -1 means short one AAPL 360 call). There are three display modes: Contract Cost shows the aggregate contract cost for the spread; Spread Value shows the dollar value of the spread; Bar Percent Change shows the percent change in the spread from one chart bar to the next. The user has the option to display an entry price in the Contract Cost mode which will be plotted across the chart for reference. The image below shows three examples of the Option Spread Viewer in each of the modes.

This study will be published in the Pro Member’s update tomorrow 27 Feb. Good luck in your trading – Eric

Option Spread Viewer

Posted in Indicator | Tagged , , , | 23 Comments

Daily Moving Average – Intraday Chart

Extending the basic structure of the Pivot Point Moving Average, this study plots a daily moving average of a specified period on any intraday chart. The image shows the 50, 100, and 200 period daily moving averages on a four hour chart as well as ThinkScripter MultiStops using a chandelier stop.

Daily MA on Intraday Chart

# TS_DailyMA
# By Eric Purdy, ThinkScripter LLC
# http://www.thinkscripter.com
# thinkscripter@gmail.com
# Last Update 20 Feb 2011

input period = 50;
input displace = 0;
input display = {default linear, stairStep};

def MA = (fold i = 1 + displace to period + 1 + displace
with sum = 0 do sum + getValue(close(period="Day"),i,period+1))/period;
def newDay = if getDay() != getDay()[1] then 1 else 0;

plot DailyMovingAverage = if display==display.linear then if newDay then MA else double.nan else MA;
DailyMovingAverage.setDefaultColor(color.yellow);
DailyMovingAverage.setLineWeight(2);
DailyMovingAverage.enableApproximation();
Posted in Indicator | Tagged , , , | 9 Comments

MACD with Bollinger Bands

We had a request in the forum to duplicate an indicator found on other platforms that plots a standard MACD with a set of its own Bollinger Bands. Here it is in case you missed it in the forum.
-Eric

MACD with Bollinger Bands

# TS_MACD_BB
# By Eric Purdy, ThinkScripter LLC
# http://www.thinkscripter.com
# thinkscripter@gmail.com
# Last Update 07 Feb 2011

declare lower;

input price = close;
input BBlength = 10;
input BBNum_Dev = 1.0;
input MACDfastLength = 12;
input MACDslowLength = 26;
input MACDLength = 5;

def MACD_Data = MACD(fastLength=MACDfastLength, slowLength=MACDslowLength, MACDLength = MACDLength);

plot MACD_Dots = MACD_Data;
plot MACD_Line= MACD_Data;

plot BB_Upper = BollingerBandsSMA(price = MACD_Line, length=BBlength, Num_Dev_Dn=-BBNum_Dev, Num_Dev_Up=BBNum_Dev).UpperBand;
plot BB_Lower = BollingerBandsSMA(price = MACD_Line, length=BBlength, Num_Dev_Dn=-BBNum_Dev, Num_Dev_Up=BBNum_Dev).Lowerband;
plot BB_Midline = BollingerBandsSMA(price = MACD_Line, length=BBlength, Num_Dev_Dn=-BBNum_Dev, Num_Dev_Up=BBNum_Dev).MidLine;

BB_Upper.SetDefaultColor(color.gray);
BB_Lower.SetDefaultColor(color.gray);
BB_MidLine.SetDefaultColor(color.gray);
BB_MidLine.setStyle(curve.SHORT_DASH);

MACD_Line.setDefaultColor(color.white);

MACD_Dots.setStyle(curve.POINTS);
MACD_Dots.setLineWeight(2);
MACD_Dots.assignValueColor(if MACD_Line>MACD_line[1] then color.green else color.red);

plot zero = 0;
zero.assignValueColor(if MACD_line<0 then color.red else color.green);
zero.setLineWeight(2);
Posted in Indicator | Tagged , , , | 6 Comments

Pivot Point Moving Average

Reader Len asked for a moving average of the daily pivot point (H+L+C/3). This provided a great opportunity to demonstrate using the fold command to calculate a moving average from a higher timeframe. This method is extensible and you can let your scripting imaginations run wild with other possibilities. Good luck out there.
-Eric

Pivot Point Moving Average

# TS_PivotPointMovingAverage
# By Eric Purdy, ThinkScripter LLC
# http://www.thinkscripter.com
# thinkscripter@gmail.com
# Last Update 30 Jan 2011

input period = 3;
input displace = 0;

plot PivotPointMovingAverage = (fold i = 1 + displace
to period + 1 + displace
with sum = 0 do sum
+ getValue(hlc3(period="Day"),i,period+1))/period;

PivotPointMovingAverage.setDefaultColor(color.magenta);
PivotPointMovingAverage.setLineWeight(2);
Posted in Indicator | Tagged , , , , | 3 Comments