Will's StrategyDesk Formula Page

(May 2007)

Welcome to my page of Formulas for TDAmeritrade StrategyDesk! The following table contains formulas gleaned from reviewing Ameritrade's wimpy documentation (with corrections in some of their errors) and from personal experience. This list is a "work in progress," and will continue to evolve until/unless Ameritrade finally publishes a decent formula reference themselves.

I've discovered (as I'm sure you have) that not everything always works as "it seems it should" in this quirky program, so I can't make any guarantees as to how well these formulas perform. My disclaimer on my home page applies to anything I write: if I were so smart, I'd be rich.

At this point I've included only some of the core formulas, which of course you can "mix and match" by concatenating a bunch of them with "AND" and "OR" to suit your purpose. (Careful with those parentheses, Hoss). Also, to improve clarity, I've only written the following formulas using a single period and DAILY bars. They can be easily modified for different time frames, though. For example, you can screen for a 7ema on 30-minute bars by simply taking the "5ema on daily bars" formula and changing the "5" in the formula to a "7" and the "D" in the formula to a "30".

Please feel free to try out the formulas, and email me any suggestions, corrections, or new formulas you'd like added to the list.

Cheers and best of luck!


Basic Formulas:

NAME OF STUDY and basic formula which can be used in StrategyDesk COLUMNS Examples of use in StrategyDesk ALERTS and SCREENER Examples of use in StrategyDesk BACKTESTER

Description:
PRICE

Formula (last price):
Last

Formula (today's close):
Bar[Close,D]

Formula (today's high):
Bar[High,D]

Formula (yesterday's close):
Bar[Close,D,1]

Formula (high 3 days ago):
Bar[High,D,3]

Alert/Screener example:
Opening price is above 50

Formula:
Bar[Open,D] > 50

Backtesting examples:
Opening price is below Low of 3 bars ago

Formula:
Bar[Open,D] < Bar[Low,D,3]

***

Last price is above yesterday's High

Formula:
Last > Bar[High,D,1]

Description:
OPENING GAP above previous close

Formula:
Bar[Open,D] / Bar[Close,D,1]

*****

Description:
OPENING GAP above previous high

Formula:
Bar[Open,D] / Bar[High,D,1]

Alert/Screener/Backtesting example:
Opening Gap over 2% above previous close

Formula:
(Bar[Open,D] / Bar[Close,D,1]) > 1.02

Description:
10-PERIOD HIGH

Formula:
PriceRangeChannels[Upper,10,0,D]

*****

Description:
10-PERIOD LOW

Formula:
PriceRangeChannels[Lower,10,0,D]

Alert/Screener example:
Last Price is a 10-day high

Formula:
Last = PriceRangeChannels[Upper,10,0,D]

Backtesting example:
Closing Price is less than the low of the previous 10 days

Formula:
Bar[Close,D] < PriceRangeChannels[Lower,10,0,D,1]

Technical Analysis Formulas:

NAME OF STUDY and basic formula which can be used in StrategyDesk COLUMNS Examples of use in StrategyDesk ALERTS and SCREENER Examples of use in StrategyDesk BACKTESTER

Description:
SIMPLE MOVING AVERAGE (10-period example)

Formula:
MovingAverage[MA,Close,10,0,D]

Alert/Screener example:
Last Price is above the 10-day Simple Moving Average

Formula:
Last > MovingAverage[MA,Close,10,0,D]

Backtesting example:
Closing Price crosses 10-day Simple Moving Average from below ("UP" crossover)

Formula:
Bar[Close,D] > MovingAverage[MA,Close,10,0,D] AND Bar[Close,D,1] <= MovingAverage[MA,Close,10,0,D,1]

Description:
EXPONENTIAL MOVING AVERAGE (5-period example)

Formula:
ExpMovingAverage[EMA,Close,5,0,D]

Alert/Screener example:
Closing Price is below the 5-Day Exponential Moving Average

Formula:
Bar[Close,D] < ExpMovingAverage[EMA,Close,5,0,D]

Backtesting example:
5-day EMA crosses 10-day SMA from above ("DOWN" crossover)

Formula:
ExpMovingAverage[EMA,Close,5,0,D] < MovingAverage[MA,Close,10,0,D] AND ExpMovingAverage[EMA,Close,5,0,D,1] >= MovingAverage[MA,Close,10,0,D,1]

Description:
MACD HISTOGRAM (12,26,9)

Formula:
MACD[Diff,Close,12,26,9,D]

Alert/Screener example:
MACD Histogram (12,26,9) is above 0

Formula:
MACD[Diff,Close,12,26,9,D] > 0

Backtesting example:
MACD Histogram (12,26,9) crosses zero line from below ("UP" crossover)

Formula:
MACD[Diff,Close,12,26,9,D] < 0 AND MACD[Diff,Close,12,26,9,D,1] >= 0

Description:
RSI (14-period)

Formula:
RSI[RSI,14,D]

Alert/Screener example:
RSI (14) is above 70

Formula:
RSI[RSI,14,D] > 70

Backtesting example:
RSI crosses 30 from below ("UP" crossover)

Formula:
RSI[RSI,14,D] > 30 AND RSI[RSI,14,D,1]<=30

Description:
BOLLINGER BANDS (20-period SMA, 2 Standard Devations)

Formula:
BollingerBands[Lower,Close,20,2,D]

BollingerBands[Upper,Close,20,2,D]

Alert/Screener example:
Last Price is above Upper Bollinger Band

Formula:
Last > BollingerBands[Upper,Close,20,2,D]

Backtesting example:
Closing Price crosses Lower Bollinger Band from below ("UP" crossover)

Formula:
Bar[Close,D] > BollingerBands[Lower,Close,20,2,D] AND Bar[Close,D,1] <= BollingerBands[Lower,Close,20,2,D,1]

Description:
FAST STOCHASTIC "K" (14,3,3,5)

Formula:
Stochastic[StocK,14,3,3,5]

*****

Description:
SLOW STOCHASTIC "D" (14,3,3,5)

Formula:
Stochastic[StocD,14,3,3,5]

Alert/Screener example:
Fast Stochastic "K" is above 80

Formula:
Stochastic[StocK,14,3,3,60] > 80

Backtesting example:
Fast Stochastic "K" crosses Slow Stochastic "D" from below ("UP" crossover)

Formula:
Stochastic[StocK,14,3,3,5] > Stochastic[StocD,14,3,3,5] AND Stochastic[StocK,14,3,3,5,1] <= Stochastic[StocD,14,3,3,5,1]

Description:
COMMODITY CHANNEL INDEX

Formula:
CCI[CCI,20,D]

Alert/Screener example:
CCI is above 100

Formula:
CCI[CCI,20,D] > 100

Backtesting example:
CCI crosses -100 from below ("UP" crossover)

Formula:
CCI[CCI,20,D] > -100 AND CCI[CCI,20,D,1] <= -100

Time-of-Day Formulas:

NAME OF STUDY and basic formula which can be used in StrategyDesk COLUMNS Examples of use in StrategyDesk ALERTS and SCREENER Examples of use in StrategyDesk BACKTESTER

Description:
HIGH OF FIRST 90 MINUTES

Formula:
Bar[High,90]*(Bar[Hour,90] = 9) + Bar[High,90,1]*(Bar[Hour,90] = 11) + Bar[High,90,2]*(Bar[Hour,90] = 12) + Bar[High,90,3]*(Bar[Hour,90] = 14) + Bar[High,90,4]*(Bar[Hour,90] = 15)

Alert/Screener example:
Last price is above high of the first 90 minutes

Formula:
Last > Bar[High,90]*(Bar[Hour,90] = 9) + Bar[High,90,1]*(Bar[Hour,90] = 11) + Bar[High,90,2]*(Bar[Hour,90] = 12) + Bar[High,90,3]*(Bar[Hour,90] = 14) + Bar[High,90,4]*(Bar[Hour,90] = 15)

Backtesting examples:
Price / high of first 90 minutes CROSSOVER

Formula:
Bar[Close,90,1] < (Bar[High,90]*(Bar[Hour,90] = 9) + Bar[High,90,1]*(Bar[Hour,90] = 11) + Bar[High,90,2]*(Bar[Hour,90] = 12) + Bar[High,90,3]*(Bar[Hour,90] = 14) + Bar[High,90,4]*(Bar[Hour,90] = 15)) AND Bar[Close,90] > (Bar[High,90]*(Bar[Hour,90] = 9) + Bar[High,90,1]*(Bar[Hour,90] = 11) + Bar[High,90,2]*(Bar[Hour,90] = 12) + Bar[High,90,3]*(Bar[Hour,90] = 14) + Bar[High,90,4]*(Bar[Hour,90] = 15))

Description:
HIGH OF FIRST HOUR

Formula:
(Bar[Hour,60] = 9) * Bar[High,60] + (Bar[Hour,60] = 10) * Bar[High,60,1] + (Bar[Hour,60] = 11) * Bar[High,60,2] + (Bar[Hour,60] = 12) * Bar[High,60,3] + (Bar[Hour,60] = 13) * Bar[High,60,4] + (Bar[Hour,60] = 14) * Bar[High,60,5] + (Bar[Hour,60] = 15) * Bar[High,60,6]

Alert/Screener example:
Last price is above the first hour's high

Formula:
Last > (Bar[Hour,60] = 9) * Bar[High,60] + (Bar[Hour,60] = 10) * Bar[High,60,1] + (Bar[Hour,60] = 11) * Bar[High,60,2] + (Bar[Hour,60] = 12) * Bar[High,60,3] + (Bar[Hour,60] = 13) * Bar[High,60,4] + (Bar[Hour,60] = 14) * Bar[High,60,5] + (Bar[Hour,60] = 15) * Bar[High,60,6]

Backtesting examples:
Price CROSSES OVER first hour's high

Formula:
Bar[Close,60,1] < ((Bar[Hour,60] = 9) * Bar[High,60] + (Bar[Hour,60] = 10) * Bar[High,60,1] + (Bar[Hour,60] = 11) * Bar[High,60,2] + (Bar[Hour,60] = 12) * Bar[High,60,3] + (Bar[Hour,60] = 13) * Bar[High,60,4] + (Bar[Hour,60] = 14) * Bar[High,60,5] + (Bar[Hour,60] = 15) * Bar[High,60,6]) AND Bar[Close,60] > ((Bar[Hour,60] = 9) * Bar[High,60] + (Bar[Hour,60] = 10) * Bar[High,60,1] + (Bar[Hour,60] = 11) * Bar[High,60,2] + (Bar[Hour,60] = 12) * Bar[High,60,3] + (Bar[Hour,60] = 13) * Bar[High,60,4] + (Bar[Hour,60] = 14) * Bar[High,60,5] + (Bar[Hour,60] = 15) * Bar[High,60,6])

Description:
HIGH OF FIRST 30 MINUTES

Thanks to BNJ for this formula!

Formula:
Bar[High,30] * (Bar[Hour,30]=9) * (Bar[Minute,30]=30) + Bar[High,30,1] * (Bar[Hour,30]=10) * (Bar[Minute,30]=0) + Bar[High,30,2] * (Bar[Hour,30]=10) * (Bar[Minute,30]=30) + Bar[High,30,3] * (Bar[Hour,30]=11) * (Bar[Minute,30]=0) + Bar[High,30,4] * (Bar[Hour,30]=11) * (Bar[Minute,30]=30) + Bar[High,30,5] * (Bar[Hour,30]=12) * (Bar[Minute,30]=0) + Bar[High,30,6] * (Bar[Hour,30]=12) * (Bar[Minute,30]=30) + Bar[High,30,7] * (Bar[Hour,30]=13) * (Bar[Minute,30]=0) + Bar[High,30,8] * (Bar[Hour,30]=13) * (Bar[Minute,30]=30) + Bar[High,30,9] * (Bar[Hour,30]=14) * (Bar[Minute,30]=0) + Bar[High,30,10] * (Bar[Hour,30]=14) * (Bar[Minute,30]=30) + Bar[High,30,11] * (Bar[Hour,30]=15) * (Bar[Minute,30]=0) + Bar[High,30,12] * (Bar[Hour,30]=15) * (Bar[Minute,30]=30)

Alert/Screener example:

See above examples of how to use this type of formula in screeners and backtesting

Candlestick Formulas:

Description:
"DOJI" CANDLESTICK (open and close within 0.1% of each other)

Note: I arbitrarily chose the 0.1% parameter; StrategyDesk uses a simple "equals" statement, but very few dojis actually have an open and close "equal" to the thousandth of a penny!

Formula:
(Bar[Open,D] - Bar[Close,D]) / Bar[Open,D] < 0.001 AND (Bar[Open,D] - Bar[Close,D]) / Bar[Open,D] > -0.001

Description:
"HAMMER" CANDLESTICK (open-close range less than 1/3 of hi-lo range, upper wick less than 10% of day's range)

This is a great example of how mathematically expressing something as simple as a Hammer can get really complicated really quickly... not quite as easy as eyeballing one on a chart!

Formula:
((((Bar[Open,D]-Bar[Close,D])>0)*(Bar[Open,D]-Bar[Close,D]) + ((Bar[Close,D]-Bar[Open,D])>0)*(Bar[Close,D]-Bar[Open,D])) / (Bar[High,D] - Bar[Low,D]) < 0.33) AND (((Bar[High,D] - Bar[Open,D]) / (Bar[High,D] - Bar[Low,D])) < 0.1 OR ((Bar[High,D] - Bar[Close,D]) / (Bar[High,D] - Bar[Low,D])) <0.1)

Miscellaneous Formulas:

NAME OF STUDY and basic formula which can be used in StrategyDesk COLUMNS Examples of use in StrategyDesk ALERTS and SCREENER Examples of use in StrategyDesk BACKTESTER

Description:
PROFITABILITY OF TRADE (percent)

Note: There is no documentation of exactly how StrategyDesk determines "Entry Price," so this formula may only be useful as an EXIT formula in the BACKTESTER.

Formula:
(Bar[Close,D] - EntryPrice) * 100 / EntryPrice

Alert/Screener example:
Profit is greater than 3 %

Formula:
(Bar[Close,D] - EntryPrice) * 100 / EntryPrice >= 3

Backtesting example:
Loss is greater than 1% (e.g. profit is less than -1%); could be used as trailing stop, for example

Formula:
(Bar[Close,D] - EntryPrice) * 100 / EntryPrice <= -1

Description:
ELAPSED TIME SINCE TRADE ENTRY

Note: There is no documentation of exactly how StrategyDesk determines "Entry Price," so this formula may only be useful as an EXIT formula in the BACKTESTER.

Formula:
(only have screen/backtest formula)

Alert/Screener/Backtesting example:
Three Days have elapsed since trade entry

Formula:
Bar[Close,D,3] = EntryPrice