Small Dog Moving Average Indicator for ThinkorSwim

Shinthus

Shinthus

Member
VIP
I found this in the almighty ThinkScript_Cloud under 03. Technical Analysis > Trend. This was written by a gentleman named Allen Everhart. No idea who he is but he made this and I put it on my chart to test it out. I tested this using a swing trading mindset.


Steep sloping MA is red, flat or close to flat is orange. "Hot" price movement in either direction is given purple triangles as seen below. I have more testing to do, but it seems scarily accurate to the point where I'm personally going to throw money in the direction of the trend in the form of an OTM cheapo call/put once I'm alerted to purple triangles appearing. This does repaint; since it can repaint, I recommend entering your position after a set amount of time (maybe 1H) or price action after the MA changes colors or purple triangles show up. It might even be best to enter 1min before market close to confirm it won't repaint and fake you out. This does not do well for intraday strategies, as there are very few signals. But if you're busy like me, this could be a great thing to swing with.

The purple triangles can appear any time during the day so it allows us to buy in, set stop loss, and "forget." The only thing we need to do is monitor our position for a profit exit. I'm going to be pressed for time for the next few days so please test it and see if it's great or just ok. I will bring updates to this thread as I test it.

Please manage your risk accordingly.

thinkScript Code

Code:
plot Data = close;
#########################

# sdi_ma: Small Dog Investor Moving Average

#

#hint: Displays a moving average with some additional signals. In the default configuration, when the MA is trending, as defined by 30 consecutive up/down moves, OR the MA is more than 5% away from the MA 30 bars prior then the MA appears in red. When the moving average is nontrending and within 5% of the value 30 bars prior then the MA appears in orange. When price is more than 10% away from the MA, the MA line is decorated with hot pink triangles. In the right extension we show a straight line projection taken from the last two bars. Version: 1.1

#

# source: smalldoginvestor.blogspot.com

# author: allen everhart 8/4/2011

# revised: 8/21/2011 added price data series selection.

#

# copylefts reserved. This is free software. That means you are free

# to use or modify it for your own usage but not for resale.

# Help me get the word out about my blog by keeping this header

# in place. 



#hint price: Choose data series to average over.

input price = close;

#def price = close;

#hint type: Choose between Simple and Exponential Moving Average.

input type = { default EXP, SMP } ;

#hint length: Number of bars in moving average.

input length = 30 ;

#hint flatPct: Main criteria for color-coded trend changes.

input flatPct = 5.0 ;

#hint compLength: Number of consecutive up/down bars to use as the secondary criteria for color-coded trend changes.

input compLength = 30 ;

#hint hotPct: Criteria for the hot decoration.

input hotPct = 10.0 ;



def ma =

  if type == type.SMP then

    simpleMovingAvg(price, length)

  else

    movAvgExponential(price, length)

;

rec maUpBars =

  if ma > ma[1] then

    maUpBars[1] + 1

  else if ma == ma[1] then

    maUpBars[1]

  else

    0

;

#plot up = maUpBars ; # diagnostics

rec maDnBars =

  if ma < ma[1] then

    maDnBars [1] + 1

  else if ma == ma[1] then

    maDnBars[1]

  else

    0

;

#plot dn = maDnBars ; # diagnostics

plot steep =

if AbsValue(100 * ((ma / ma[compLength]) - 1)) >= flatPct then

    ma

else if maUpBars >= compLength then

    ma

else if maDnBars >= compLength then

    ma

else

    double.NaN

;

steep.SetDefaultColor( color.RED);

steep.SetLineWeight(2) ;

plot flat =

if AbsValue(100 * ((ma / ma[compLength]) - 1)) < flatPct then

    ma

else if maUpBars < compLength then

    ma

else if maDnBars < compLength then

    ma

else

    double.NaN

;

flat.SetDefaultColor( color.ORANGE);

flat.SetLineWeight(2) ;



#plot pct =100 * ((ma / ma[compLength]) - 1);

#plot bkma =  ma[compLength] ;

plot hot =

if AbsValue( 100 * ((price / ma) - 1) ) > hotPct then

    ma

else

    double.NaN

;

hot.setDefaultColor( color.MAGENTA);

hot.setPaintingStrategy(paintingStrategy.LINE_VS_TRIANGLES);

rec slope =

  if isnaN(close) and !isnaN(close[1]) then

    ma[1]-ma[2]

  else if isnaN(close) and isnaN(close[1]) then

    slope[1]

  else

    double.NaN

;

rec extrec =

  if !isnaN(slope) and isnaN(slope[1]) then

    ma[1]+slope

  else if !isnaN(slope) then

    extrec[1]+ slope

  else

    double.NaN

;

plot ext = extrec ;

ext.setDefaultColor(color.RED);

ext.setStyle( curve.SHORT_DASH);

#end
 
Last edited:
markos

markos

Well-known member
VIP
Warehouse
@Shinthus I am happy to see that you are finding your way all around our Universe of Thinkscript, located in the Tutorial Section of this site. (y)
Mr. Everhart is known as the "small dog investor", his study codes will most likely have SDI in the header.
Very nice find, Let the testing begin!
 
Shinthus

Shinthus

Member
VIP
Update: It doesn't seem to work well with stop losses. I'm thinking about just buying cheap 2 week exp, OTM options and YOLOing each trade to see if there are more gains than losses. Also sucks for intraday. There are barely any signals for 5m, 15m, and 30 minute charts.

If it's possible to set up an automatic paper trading strat with this, please let me know.

Will report back.
 
Last edited:
Shinthus

Shinthus

Member
VIP
Update: Ok I realized it can also be used as a confirmation when you are already in a position. Depending on the situation, it may warrant an additional position on top of the one you have. For example, if you used other indicators to get into a position and you are already winning, you may be able to add to your position if the purple triangles show up.
 
Shinthus

Shinthus

Member
VIP
I just got a seemingly brilliant idea. Have one chart open with daily timeframe. Have the other chart 5m or some intraday interval. When the purple triangle shows up on the daily chart in the middle of a trend, check the intraday chart for a pullback in the opposite direction of the trend. Using help of RSI L and Market Mover or the Zigzag reversal (or whatever you like), wait until the pullback seems over and take a weekly ATM option in the direction of the trend!

Let me know it this was clear or not. It sounds like an awesome strategy. Basically, days that have a purple triangle on them are really really good day trading days. Say the daily trend is violently DOWN. The triangle appears on the daily, and you wait until a small uptrend happens on the 5m chart and possibly look for oversold signal on RSI or TMO/stochastics. Then buy puts as soon as you start to see a decline!
 
markos

markos

Well-known member
VIP
Warehouse
Just letting you know that it sounded clear to me. Very interesting thought, checking multiple time frames. Obviously, you would consult at least a full year daily chart to be sure of trend. Good trading & let us know what you've found!
 
H

horserider

Well-known member
VIP
Warehouse
Had this indicator on one of my charts for some time. I have found no use for it other than as a 30 EMA which is useful for checking if price breaks or respects the line. It needs a highly volatile stock to show triangles.
 
Thread starter Similar threads Forum Replies Date
BenTen Strategies 8

Top