Price Trend Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
Warehouse
Another trend following indicator for ThinkorSwim. Similar to the one here, it will plot bearish, bullish, and neutral trend signals in the form of candles color. When adding the indicator, your candles will be assigned to either red, green, or grey.

Notes:
  • Red candles = bearish trend
  • Green candles = bullish trend
  • Gray = Neutral or Sideways trend



thinkScript Code

Code:
# PRICETREND
# DREWGRIFFITH15 (C) 2014
# Posted at https://github.com/hwrdprkns/ThinkOrSwim/blob/master/PriceTrendSTUDY.ts

DECLARE UPPER;

INPUT TRAIL = 1;
INPUT DISPLACE = 1;
INPUT AGGREGATIONPERIOD = AGGREGATIONPERIOD.DAY;

DEF NEW_HIGH = CLOSE > HIGHEST(HIGH(PERIOD = AGGREGATIONPERIOD), TRAIL)[DISPLACE];
DEF NEW_LOW = CLOSE < LOWEST(LOW(PERIOD = AGGREGATIONPERIOD), TRAIL)[DISPLACE];

DEF GREENPRICE = IF NEW_HIGH THEN YES ELSE IF NEW_LOW THEN NO ELSE NEW_HIGH[1];
DEF REDPRICE = IF NEW_LOW THEN YES ELSE IF NEW_HIGH THEN NO ELSE NEW_LOW[1];

PLOT BULLISH = GREENPRICE;
PLOT NEUTRAL = !GREENPRICE AND !REDPRICE;
PLOT BEARISH = REDPRICE;

PLOT RATING =
IF GREENPRICE THEN 1
ELSE IF REDPRICE THEN .5
ELSE 0;

DEF PAINTBARS = YES;

BULLISH.SETDEFAULTCOLOR(COLOR.UPTICK);
BULLISH.SETPAINTINGSTRATEGY(PAINTINGSTRATEGY.BOOLEAN_POINTS);
BULLISH.SETLINEWEIGHT(3);
BULLISH.HIDE();
NEUTRAL.SETDEFAULTCOLOR(COLOR.GRAY);
NEUTRAL.SETPAINTINGSTRATEGY(PAINTINGSTRATEGY.BOOLEAN_POINTS);
NEUTRAL.SETLINEWEIGHT(3);
NEUTRAL.HIDE();
BEARISH.SETDEFAULTCOLOR(COLOR.DOWNTICK);
BEARISH.SETPAINTINGSTRATEGY(PAINTINGSTRATEGY.BOOLEAN_POINTS);
BEARISH.SETLINEWEIGHT(3);
BEARISH.HIDE();
RATING.Hide();
RATING.HideBubble();

DEFINEGLOBALCOLOR("BULLISH", COLOR.UPTICK);
DEFINEGLOBALCOLOR("NEUTRAL", COLOR.GRAY);
DEFINEGLOBALCOLOR("BEARISH", COLOR.DOWNTICK);
ASSIGNPRICECOLOR(IF !PAINTBARS THEN COLOR.CURRENT ELSE IF GREENPRICE THEN GLOBALCOLOR("BULLISH") ELSE IF REDPRICE THEN GLOBALCOLOR("BEARISH") ELSE GLOBALCOLOR("NEUTRAL"));

Shareable Link

 

Top