1. Home
  2. ThinkorSwim Indicators
  3. nextSignals Trend Following System for ThinkorSwim

nextSignals Trend Following System for ThinkorSwim

nextSignals, otherwise known as @stephenharlinmd on Twitter, is a prominent trader in the FinTwit community.

He recently disseminated what he described as a “Simple and Effective Trend Following System.”

The paper also includes nextSignals’ Trend Following indicator for ThinkorSwim.

Before we get to the source code, let’s review some of the critical components that Stephen uttered in his work.

Brief Introduction

This document provides a simple approach to trading off of a Thinkorswim study that I have used to manage my own investment portfolios, for years.

This is a mechanical time-series momentum strategy that combines trend following and mean reversion.

…it’s always best to monitor external market forces and keep abreast of events that might forewarn of a shock.

Entry Decisions

The system is a breakout system for short- and medium-term trades.

Trades signaled and initiated in a 1-day chart represent new, unqualified breakouts. If trend continues into the intermediate term, this will be confirmed in a 1-week chart.

There are 3 moving parts to this system:
1. an adaptive moving average (AMA) used for “break points” (closes above/below AMA)
2. a 20-day slope indicator
3. a 7-day slope indicator

Trend following systems can be used to trade any instrument … the underlying itself, options on the underlying, or futures contracts.

Exit Principles

Exits have a greater bearing on profitability than entries … only exceeded by position sizing. (See key points on Kelly position sizing below.)

Exit when you have more to lose than you have to gain. “Cut your losses early and let your profits run” is extremely hard to accomplish.

Expect to be wrong. Predetermine the level at which you will cut the loss “mercilessly” and unemotionally move on.

Only 30% of a stock’s price movement is idiosyncratic – i.e. not related to movement within it’s index. If the correlation to the index is high – holding the position in the face of a declining index is unnecessarily risky.

Trend Following Indicator for ThinkorSwim

# Original source: https://www.dropbox.com/s/95dirjyay9vff2v/Trend%20Following%20System.pdf?dl=0
## Comments
## Identify Last
def lastBar = BarNumber();
def current = HighestAll(If(IsNaN(close), 0, lastBar));
## Chop Thinkorswim's MovAvgAdaptive
input mode = {default KAMA, AMA};
def direction;
def volatility;
def ER;
switch (mode) {
case KAMA:
direction = AbsValue(close - close[10]);
volatility = Sum(AbsValue(close - close[1]), 10);
ER = if volatility != 0 then direction / volatility else 0;
case AMA:
direction = Double.NaN;
volatility = Double.NaN;
ER = AbsValue((close - Lowest(low, 10)) -
(Highest(high, 10) - close)) / (Highest(high,
10) - Lowest(low, 10));}
def SlowSF = 0.2222;
def ScaledSF = ER * (0.4 - SlowSF) + SlowSF;
def AMA = CompoundValue(1, AMA[1] + Sqr(ScaledSF) * (close - AMA[1]),
close);
plot MAA = AMA;
MAA.assignvaluecolor(if OHLC4 > AMA then createcolor(38,115,251)
else createcolor(234,33,0));
MAA.setlineweight(2);
MAA.hidebubble();
MAA.hidetitle();
### Calculate Tangent
def m = Tan(OHLC4 * Double.Pi / 10) - Tan(OHLC4[5] * Double.Pi / 10);
# 7-bar slope line
def lrs = 6 * (WMA(OHLC4,7) - Average(OHLC4,7))/(6);
input fr = No;
def mlr;
if (fr) then {
mlr = InertiaAll(OHLC4);} else {
mlr = InertiaAll(OHLC4,7);}
def dist = HighestAll(AbsValue(mlr - OHLC4));
plot mlrPlot = mlr;
mlrPlot.SetDefaultColor(createcolor(25,115,250));
mlrPlot.assignvaluecolor(if m < 0 then color.red else createcolor(25,115,250));
mlrPlot.setlineweight(2);
mlrPlot.hidebubble();
mlrPlot.hidetitle();
# 20-bar slope line;
def lrs2 = 6 * (WMA(OHLC4, 20) - Average(OHLC4, 20))/(19);
input fr2 = No;
def mlr2;
if (fr2) then {
mlr2 = InertiaAll(OHLC4);} else {
mlr2 = InertiaAll(OHLC4, 20);}
plot mlr2Plot = mlr2;
mlr2Plot.HideBubble();
mlr2Plot.hidetitle();
mlr2Plot.SetDefaultColor(createcolor(80,100,130));
mlr2Plot.SetStyle(curve.short_dash);
mlr2Plot.setlineweight(1);
addlabel(current == lastBar and close > AMA," Long ",createcolor(38,115,251));
addlabel(current == lastBar and close < AMA," Short ",createcolor(206,49,56));
assignpricecolor(if close > AMA then createcolor(38,115,251) else createcolor(206,49,56));

Final Words

There are a lot of hidden gems from the document.

I highly recommend going over it in detail before you apply the strategy to your trading.

Analyze the examples that Stephen (nextSignals) posted.

Unlock the Power of ThinkorSwim

Get the latest news and updates on TD Ameritrade, ThinkorSwim indicators, thinkScript tutorials, and trading strategies delivered straight to your inbox every week.

We don’t spam! Unsubscribe at anytime.

2 thoughts on “nextSignals Trend Following System for ThinkorSwim

  1. Hi Melvin
    Can this system be used for intraday?
    Can you make this indicator as strategy to get backtesting results?

Leave a Reply

Your email address will not be published. Required fields are marked *