I struggle with line 8:1 which is indicated on Think or Swim Script editor as an invalid statement (the last two lines of this code). Help is appreciated.
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;
I struggle with line 8:1 which is indicated on Think or Swim Script editor as an invalid statement (the last two lines of this code). Help is appreciated.
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;
I struggle with line 8:1 which is indicated on Think or Swim Script editor as an invalid statement (the last two lines of this code). Help is appreciated.
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;
..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);
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);
#
..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);
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);
#
This is awesome! Thank you! I wonder if trend phases, i.e. bear, bull, and sideway could be implemented in the background of the chart so we know which trend the market goes? I saw that on trading view and LOVED it but I am not sure how to implement it on Think and Swim.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
How do I get started?
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.