Bull Market Support Band for ThinkorSwim

petergluis

Active member
I convert Bull Market Support Band for ThinkorSwim.
This moving average indicator is a bull market support band. It's significance comes from the previous bull runs where the price was bouncing off or riding from a distance the support band until the end of the market cycle.
https://www.tradingview.com/script/uSBR7cFa-Bull-Market-Support-Band-20w-SMA-21w-EMA/


Ruby:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © legroszach

//@version=4
study("Bull Market Support Band", overlay=true, resolution="W")

source = close
smaLength = 20
emaLength = 21

sma = sma(source, smaLength)
ema = ema(source, emaLength)

outSma = security(syminfo.tickerid, timeframe.period, sma)
outEma = security(syminfo.tickerid, timeframe.period, ema)

smaPlot = plot(outSma, color=color.red, title="20w SMA")
emaPlot = plot(outEma, color=color.green, title="21w EMA")
// thanks @bbrujas for the heads up
fill(smaPlot, emaPlot, color=color.new(color.orange, 75), fillgaps=true)




Ruby:
#[URL]https://www.tradingview.com/script/uSBR7cFa-Bull-Market-Support-Band-20w-SMA-21w-EMA/[/URL]
#© legroszach
def source = close;
def smaLength = 20;
def emaLength = 21;

def sma = Average(source, smaLength);
def ema = ExpAverage(source, emaLength);

Plot LineSma = sma;
LineSma.DefineColor("UpTrend", Color.GREEN);
LineSma.DefineColor("DownTrend", Color.RED);
LineSma.SetLineWeight(3);
LineSma.SetPaintingStrategy(PaintingStrategy.LINE);
LineSma.SetStyle(Curve.FIRM);
LineSma.AssignValueColor(if LineSma > LineSma [1] then LineSma.Color("UpTrend") else LineSma.Color("DownTrend"));
plot LineEma = ema;
LineEma.DefineColor("UpTrend", Color.light_GREEN);
LineEma.DefineColor("DownTrend", Color.Light_RED);
LineEma.SetLineWeight(3);
LineEma.SetPaintingStrategy(PaintingStrategy.LINE);
LineEma.SetStyle(Curve.FIRM);
LineEma.AssignValueColor(if LineEma > LineEma [1] then LineEma.Color("UpTrend") else LineEma.Color("DownTrend"));
Addcloud (sma, ema, color.cyan, color.cyan);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I combined Bull Market Support Band with Bollinger Bands, Keltner Bands, and Mono-Bollinger Bands into a package.
Ruby:
#https://usethinkscript.com/threads/bollinger-bands-and-keltner-bands-for-thinkorswim.10509/page-2#posts
#https://www.tradingview.com/script/uSBR7cFa-Bull-Market-Support-Band-20w-SMA-21w-EMA/
#Bollinger bands and Keltner bands
#https://usethinkscript.com/threads/fw_mobo_advanced-indicator.10525/#post-93508
#[URL]https://www.tradingview.com/script/uSBR7cFa-Bull-Market-Support-Band-20w-SMA-21w-EMA/[/URL]
#© legroszach

def source = close;
def smaLength = 20;
def emaLength = 21;

def sma = Average(source, smaLength);
def ema = ExpAverage(source, emaLength);

plot LineSma = sma;
LineSma.DefineColor("UpTrend", Color.GREEN);
LineSma.DefineColor("DownTrend", Color.RED);
LineSma.SetLineWeight(3);
LineSma.SetPaintingStrategy(PaintingStrategy.LINE);
LineSma.SetStyle(Curve.FIRM);
LineSma.AssignValueColor(if LineSma > LineSma [1] then LineSma.Color("UpTrend") else LineSma.Color("DownTrend"));
plot LineEma = ema;
LineEma.DefineColor("UpTrend", Color.LIGHT_GREEN);
LineEma.DefineColor("DownTrend", Color.LIGHT_RED);
LineEma.SetLineWeight(3);
LineEma.SetPaintingStrategy(PaintingStrategy.LINE);
LineEma.SetStyle(Curve.FIRM);
LineEma.AssignValueColor(if LineEma > LineEma [1] then LineEma.Color("UpTrend") else LineEma.Color("DownTrend"));
AddCloud (sma, ema, Color.CYAN, Color.CYAN);
input price = close;
input displace = 0;
input length = 5;
input Num_Dev_Dn = -1.0;
input Num_Dev_up = 1.0;
input averageType = AverageType.Simple;
input price_C = FundamentalType.CLOSE;
input aggregationPeriod = AggregationPeriod.DAY;
input averageType_c = AverageType.EXPONENTIAL;
input ma3 = 20;
plot Ema20 = MovingAverage(averageType_c, Fundamental(price_c, period = aggregationPeriod), ma3);
Ema20.DefineColor("Up Trend", Color.GREEN);
Ema20.DefineColor("Down Trend", Color.RED);
Ema20.AssignValueColor(if Ema20 > Ema20[1] then Ema20.Color("Up Trend") else Ema20.Color("Down Trend"));
Ema20.SetLineWeight(3);
def sDev = stdev(data = price[-displace], length = length);
def nan  =  Double.NaN;
input fill = yes;
def MidLine = MovingAverage(averageType, data = price[-displace], length = length);
plot LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;
LowerBand.SetDefaultColor(GetColor(0));
#MidLine.SetDefaultColor(GetColor(1));
UpperBand.SetDefaultColor(GetColor(5));
plot ArrowUp = if close crosses above UpperBand
then close
else double.nan;

plot ArrowDn = if close crosses below LowerBand
then close
else double.nan;
input price_a = close;
input length_a = 20;
input Num_Dev_Dn_a = -2.0;
input Num_Dev_up_a = 2.0;
input factor = 1.5;
input length_1 = 20;
input trueRangeAverageType = AverageType.SIMPLE;
def sDev_a = StDev(data = price_a[-displace], length = length_a);
def MidLine_a = MovingAverage(averageType, data = price_a[-displace], length = length_a);
plot LowerBand_a = MidLine_a + Num_Dev_Dn_a * sDev_a;
plot UpperBand_a = MidLine_a + Num_Dev_up_a * sDev_a;
LowerBand.SetDefaultColor(GetColor(0));
UpperBand.SetDefaultColor(GetColor(5));
def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length_a);
def average = MovingAverage(averageType, price_a, length_a);
def Avg_a = average[-displace];
#Avg.SetDefaultColor(GetColor(1));
plot Upper_Band = average[-displace] + shift[-displace];
Upper_Band.SetDefaultColor(GetColor(8));
plot Lower_Band = average[-displace] - shift[-displace];
Lower_Band.SetDefaultColor(GetColor(5));
AddCloud(UpperBand_a, Upper_Band, Color.CYAN);
AddCloud (LowerBand_a, Lower_Band, Color.LIGHT_GREEN, Color.YELLOW);
UpperBand.DefineColor("Up Trend", Color.GREEN);
UpperBand.DefineColor("Down Trend", Color.RED);
UpperBand.AssignValueColor(if UpperBand > UpperBand[1] then UpperBand.Color("Up Trend") else UpperBand.Color("Down Trend"));
UpperBand.SetLineWeight(1);
LowerBand.DefineColor("Up Trend", Color.GREEN);
LowerBand.DefineColor("Down Trend", Color.RED);
LowerBand.AssignValueColor(if LowerBand > LowerBand[1] then LowerBand.Color("Up Trend") else LowerBand.Color("Down Trend"));
LowerBand.SetLineWeight(1);

def a = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def d = (UpperBand < UpperBand[1] and midline < midline[1]);
def e = Average(close) > midline;
def f = midline < Average(close);

def Chg      =   If((UpperBand > UpperBand[1] and LowerBand > LowerBand[1]), 1, If((UpperBand < UpperBand[1] and LowerBand < LowerBand[1]), -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
DefineGlobalColor("Cloud Up", Color.MAGENTA);
DefineGlobalColor("Cloud Dn", Color.GREEN);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
 
Last edited:
I combined Bull Market Support Band with BLSH, Bollinger Bands, Keltner Bands, and Mono-Bollinger Bands into a package.
Ruby:
#https://usethinkscript.com/threads/bollinger-bands-and-keltner-bands-for-thinkorswim.10509/page-2#posts
#https://www.tradingview.com/script/uSBR7cFa-Bull-Market-Support-Band-20w-SMA-21w-EMA/
#Bollinger bands and Keltner bands
#https://usethinkscript.com/threads/fw_mobo_advanced-indicator.10525/#post-93508
#https://usethinkscript.com/threads/blsh-for-thinkorswim.11013/
#[URL]https://www.tradingview.com/script/uSBR7cFa-Bull-Market-Support-Band-20w-SMA-21w-EMA/[/URL]
#© legroszach
def source = close;
def smaLength = 20;
def emaLength = 21;
def length_c = 25;
def profit = 5;
def LOW25 = lowest(low, length_c);
def GTT = LOW25*1.05;
def TARGET = GTT*1.05;
def sma = Average(source, smaLength);
def ema = ExpAverage(source, emaLength);

plot LineSma = sma;
LineSma.DefineColor("UpTrend", Color.GREEN);
LineSma.DefineColor("DownTrend", Color.RED);
LineSma.SetLineWeight(3);
LineSma.SetPaintingStrategy(PaintingStrategy.LINE);
LineSma.SetStyle(Curve.FIRM);
LineSma.AssignValueColor(if LineSma > LineSma [1] then LineSma.Color("UpTrend") else LineSma.Color("DownTrend"));
plot LineEma = ema;
LineEma.DefineColor("UpTrend", Color.LIGHT_GREEN);
LineEma.DefineColor("DownTrend", Color.LIGHT_RED);
LineEma.SetLineWeight(3);
LineEma.SetPaintingStrategy(PaintingStrategy.LINE);
LineEma.SetStyle(Curve.FIRM);
LineEma.AssignValueColor(if LineEma > LineEma [1] then LineEma.Color("UpTrend") else LineEma.Color("DownTrend"));
AddCloud (sma, ema, Color.CYAN, Color.CYAN);
input price = close;
input displace = 0;
input length = 5;
input Num_Dev_Dn = -1.0;
input Num_Dev_up = 1.0;
input averageType = AverageType.Simple;
input price_C = FundamentalType.CLOSE;
input aggregationPeriod = AggregationPeriod.DAY;
input averageType_c = AverageType.EXPONENTIAL;
input ma3 = 20;
plot Ema20 = MovingAverage(averageType_c, Fundamental(price_c, period = aggregationPeriod), ma3);
Ema20.DefineColor("Up Trend", Color.GREEN);
Ema20.DefineColor("Down Trend", Color.RED);
Ema20.AssignValueColor(if Ema20 > Ema20[1] then Ema20.Color("Up Trend") else Ema20.Color("Down Trend"));
Ema20.SetLineWeight(3);
def sDev = stdev(data = price[-displace], length = length);
def nan  =  Double.NaN;
input fill = yes;
def MidLine = MovingAverage(averageType, data = price[-displace], length = length);
plot LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;
LowerBand.SetDefaultColor(GetColor(0));
#MidLine.SetDefaultColor(GetColor(1));
UpperBand.SetDefaultColor(GetColor(5));
plot ArrowUp = if close crosses above UpperBand
then close
else double.nan;

plot ArrowDn = if close crosses below LowerBand
then close
else double.nan;
input price_a = close;
input length_a = 20;
input Num_Dev_Dn_a = -2.0;
input Num_Dev_up_a = 2.0;
input factor = 1.5;
input length_1 = 20;
input trueRangeAverageType = AverageType.SIMPLE;
def sDev_a = StDev(data = price_a[-displace], length = length_a);
def MidLine_a = MovingAverage(averageType, data = price_a[-displace], length = length_a);
plot LowerBand_a = MidLine_a + Num_Dev_Dn_a * sDev_a;
plot UpperBand_a = MidLine_a + Num_Dev_up_a * sDev_a;
LowerBand.SetDefaultColor(GetColor(0));
UpperBand.SetDefaultColor(GetColor(5));
def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length_a);
def average = MovingAverage(averageType, price_a, length_a);
def Avg_a = average[-displace];
#Avg.SetDefaultColor(GetColor(1));
plot Upper_Band = average[-displace] + shift[-displace];
Upper_Band.SetDefaultColor(GetColor(8));
plot Lower_Band = average[-displace] - shift[-displace];
Lower_Band.SetDefaultColor(GetColor(5));
AddCloud(UpperBand_a, Upper_Band, Color.CYAN);
AddCloud (LowerBand_a, Lower_Band, Color.LIGHT_GREEN, Color.YELLOW);
UpperBand.DefineColor("Up Trend", Color.GREEN);
UpperBand.DefineColor("Down Trend", Color.RED);
UpperBand.AssignValueColor(if UpperBand > UpperBand[1] then UpperBand.Color("Up Trend") else UpperBand.Color("Down Trend"));
UpperBand.SetLineWeight(1);
LowerBand.DefineColor("Up Trend", Color.GREEN);
LowerBand.DefineColor("Down Trend", Color.RED);
LowerBand.AssignValueColor(if LowerBand > LowerBand[1] then LowerBand.Color("Up Trend") else LowerBand.Color("Down Trend"));
LowerBand.SetLineWeight(1);

def a = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def d = (UpperBand < UpperBand[1] and midline < midline[1]);
def e = Average(close) > midline;
def f = midline < Average(close);

def Chg      =   If((UpperBand > UpperBand[1] and LowerBand > LowerBand[1]), 1, If((UpperBand < UpperBand[1] and LowerBand < LowerBand[1]), -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
DefineGlobalColor("Cloud Up", Color.MAGENTA);
DefineGlobalColor("Cloud Dn", Color.GREEN);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));

plot lineGTT = GTT;
lineGTT.AssignValueColor(if lineGTT> lineGTT[1] then Color.GREEN else if lineGTT <lineGTT[1] then Color.MAGENTA else color.light_gray);
lineGTT.SetLineWeight(3);
plot LineLowe25 = LOW25;
LineLowe25.AssignValueColor(if LineLowe25> LineLowe25[1] then Color.light_GREEN else if LineLowe25 <LineLowe25[1] then Color.light_red else color.yellow);
LineLowe25.SetLineWeight(3);
plot LineTarget = TARGET;
LineTarget.AssignValueColor(if LineTarget> LineTarget[1] then Color.dark_GREEN else if LineTarget<LineTarget[1] then Color.red else color.white);
LineTarget.SetLineWeight(4);
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
587 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

What are the benefits of VIP Membership?
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.
Back
Top