This is epic, was curious if there was a way to change the colors of the clouds?Try this:
Code:# # TD Ameritrade IP Company, Inc. (c) 2007-2019 # input price = close; input displace = 0; input length = 20; input Num_Dev_Dn = -2.0; input Num_Dev_up = 2.0; input averageType = AverageType.Simple; def sDev = stdev(data = price[-displace], length = length); plot 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)); AddCloud(UpperBand, Midline, Color.Green, Color.Green); AddCloud(LowerBand, Midline, Color.Red, Color.Red);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
This script is awesome! Appreciate the share. Is there any way to scan for this?@arod49
Code:declare upper; declare weak_volume_dependency; input price = close; input bb_averageType = AverageType.Simple; input bb_length = 20; input Num_Dev_Dn = -2.0; input Num_Dev_up = 2.0; def sDev = stdev(data = price, length = bb_length); def MidLine = MovingAverage(bb_averageType, data = price, length = bb_length); def LowerBand = MidLine + num_Dev_Dn * sDev; def UpperBand = MidLine + num_Dev_Up * sDev; input kc_averageType = AverageType.Simple; input trueRangeAverageType = AverageType.SIMPLE; input kc_length = 20; input factor = 1.5; def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), kc_length); def average = MovingAverage(kc_averageType, price, kc_length); def UpperChannel = average + shift; def LowerChannel = average - shift; AssignPriceColor(if UpperBand < UpperChannel and LowerBand > LowerChannel then color.BLUE else color.CURRENT);
plot data = if UpperBand < UpperChannel and LowerBand > LowerChannel then 1 else Double.NaN;
It's not working.@shgreenejr Replace the last line of code with the following code... Untested but should work as expected...
Ruby:plot data = if UpperBand < UpperChannel and LowerBand > LowerChannel then 1 else Double.NaN;
@generic Is there a scan for this particular code? I noticed that $CEI had a yellow candle for the week before it exploded. Would be nice to scan for these plays. Thanks!@arod49 Add this to the bottom of the code. Note that this will overlap with the blue bars if it's also in a squeeze.
Code:AssignPriceColor(if low < LowerBand and low < LowerChannel and close > LowerBand and close > LowerChannel then color.YELLOW else color.CURRENT);
declare upper;
declare weak_volume_dependency;
input price = close;
input bb_averageType = AverageType.Simple;
input bb_length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
def sDev = stdev(data = price, length = bb_length);
def MidLine = MovingAverage(bb_averageType, data = price, length = bb_length);
def LowerBand = MidLine + num_Dev_Dn * sDev;
def UpperBand = MidLine + num_Dev_Up * sDev;
input kc_averageType = AverageType.Simple;
input trueRangeAverageType = AverageType.SIMPLE;
input kc_length = 20;
input factor = 1.5;
def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), kc_length);
def average = MovingAverage(kc_averageType, price, kc_length);
def UpperChannel = average + shift;
def LowerChannel = average - shift;
plot scan = if UpperBand < UpperChannel and LowerBand > LowerChannel then 1 else Double.NaN;
input Opacity = 50;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input Num_Dev_Dn2 = -3.0;
input Num_Dev_up2 = 3.0;
AddCloud(UpperBand, UpperBand2, Color.Green, Color.Green, Opacity);
AddCloud(LowerBand, LowerBand2, Color.Red, Color.Red, Opacity);
# 2-in-1 BB/KC by Ronin
# BB Indicator
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;
def displace = 0;
def sDev = stdev(data = close[-displace], length = length);
plot MidLine = MovingAverage(averageType, data = close[-displace], length = length);
plot LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;
LowerBand.SetDefaultColor(GetColor(7));
MidLine.SetDefaultColor(GetColor(1));
UpperBand.SetDefaultColor(GetColor(7));
# KC Indicator
declare weak_volume_dependency;
input KCfactor1 = 1.618;
input KCfactor2 = 2.000;
input KClength = 20;
input KCaverageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;
def KCdisplace = 0;
def shift1 = KCfactor1 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), KClength);
def shift2 = KCfactor2 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), KClength);
def average = MovingAverage(KCaverageType, close, KClength);
#plot Avg = average[-displace];
#Avg.SetDefaultColor(GetColor(1));
plot Upper_Band1 = average[-KCdisplace] + shift1[-KCdisplace];
Upper_Band1.SetDefaultColor(GetColor(7));
upper_Band1.SetStyle(Curve.SHORT_DASH);
plot Lower_Band1 = average[-KCdisplace] - shift1[-KCdisplace];
Lower_Band1.SetDefaultColor(GetColor(7));
Lower_Band1.SetStyle(Curve.SHORT_DASH);
plot Upper_Band2 = average[-KCdisplace] + shift2[-KCdisplace];
Upper_Band2.SetDefaultColor(GetColor(7));
upper_Band2.SetStyle(Curve.SHORT_DASH);
plot Lower_Band2 = average[-KCdisplace] - shift2[-KCdisplace];
Lower_Band2.SetDefaultColor(GetColor(7));
Lower_Band2.SetStyle(Curve.SHORT_DASH);
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input factor = 1.5;
input length_1 = 20;
input averageType = AverageType.Simple;
input trueRangeAverageType = AverageType.SIMPLE;
def sDev = stdev(data = price[-displace], length = length);
plot 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));
UpperBand.SetDefaultColor(GetColor(5));
def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, price, length);
plot Avg = 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, upper_band, color.cyan);
Addcloud (lowerBand, lower_band, color.green);
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.SIMPLE;
input factor = 1.5;
input length_1 = 20;
input lenSMA = 50;
input lenATR = 14;
input firstFactor = 1.610;
input secondFactor = 2.618;
input thirdFactor = 4.236;
def sDev = StDev(data = price[-displace], length = length);
plot 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));
input trueRangeAverageType = AverageType.SIMPLE;
def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, price, length);
plot Avg = 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, Upper_Band, Color.CYAN);
AddCloud (LowerBand, Lower_Band, Color.GREEN);
script MTF_ATR {
input TF = AggregationPeriod.HOUR;
input Length = 14;
input averageType = AverageType.WILDERS;
plot ATR =
MovingAverage(
averageType,
TrueRange(
high(period = TF),
close(period = TF),
low(period = TF)
),
Length
)
;
}
;
def VAtr = ATR(lenATR);
def vSma = Average(close, lenSMA);
def fib1u = vSma + VAtr * firstFactor;
def fib1l = vSma - VAtr * firstFactor;
def fib2u = vSma + VAtr * secondFactor;
def fib2l = vSma - VAtr * secondFactor;
def fib3u = vSma + VAtr * thirdFactor;
def fib3l = vSma - VAtr * thirdFactor;
plot Centerline = vSma;
plot band1upper = fib1u;
band1upper.SetDefaultColor(GetColor(9));
plot band1lower = fib1l;
band1lower.SetDefaultColor(GetColor(9));
plot band2upper = fib2u;
band2upper.SetDefaultColor(GetColor(6));
plot band2lower = fib2l;
band2lower.SetDefaultColor(GetColor(6));
plot band3upper = fib3u;
band3upper.SetDefaultColor(GetColor(5));
plot band3lower = fib3l;
band3lower.SetDefaultColor(GetColor(5));
declare lower;
def o = open;
def h = high;
def l = low;
def c = close;
def UpO;
def UpH;
def UpL;
def UpC;
if o < c
then {
UpO = o;
UpH = h;
UpL = l;
UpC = c;
} else {
UpO = Double.NaN;
UpH = Double.NaN;
UpL = Double.NaN;
UpC = Double.NaN;
}
# OHLC DOWN candle
def DnO;
def DnH;
def DnL;
def DnC;
if o > c
then {
DnO = o;
DnH = h;
DnL = l;
DnC = c;
} else {
DnO = Double.NaN;
DnH = Double.NaN;
DnL = Double.NaN;
DnC = Double.NaN;
}
AddChart(high = UpH, low = UpL, open = UpC, close = UpO, type = ChartType.CANDLE, growcolor = Color.GREEN);
AddChart(high = DnH, low = DnL, open = DnO, close = DnC, type = ChartType.CANDLE, growcolor = Color.RED);
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input factor = 1.5;
input length_1 = 20;
input averageType = AverageType.Simple;
input trueRangeAverageType = AverageType.SIMPLE;
def sDev = stdev(data = price[-displace], length = length);
plot 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));
UpperBand.SetDefaultColor(GetColor(5));
def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, price, length);
plot Avg = 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, upper_band, color.cyan);
Addcloud (lowerBand, lower_band, color.green);
I removed Ichimuko clouds and kept its moving average as you requested.Here is my Bollinger bands and Keltner bands for ThinkorSwim
#The part of the code is from ThinkorSwim
Ruby:input price = close; input displace = 0; input length = 20; input Num_Dev_Dn = -2.0; input Num_Dev_up = 2.0; input factor = 1.5; input length_1 = 20; input averageType = AverageType.Simple; input trueRangeAverageType = AverageType.SIMPLE; def sDev = stdev(data = price[-displace], length = length); plot 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)); UpperBand.SetDefaultColor(GetColor(5)); def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length); def average = MovingAverage(averageType, price, length); plot Avg = 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, upper_band, color.cyan); Addcloud (lowerBand, lower_band, color.green);
#Heiken_Ashi based on Sylvan Verboort's Trading with HA Candlestick Oscillator
#Bon Bon _last update Jan 17th 2021
# Ichimoku is from ThinkorSwim
declare lower;
input period = 1;
input hideCandles = no;
input candleSmoothing = {default Valcu, Vervoort};
input show_bubble_labels = yes;
input bubbles = yes;
input arrows = yes;
input tenkan_period = 9;
input kijun_period = 26;
def src = close;
input length =20;
def sma = average(src, length);
def stdev = stdev(src, length);
plot Tenkan = (Highest(high, tenkan_period) + Lowest(low, tenkan_period)) / 2;
plot Kijun = (Highest(high, kijun_period) + Lowest(low, kijun_period)) / 2;
plot Chikou = close[-kijun_period];
Tenkan.SetDefaultColor(GetColor(6));
Tenkan.SetLineWeight(2);
Kijun.SetDefaultColor(GetColor(5));
Kijun.SetLineWeight(2);
Chikou.SetDefaultColor(GetColor(0));
input movingAverageType = {default TEMA, Exponential, Hull };
def openMA;
def closeMA;
def highMA;
def lowMA;
switch (movingAverageType) {
case Exponential:
openMA = CompoundValue(1, ExpAverage(open, period), open);
closeMA = CompoundValue(1, ExpAverage(close, period), close);
highMA = CompoundValue(1, ExpAverage(high, period), high);
lowMA = CompoundValue(1, ExpAverage(low, period), low);
case Hull:
openMA = CompoundValue(1, HullMovingAvg(open, period), open);
closeMA = CompoundValue(1, HullMovingAvg(close, period), close);
highMA = CompoundValue(1, HullMovingAvg(high, period), high);
lowMA = CompoundValue(1, HullMovingAvg(low, period), low);
case TEMA:
openMA = CompoundValue(1, TEMA(open, period), open);
closeMA = CompoundValue(1, TEMA(close, period), close);
highMA = CompoundValue(1, TEMA(high, period), high);
lowMA = CompoundValue(1, TEMA(low, period), low);
}
HidePricePlot(hideCandles);
def haOpen;
def haClose;
switch (candleSmoothing){
case Valcu:
haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0) / 2.0), open);
haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);
case Vervoort:
haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0 ) / 2.0), open);
haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);
}
plot o = haOpen;
o.AssignValueColor(if o > o[1] then Color.cyan else if o < o[1] then Color.magenta else color.gray);
o.SetLineWeight (5);
o.Hide();
def haLow = Min(lowMA, haOpen);
def haHigh = Max(highMA, haOpen);
#Zero Lag System - MetaStock Crossover Formula
#zero-lagging principle
#Zero-lagging TEMA average on closing prices
#Medium-term price reversals - upward trend
def avg = 34;
def TMA1 = reference TEMA(haClose, avg); # triple exponential moving average (TEMA) of 34 bars
def TMA2 = reference TEMA(TMA1, avg);
def Diff = TMA1 - TMA2;
def ZlHa = TMA1 + Diff; #Zero-lagging TEMA average on closing prices - medium term uptrend;
#Medium-term price reversals - downward trend
def TMA1_ = reference TEMA((high + low) / 2, avg);
def Diff2 = TMA1_ - TMA2;
def ZlCl = TMA1_ + Diff2; #Zero-lagging TEMA average on closing prices - medium term doenwardtrend;
def ZlDif = ZlCl - ZlHa; # Zero-Lag close - Zero-Lag HA(green candle) Uptrend when ZlDif is equal to or greater than zero
#uptrend {green candle}
def keep1 = if (haClose >= haOpen and haClose[1] >= haOpen[1]) then 1 else 0;
def keep2 = if ZlDif >= 0 then 1 else 0;
def keep3 = if (AbsValue(close - open) < ((high - low) * 0.35)) and high >= low[1] then 1 else 0;
def keeping = if (keep1 or keep2) then 1 else 0;
def keepall = if keeping or (keeping[1]) and close >= open or close >= (close[1]) then 1 else 0;
def utr = if keepall or (keepall[1]) and keep3 then 1 else 0;
#downtrend red candle
def keep1_ = if (haClose < haOpen and haClose[1] < haOpen[1]) then 1 else 0;
def keep2_ = if ZlDif < 0 then 1 else 0;
def keep3_ = if (AbsValue(close - open) < ((high - low) * 0.35)) and low <= high[1] then 1 else 0;
def keeping_ = if (keep1_ or keep2_) then 1 else 0;
def dkeepall_ = if keeping_ or (keeping_[1]) and close < open or close < (close[1]) then 1 else 0;
def dtr = if dkeepall_ or (dkeepall_[1] - 1) and keep3_ == 1 then 1 else 0; #downtrend
def upw = if dtr and (dtr[1]) and utr then 1 else 0;
def dnw = if !utr and (utr[1] ) and dtr then 1 else 0;
def results = if upw then 1 else if dnw then 0 else results[1];
#Change the color of HA and Japanese Candles - turn off to show only HA on chart
#AssignPriceColor(if haClose >= haOpen
# then Color.cyan else
# if haClose < haOpen
# then Color.magenta else Color.WHITE);
#Heiken_A script
#####################################################################################################
input charttype = ChartType.CANDLE;
def haopen_ = if haClose <= haOpen
then haOpen + 0
else Double.NaN;
def HAhi = if haClose <= haOpen
then haHigh
else Double.NaN;
def HAlo = if haClose <= haOpen
then haLow
else Double.NaN;
AddChart(growColor = Color.red, neutralColor = Color.CURRENT, high = HAhi, low = HAlo, open = haopen_, close = haClose, type = ChartType.CANDLE);
def HAclose1 = ohlc4;
def HAopen1 = if haClose >= haOpen
then CompoundValue(1, (haOpen[1] + haClose[1]) / 2, (open[1] + close[1]) / 2)
else Double.NaN;
def haopen_1 = if haOpen <= haClose
then HAopen1 + 0 else Double.NaN;
def HAhigh1 = haHigh;
def HAlow1 = haLow;
AddChart(growColor = Color.green, neutralColor = Color.CURRENT, high = HAhigh1, low = HAlow1, open = haopen_1, close = haClose, type = ChartType.CANDLE);
def na = double.nan;
def t1 = SequenceCounter()."Buy Formation";
def t2 = SequenceCounter()."Sell Formation";
def t3 = SequenceCounter()."Buy Array";
def t4 = SequenceCounter()."Sell Array";
def t5 = SequenceCounter()."Perfect Buy";
def t6 = SequenceCounter()."Perfect Sell";
def t7 = SequenceCounter()."Perfect Array Buy";
def t8 = SequenceCounter()."Perfect Array Sell";
input show_test_labels = no;
addlabel(show_test_labels , "seq1 " + t1, color.cyan);
addlabel(show_test_labels , "seq2 " + t2, color.cyan);
addlabel(show_test_labels , "seq3 " + t3, color.cyan);
addlabel(show_test_labels , "seq4 " + t4, color.cyan);
addlabel(show_test_labels , "seq5 " + t5, color.cyan);
addlabel(show_test_labels , "seq6 " + t6, color.cyan);
addlabel(show_test_labels , "seq7 " + t7, color.cyan);
addlabel(show_test_labels , "seq8 " + t8, color.cyan);
# t1 - lower white
# t2 - upper white
# t3 - lower red
# t4 - uper red
# keep 8, 9, and 13 , ignore other numbers
plot u1 = if t1 == 8 or t1 == 9 or t1 == 13 then t1 else na;
plot u2 = if t2 == 8 or t2 == 9 or t2 == 13 then t2 else na;
plot u3 = if t3 == 8 or t3 == 9 or t3 == 13 then t3 else na;
plot u4 = if t4 == 8 or t4 == 9 or t4 == 13 then t4 else na;
u1.SetPaintingStrategy(PaintingStrategy.VALUES_below);
u1.SetDefaultColor(Color.white);
u1.hidebubble();
u2.SetPaintingStrategy(PaintingStrategy.VALUES_above);
u2.SetDefaultColor(Color.white);
u2.hidebubble();
u3.SetPaintingStrategy(PaintingStrategy.VALUES_below);
u3.SetDefaultColor(Color.yellow);
u3.hidebubble();
u4.SetPaintingStrategy(PaintingStrategy.VALUES_above);
u4.SetDefaultColor(Color.yellow);
u4.hidebubble();
plot upper3 = sma + (stdev *3);
Upper3.AssignValueColor(if upper3> upper3[1] then color.green else color.red);
plot lower3 = sma - (stdev * 3);
Lower3.AssignValueColor(if lower3> lower3[1] then color.green else color.red);
plot upper2 = sma + (stdev * 2);
plot lower2 = sma - (stdev * 2);
plot mid = (upper2 + lower2) / 2;
mid.AssignValueColor(if mid> mid[1] then color.cyan else color.pink);
mid.SetLineWeight(2);
plot upper1 = sma + (stdev * 1);
plot lower1 = sma - (stdev * 1);
addcloud (upper3, upper2, color.light_red, color.light_red);
addcloud (upper2, upper1, color.lime);
addcloud (upper1, lower1, color.gray);
addcloud (lower1, lower2, color.lime);
addcloud (lower2, lower3, color.light_red, color.light_red);
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
J | Gap between Keltner Channels/Bollinger Bands in scanner | Questions | 8 | |
M | Price crosses Bollinger Bands | Questions | 2 | |
F | Bollinger Bands Strategy | Questions | 2 | |
D | Verify Larry McMillan’s Modified Bollinger Bands | Questions | 5 | |
B | Daily Bollinger Bands | Questions | 10 |
Start a new thread and receive assistance from our community.
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.
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.