Archive for January, 2009

NR7 Paintbar for Think or Swim

January 30, 2009


Here is a Thinkscript indicator to flag if a bar is an NR7 (narrowest range bar in the last 7 bars). I first read about them back in the day on TraderMike’s site. Usually, decreasing volatility and range foreshadows increasing volatility and range. An NR7 can alert you to this pause in price movement. In this indicator, a yellow dot above the bar signifies that the bar is NR7.

Here is the code: (more…)

Volatility-Based Trailing Stop for Think or Swim

January 30, 2009

UPDATE 18 May 2009: Fixed error as noted in comments below (Thanks, Jeff!)

UPDATE 23 Feb 2009: Added option to use High/Low as well as Close as the volatility stop switching trigger. Also changed “AverageTrueRange” to exponential average of High-Low so it works on tick charts.


This Thinkscript indicator is a volatility-based trailing stop, similar to the Chandelier Stop. When direction switches from short to long (or vice versa), the initial stop level is a specified number of multiples of the Average True Range (ATR) of the last ‘n’ bars. Then the value is trailed, getting tighter should volatility decrease or price move to new extremes. A close through the stop level signifies a trend change in this indicator; crossing the value and closing back on the other side does not.

The part of this indicator that was tricky is the trailing stop logic, as well as switching the direction of the indicator–long or short. Thinkscript runs in very linear fashion, and you can’t define an indicator at one point and then change the value at another point. The workaround is to put complicated logic gates into the definition itself.

There are two inputs here: The ATR factor, and the length for the ATR calculation. These can be reset from the studies window without changing the Thinkscript. If you want a different default value, change the code below to the value you want.

The code can be found on my Google site.