hello and welcome,
there are several things wrong with your study
..this won't do anything, will always be 0
def sideway_trend = if close == open then 0 else 0;
..you are plotting 1 , -1, or 0, so you probably want a lower chart, but didn't declare it as a lower study
declare lower;
..this line is wrong. 2 colors are not defined
Color.SIDEWAYS and Color.NOCHANGE) don't exist
TrendPhase.AssignValueColor(if TrendPhase > 0 then Color.UPTICK else if TrendPhase < 0 then Color.DOWNTICK else Color.SIDEWAYS else Color.NOCHANGE);
list of colors
https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/Color
--------------------
i added a new formula, to replace the 3 formulas you had.
def trend = if close > open then 1
else if close < open then -1
else 0;
defined some colors to use in the plot
fixed AssignValueColor( )
Code:
# trend_phase_00
# https://usethinkscript.com/threads/trying-to-set-a-thinkscript-code-to-show-trend-phases-on-chart-for-sideway-bear-and-bull-markets.14046/
#Trying to set a thinkscript code to show trend phases on chart for sideway, bear, and bull markets
#Dinarae 1/11
declare lower;
#def long_trend = if close > open then 1 else 0;
#def short_trend = if close < open then -1 else 0;
#def sideway_trend = if close == open then 0 else 0;
def trend = if close > open then 1
else if close < open then -1
else 0;
#plot TrendPhase = long_trend + short_trend + sideway_trend;
plot TrendPhase = trend;
TrendPhase.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TrendPhase.DefineColor("up" , color.green);
TrendPhase.DefineColor("down", color.red);
TrendPhase.DefineColor("sideways", color.yellow);
TrendPhase.AssignValueColor(
if TrendPhase > 0 then TrendPhase.Color("up")
else if TrendPhase < 0 then TrendPhase.Color("down")
else TrendPhase.Color("sideways"));
#
here is a different, simpler way to pick the plot colors
Code:
# trend_phase_00c
declare lower;
def trend = if close > open then 1
else if close < open then -1
else 0;
plot TrendPhase = trend;
TrendPhase.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TrendPhase.AssignValueColor(
if TrendPhase > 0 then color.green
else if TrendPhase < 0 then color.red
else color.yellow);
#