The OP has made the B4 Indicator proprietary.
All future questions must be directed to their vendor site: https://b4indicators.com/
All future questions must be directed to their vendor site: https://b4indicators.com/
VTR is a momentum indicator that shows if a stock is overbought or oversold based on its Weekly and Monthly average volatility trading range.
# B4 Indicator
#
# Free for use for non commercial. Header credits must be included when any form of the code included in this package is used.
# User assumes all risk. Author not responsible for errors or use of tool.
# Copyright (c) 2021 B4 Signals
#
# Get support at: https://b4signals.com
# Join us at: https://discord.gg/kD3pKE2CQd
#
#
# v3.0 - barbros / chuck - official release
# BETA - christoper84 - new squeeze logic
# v3.1 - barbaros - squeeze integration, added squeeze dots, changed squeeze label text and color
declare lower;
input ShowMarketForecastLabel = yes; #hint ShowMarketForecastLabel: Show the intermediate Market Forecast label
input ShowMACDBBLabel = yes; #hint ShowMACDBBLabel: Show the MACDBB based Trend label
input ShowMACDBBCloud = no; #hint ShowMACDBBCloud: Show the MACDBB cloud shaded between BB
input ShowRSMCloud = no; #hint ShowRSMCloud: Show the vertical cloud based on RSM
input ShowHMALabel = yes; #hint ShowHMALabel: Show HUll Moving Average based Divergence label
input ShowSQZSqueezeLabel = yes; #hint ShowSQZSqueezeLabel: Show Stochastic Scalper based squeeze label
input ShowSQZSqueezeCloud = yes; #hint ShowSQZSqueezeCloud: Show Stochastic Scalper based squeeze cloud between BB
input ShowBullBearVerticalLines = yes; #hint ShowBullBearVerticalLines: Show vertical lines for bullish or bearish direction
AddLabel(yes, "B4 Indicator", Color.WHITE);
### Market Forecast
def pIntermediate = MarketForecast().Intermediate;
AddLabel(ShowMarketForecastLabel,
"Market Forecast " +
if pIntermediate >= 80 then "Bullish" else
if pIntermediate <= 20 then "Bearish" else
if pIntermediate > pIntermediate[1] then "Rising" else
if pIntermediate < pIntermediate[1] then "Falling" else "Neutral",
if pIntermediate >= 80 then Color.DARK_GREEN else
if pIntermediate <= 20 then Color.DARK_RED else
if pIntermediate > pIntermediate[1] then Color.GREEN else
if pIntermediate < pIntermediate[1] then Color.RED else Color.GRAY
);
### MACDBB
input MACDBB_FastLength = 12;
input MACDBB_SlowLength = 26;
input MACDBB_BandLength = 15;
input MACDBB_NumDev = 1.0;
def MACDBB_Data = MACD(fastLength = MACDBB_FastLength, slowLength = MACDBB_SlowLength, MACDLength = 5);
plot MACDBB_Upper = reference BollingerBands(price = MACDBB_Data, length = MACDBB_BandLength,
Num_Dev_Dn = -MACDBB_NumDev, Num_Dev_Up = MACDBB_NumDev).UpperBand;
MACDBB_Upper.SetDefaultColor(Color.RED);
MACDBB_Upper.HideTitle();
MACDBB_Upper.HideBubble();
plot MACDBB_Lower = reference BollingerBands(price = MACDBB_Data, length = MACDBB_BandLength,
Num_Dev_Dn = -MACDBB_NumDev, Num_Dev_Up = MACDBB_NumDev).Lowerband;
MACDBB_Lower.SetDefaultColor(Color.GREEN);
MACDBB_Lower.HideTitle();
MACDBB_Lower.HideBubble();
plot MACDBB_Midline = reference BollingerBands(price = MACDBB_Data, length = MACDBB_BandLength,
Num_Dev_Dn = -MACDBB_NumDev, Num_Dev_Up = MACDBB_NumDev).MidLine;
MACDBB_Midline.SetDefaultColor(Color.LIGHT_RED);
MACDBB_Midline.SetStyle(Curve.FIRM);
MACDBB_MidLine.HideTitle();
MACDBB_MidLine.HideBubble();
plot MACDBB_Line = MACDBB_Data;
MACDBB_Line.AssignValueColor(
if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line >= MACDBB_Upper then Color.GREEN
else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line >= MACDBB_Upper then Color.DARK_GREEN
else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line <= MACDBB_Lower then Color.RED else
if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line <= MACDBB_Lower then Color.DARK_RED
else Color.GRAY
);
MACDBB_Line.SetLineWeight(1);
plot MACDBB_Dots = MACDBB_Data;
MACDBB_Dots.AssignValueColor(
if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.GREEN
else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.DARK_GREEN
else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.RED
else if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.DARK_RED
else Color.GRAY
);
MACDBB_Dots.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
MACDBB_Dots.SetLineWeight(1);
MACDBB_Dots.HideTitle();
MACDBB_Dots.HideBubble();
input MACDBB_CrossFromAboveAlert = {default "Zero", "Lower", "Middle", "Upper"};
input MACDBB_CrossFromBelowAlert = {default "Zero", "Lower", "Middle", "Upper"};
def MACDBB_CrossFromAboveVal = if MACDBB_CrossFromAboveAlert == MACDBB_CrossFromAboveAlert.Lower then MACDBB_Lower
else if MACDBB_CrossFromAboveAlert == MACDBB_CrossFromAboveAlert.Upper then MACDBB_Upper
else 0;
def MACDBB_CrossFromBelowVal = if MACDBB_CrossFromBelowAlert == MACDBB_CrossFromBelowAlert.Lower then MACDBB_Lower
else if MACDBB_CrossFromBelowAlert == MACDBB_CrossFromBelowAlert.Upper then MACDBB_Upper
else 0;
def MACDBB_Buy = MACDBB_Data > MACDBB_Upper;
def MACDBB_Sell = MACDBB_Data <= MACDBB_Lower;
AddLabel(ShowMACDBBLabel,
"Trend " +
if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then "Bullish"
else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then "Bullish (reversing)"
else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then "Bearish"
else if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then "Bearish (reversing)"
else "Neutral",
if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.GREEN
else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.DARK_GREEN
else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.RED
else if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.DARK_RED
else Color.GRAY
);
AddCloud(if ShowMACDBBCloud then MACDBB_Upper else MACDBB_Lower, MACDBB_Lower, Color.LIGHT_RED);
### RSI/STOCASTIC/MACD CONFLUENCE COMBO
plot RSM_MACD_Diff = reference MACD("fast length" = 12, "slow length" = 26, "macd length" = 9).Diff;
RSM_MACD_Diff.SetDefaultColor(GetColor(5));
RSM_MACD_Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RSM_MACD_Diff.SetLineWeight(4);
RSM_MACD_Diff.DefineColor("Positive and Up", Color.GREEN);
RSM_MACD_Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
RSM_MACD_Diff.DefineColor("Negative and Down", Color.RED);
RSM_MACD_Diff.DefineColor("Negative and Up", Color.DARK_RED);
RSM_MACD_Diff.AssignValueColor(
if RSM_MACD_Diff >= 0 then
if RSM_MACD_Diff > RSM_MACD_Diff[1] then RSM_MACD_Diff.Color("Positive and Up") else RSM_MACD_Diff.Color("Positive and Down")
else
if RSM_MACD_Diff < RSM_MACD_Diff[1] then RSM_MACD_Diff.Color("Negative and Down") else RSM_MACD_Diff.Color("Negative and Up")
);
plot RSM_MACD_ZeroLine = 0;
RSM_MACD_ZeroLine.SetDefaultColor(Color.DARK_GRAY);
RSM_MACD_ZeroLine.HideTitle();
RSM_MACD_ZeroLine.HideBubble();
def RSM_RSI = reference RSI(length = 7).RSI;
def RSM_Stoch_Val = 100 * (close - lowest(low, 14)) / (highest(high, 14) - lowest(low, 14));
def RSM_StochSlowK = SimpleMovingAvg(SimpleMovingAvg(RSM_Stoch_Val,3),3);
def RSM_rsiGreen = RSM_RSI >= 50;
def RSM_rsiRed = RSM_RSI < 50;
def RSM_stochGreen = RSM_StochSlowK >= 50;
def RSM_stochRed = RSM_StochSlowK < 50;
def RSM_macdGreen = RSM_MACD_Diff >= 0;
def RSM_macdRed = RSM_MACD_Diff < 0;
def RSM_Buy = RSM_rsiGreen and RSM_stochGreen and RSM_macdGreen;
def RSM_Sell = RSM_rsiRed and RSM_stochRed and RSM_macdRed;
# Shade areas based on criteria; adjust as needed
AddCloud(
if ShowRSMCloud and RSM_rsiGreen and RSM_stochGreen and RSM_macdGreen then Double.POSITIVE_INFINITY else Double.NaN,
if ShowRSMCloud and RSM_rsiGreen and RSM_stochGreen and RSM_macdGreen then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_GREEN
);
AddCloud(
if ShowRSMCloud and RSM_rsiRed and RSM_stochRed and RSM_macdRed then Double.POSITIVE_INFINITY else Double.NaN,
if ShowRSMCloud and RSM_rsiRed and RSM_stochRed and RSM_macdRed then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_RED
);
### Divergance
input HMA_Length = 55;
input HMA_Lookback = 2;
def HMA = HullMovingAvg(price = HL2, length = HMA_Length);
def HMA_delta = HMA[1] - HMA[HMA_Lookback + 1];
def HMA_delta_per_bar = HMA_delta / HMA_Lookback;
def HMA_next_bar = HMA[1] + HMA_delta_per_bar;
def HMA_concavity = if HMA > HMA_next_bar then 1 else -1;
def HMA_MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
def HMA_MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.NaN;
def HMA_divergence = HMA - HMA_next_bar;
AddLabel(ShowHMALabel,
"Divergence " +
if HMA_concavity < 0 then
if HMA_divergence[1] > HMA_divergence then "Bearish"
else "Bearish (reversing)"
else
if HMA_divergence[1] < HMA_divergence then "Bullish"
else "Bullish (reversing)",
if HMA_concavity < 0 then
if HMA_divergence[1] > HMA_divergence then Color.RED
else Color.DARK_RED
else
if HMA_divergence[1] < HMA_divergence then Color.GREEN
else Color.DARK_GREEN
);
### Squeeze
input SQZ_SqueezeLength = 30;
def SQZ_Bandwidth = MACDBB_Upper - MACDBB_Lower;
def SQZ_Squeeze_Low = Lowest(SQZ_Bandwidth, SQZ_SqueezeLength);
def SQZ_Squeeze = SQZ_Bandwidth == SQZ_Squeeze_Low;
def SQZ_squeeze_signal = !SQZ_squeeze[1] and SQZ_squeeze;
plot SQZ_Dot = if SQZ_Squeeze then 0 else Double.NaN;
SQZ_Dot.setPaintingStrategy(PaintingStrategy.POINTS);
SQZ_Dot.setLineWeight(2);
SQZ_Dot.setDefaultColor(color.WHITE);
SQZ_Dot.HideTitle();
SQZ_Dot.HideBubble();
AddCloud(if ShowSQZSqueezeCloud and SQZ_squeeze then MACDBB_Upper else Double.NaN,
if ShowSQZSqueezeCloud and SQZ_squeeze then MACDBB_Lower else Double.NaN, Color.YELLOW);
AddLabel(ShowSQZSqueezeLabel, "Squeeze Alert", if SQZ_squeeze then Color.WHITE else Color.DARK_GRAY);
### RSI IFT
def RSI_IFT_R = reference RSI(5, close) - 50;
def RSI_IFT_AvgRSI = MovingAverage(AverageType.Exponential,RSI_IFT_R,9);
def RSI_IFT_InverseRSI = (Power(Double.E, 2 * RSI_IFT_AvgRSI) - 1) / (Power(Double.E, 2 * RSI_IFT_AvgRSI) + 1);
def RSI_IFT_Direction = if BarNumber() == 0 then 0
else if (RSI_IFT_InverseRSI[1] > 0) and (RSI_IFT_InverseRSI < 0) then -1
else if (RSI_IFT_InverseRSI > 0) and (RSI_IFT_InverseRSI[1] < 0) then 1
else RSI_IFT_Direction[1];
### Fibonacci SuperTrend
input FST_Length = 11;
input FST_Retrace = 23.6;
input FST_UseHighLow = yes;
def FST_h = if FST_UseHighLow then high else close;
def FST_l = if FST_UseHighLow then low else close;
def FST_minL = Lowest(FST_l, FST_Length);
def FST_maxH = Highest(FST_h, FST_Length);
def FST_hh = if FST_h > FST_maxH[1] then FST_h else FST_hh[1];
def FST_ll = if FST_l < FST_minL[1] then FST_l else FST_ll[1];
def FST_trend = if FST_h > FST_maxH[1] then 1 else if FST_l < FST_minL[1] then -1 else FST_trend[1];
def FST_Direction = if BarNumber() == 0 then 0
else if FST_trend != 1 then -1
else if FST_trend == 1 then 1
else FST_Direction[1];
### Bar Color
input BarColor = { "None", default "RSM", "FibonacciSuperTrend" }; #hint BarColor: Paint bars with RSM or Fibonacci SuperTrend direction
AssignPriceColor(
if BarColor == BarColor.FibonacciSuperTrend then
if FST_trend == 1 then Color.GREEN else Color.RED
else if BarColor == BarColor.RSM then
if RSM_Buy then Color.GREEN
else if RSM_Sell then Color.RED
else Color.DARK_GRAY
else Color.CURRENT
);
### Strategy
input BullBear_Include_FST = yes; #hint BullBear_Include_FST: Include Fibonacci SuperTrend in the vertical line strategy
input BullBear_Include_RSI_IFT = yes; #hint BullBear_Include_RSI_IFT: Include RSI IFT in the vertical line strategy
def BullBear_Buy = (!BullBear_Include_FST or FST_Direction == 1) and
(!BullBear_Include_RSI_IFT or RSI_IFT_Direction == 1);
def BullBear_Sell = (!BullBear_Include_FST or FST_Direction == -1) and
(!BullBear_Include_RSI_IFT or RSI_IFT_Direction == -1);
AddVerticalLine(ShowBullBearVerticalLines and BullBear_Buy and !BullBear_Buy[1],
AsDollars(close),
Color.GREEN, Curve.SHORT_DASH);
AddVerticalLine(ShowBullBearVerticalLines and BullBear_Sell and !BullBear_Sell[1],
AsDollars(close),
Color.RED, Curve.SHORT_DASH);
def Strategy_Buy = BullBear_Buy and MACDBB_Buy and RSM_Buy;
def Strategy_Sell = BullBear_Sell and MACDBB_Sell and RSM_Sell;
def Strategy_BuySignal = Strategy_Buy and !Strategy_Buy[1];
def Strategy_SellSignal = Strategy_Sell and !Strategy_Sell[1];
plot BuyArrow = if Strategy_BuySignal then 0 else Double.NaN;
BuyArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuyArrow.SetDefaultColor(Color.WHITE);
BuyArrow.HideTitle();
BuyArrow.HideBubble();
plot SellArrow = if Strategy_SellSignal then 0 else Double.NaN;
SellArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellArrow.SetDefaultColor(Color.WHITE);
SellArrow.HideTitle();
SellArrow.HideBubble();
### Alerts
Alert(Strategy_BuySignal, "Long Entry", Alert.BAR, Sound.DING);
Alert(Strategy_SellSignal, "Short Entry", Alert.BAR, Sound.DING);
Alert(MACDBB_Line crosses above MACDBB_CrossFromAboveVal, "MACDBB Crossed Up", Alert.BAR, Sound.DING);
Alert(MACDBB_Line crosses below MACDBB_CrossFromBelowVal, "MACDBB Crossed Down", Alert.BAR, Sound.DING);
Alert(SQZ_squeeze_signal, "Squeeze Alert", Alert.BAR, Sound.DING);
******************************************
WATCH LIST
# B4 Watchlist Column
#
# Free for use for non commercial. Header credits must be included when any form of the code included in this package is used.
# User assumes all risk. Author not responsible for errors or use of tool.
# Copyright (c) 2021 B4 Signals
#
# Get support at: https://b4signals.com
# Join us at: https://discord.gg/kD3pKE2CQd
#
#
# v3.0 - barbros / chuck - official release
### MACDBB
input MACDBB_FastLength = 12;
input MACDBB_SlowLength = 26;
input MACDBB_BandLength = 15;
input MACDBB_NumDev = 1.0;
def MACDBB_Data = MACD(fastLength = MACDBB_FastLength, slowLength = MACDBB_SlowLength, MACDLength = 5);
def MACDBB_Upper = reference BollingerBands(price = MACDBB_Data, length = MACDBB_BandLength,
Num_Dev_Dn = -MACDBB_NumDev, Num_Dev_Up = MACDBB_NumDev).UpperBand;;
def MACDBB_Lower = reference BollingerBands(price = MACDBB_Data, length = MACDBB_BandLength,
Num_Dev_Dn = -MACDBB_NumDev, Num_Dev_Up = MACDBB_NumDev).Lowerband;
def MACDBB_Buy = MACDBB_Data > MACDBB_Upper;
def MACDBB_Sell = MACDBB_Data <= MACDBB_Lower;
### RSI/STOCASTIC/MACD CONFLUENCE COMBO
def RSM_MACD_Diff = reference MACD(fastLength = 12, slowLength = 26, MACDLength = 9).Diff;
def RSM_MACD_ZeroLine = 0;
def RSM_RSI = reference RSI(length = 7).RSI;
def RSM_Stoch_Val = 100 * (close - lowest(low, 14)) / (highest(high, 14) - lowest(low, 14));
def RSM_StochSlowK = SimpleMovingAvg(SimpleMovingAvg(RSM_Stoch_Val,3),3);
def RSM_rsiGreen = RSM_RSI >= 50;
def RSM_rsiRed = RSM_RSI < 50;
def RSM_stochGreen = RSM_StochSlowK >= 50;
def RSM_stochRed = RSM_StochSlowK < 50;
def RSM_macdGreen = RSM_MACD_Diff >= 0;
def RSM_macdRed = RSM_MACD_Diff < 0;
def RSM_Buy = RSM_rsiGreen and RSM_stochGreen and RSM_macdGreen;
def RSM_Sell = RSM_rsiRed and RSM_stochRed and RSM_macdRed;
### RSI IFT
def RSI_IFT_R = reference RSI(5, close) - 50;
def RSI_IFT_AvgRSI = MovingAverage(AverageType.Exponential,RSI_IFT_R,9);
def RSI_IFT_InverseRSI = (Power(Double.E, 2 * RSI_IFT_AvgRSI) - 1) / (Power(Double.E, 2 * RSI_IFT_AvgRSI) + 1);
def RSI_IFT_Direction = if BarNumber() == 0 then 0
else if (RSI_IFT_InverseRSI[1] > 0) and (RSI_IFT_InverseRSI < 0) then -1
else if (RSI_IFT_InverseRSI > 0) and (RSI_IFT_InverseRSI[1] < 0) then 1
else RSI_IFT_Direction[1];
### Fibonacci SuperTrend
input FST_Length = 11;
input FST_Retrace = 23.6;
input FST_UseHighLow = yes;
def FST_h = if FST_UseHighLow then high else close;
def FST_l = if FST_UseHighLow then low else close;
def FST_minL = Lowest(FST_l, FST_Length);
def FST_maxH = Highest(FST_h, FST_Length);
def FST_hh = if FST_h > FST_maxH[1] then FST_h else FST_hh[1];
def FST_ll = if FST_l < FST_minL[1] then FST_l else FST_ll[1];
def FST_trend = if FST_h > FST_maxH[1] then 1 else if FST_l < FST_minL[1] then -1 else FST_trend[1];
def FST_Direction = if BarNumber() == 0 then 0
else if FST_trend != 1 then -1
else if FST_trend == 1 then 1
else FST_Direction[1];
### Strategy
input BullBear_Include_FST = yes; #hint BullBear_Include_FST: Include Fibonacci SuperTrend in the vertical line strategy
input BullBear_Include_RSI_IFT = yes; #hint BullBear_Include_RSI_IFT: Include RSI IFT in the vertical line strategy
def BullBear_Buy = (!BullBear_Include_FST or FST_Direction == 1) and
(!BullBear_Include_RSI_IFT or RSI_IFT_Direction == 1);
def BullBear_Sell = (!BullBear_Include_FST or FST_Direction == -1) and
(!BullBear_Include_RSI_IFT or RSI_IFT_Direction == -1);
def Strategy_Buy = BullBear_Buy and MACDBB_Buy and RSM_Buy;
def Strategy_Sell = BullBear_Sell and MACDBB_Sell and RSM_Sell;
AssignBackgroundColor(
if Strategy_Buy and !Strategy_Buy[1] then Color.GREEN
else if Strategy_Sell and !Strategy_Sell[1] then Color.RED
else color.CURRENT
);
AddLabel(yes,
if Strategy_Buy and !Strategy_Buy[1] then "Buy"
else if Strategy_Sell and !Strategy_Sell[1] then "Sell"
else if Strategy_Buy then "Long"
else if Strategy_Sell then "Short"
else "Neutral",
if Strategy_Buy and !Strategy_Buy[1] then Color.BLACK
else if Strategy_Sell and !Strategy_Sell[1] then Color.WHITE
else if Strategy_Buy then Color.LIGHT_GREEN
else if Strategy_Sell then Color.LIGHT_RED
else Color.CURRENT);
Thanks very much for sharing the link and the work that went into this
Hi Chuck, any chance for a scan for when one of the alerts or lines change color signaling sell or buy? ThanksThis is something I cooked up this morning. Not a lot went into it. Maybe you guys could refine it a little if you find it interesting. Any feedback welcomed. I am just learning to Thinkscroipt and learning by remixing things hear and their:
Code:# Balanced BB Breakout Indicator # Asymbled by Chuck Edwards # V1.0 ################################################################# #################### TOS MARKET FORECAST ####################### ################################################################# #Edited by Chuck_E declare lower; plot pIntermediate = MarketForecast()."Intermediate" ; DefineGlobalColor("Pre_Cyan", CreateColor(204, 255, 204)) ; DefineGlobalColor("LabelGreen", CreateColor(0, 165, 0)) ; addlabel(yes, if pIntermediate >= 80 then "Market Forecast Bullish" else if pIntermediate <= 20 then "Market Forecast Bearish" else if pIntermediate>pIntermediate[1] then "Market Forecast Rising" else if pIntermediate<pIntermediate[1] then "Market Forecast Falling" else " ", if pIntermediate >= 80 then GlobalColor("Pre_Cyan") else if pIntermediate <= 20 then color.red else if pIntermediate>pIntermediate[1] then GlobalColor("LabelGreen") else if pIntermediate<pIntermediate[1] then color.RED else color.light_gray); ################################################################ #################### MACD_BB ########################## ################################################################ # By Eric Purdy, Thinkscripter LLC # Modification to color scheme by Rick_K 12/26/20. # Edited color scheme Chuck_E 02/23/21. ###### MACD input price = close; input BBlength = 10; input BBNum_Dev = 1.0; input MACDfastLength = 12; input MACDslowLength = 26; input fastLengthMACD = 12; input slowLengthMACD = 26; input MACDLength = 5; input averageTypeMACD = AverageType.WEIGHTED; input showBreakoutSignals = no; def MACD_Data = MACD(fastLength = MACDfastLength, slowLength = MACDslowLength, MACDLength = MACDLength); plot MACD_Dots = MACD_Data; plot MACD_Line = MACD_Data; plot BB_Upper = reference BollingerBands(price = MACD_Line, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).UpperBand; plot BB_Lower = reference BollingerBands(price = MACD_Line, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).Lowerband; plot BB_Midline = reference BollingerBands(price = MACD_Line, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).MidLine; BB_Upper.SetDefaultColor(Color.RED); BB_Lower.SetDefaultColor(Color.GREEN); BB_Midline.SetDefaultColor(Color.LIGHT_RED); BB_Midline.SetStyle(Curve.FIRM); MACD_Line.AssignValueColor(if MACD_Line > MACD_Line[1] then color.green else color.red); MACD_Line.AssignValueColor(if MACD_Line > MACD_Line[1] and MACD_Line >= BB_Upper then Color.GREEN else if MACD_Line < MACD_Line[1] and MACD_Line >= BB_Upper then Color.DARK_GREEN else if MACD_Line < MACD_Line[1] and MACD_Line <= BB_Lower then Color.RED else if MACD_Line > MACD_Line[1] and MACD_Line <= BB_Lower then Color.DARK_RED else Color.GRAY); MACD_Line.SetLineWeight(1); MACD_Dots.AssignValueColor(if MACD_Line > MACD_Line[1] then Color.green else Color.RED); MACD_Dots.AssignValueColor(if MACD_Line > MACD_Line[1] and MACD_Line > BB_Upper then Color.GREEN else if MACD_Line < MACD_Line[1] and MACD_Line > BB_Upper then Color.DARK_GREEN else if MACD_Line < MACD_Line[1] and MACD_Line < BB_Lower then Color.RED else if MACD_Line > MACD_Line[1] and MACD_Line < BB_Lower then Color.DARK_RED else Color.GRAY); MACD_Dots.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS); MACD_Dots.SetLineWeight(1); plot zero = 0; zero.SetDefaultColor(Color.WHITE); zero.SetStyle(Curve.SHORT_DASH); zero.SetLineWeight(1); ###### Keltner Channels input displace = 0; input factor = 1.5; input length = 20; input averageType = AverageType.EXPONENTIAL; input trueRangeAverageType = AverageType.EXPONENTIAL; def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length); def average = MovingAverage(averageType, price, length); #def Avg = average[-displace]; def Upper_Band = average[-displace] + shift[-displace]; def Lower_Band = average[-displace] - shift[-displace]; ###### Bollinger Bands input BBLength2 = 20; input Num_Dev_Dn = -2.0; input Num_Dev_up = 2.0; input bb_averageType = AverageType.SIMPLE; def sDev = StDev(data = price[-displace], length = BBLength2); def MidLine = MovingAverage(bb_averageType, data = price[-displace], length = BBLength2); def LowerBand = MidLine + Num_Dev_Dn * sDev; def UpperBand = MidLine + Num_Dev_up * sDev; ###### Add Cloud AddCloud(if UpperBand <= Upper_Band and LowerBand >= Lower_Band then BB_Upper else BB_Lower, BB_Lower, Color.YELLOW); AddCloud( BB_Upper, BB_Lower, Color.LIGHT_RED ); ###### Add Alert def bull_cross = MACD_Line crosses above zero; def bear_cross = MACD_Line crosses below zero; Alert(bull_cross, "Time to Buy", Alert.BAR, Sound.Chimes); Alert(bear_cross, "Time to Sell", Alert.BAR, Sound.Bell); ################################################################ ########## RSI/STOCASTIC/MACD CONFLUENCE COMBO ############# ################################################################ #CHANGELOG # 2020.10.27 V1.0 [USER=6343]@cos251[/USER] - Added RSI, StochasticSlow and MACD to same indicator; this will plot only MACD but also # - calculates RSI and Sotchasit; Will shade the lower plot area of the following conditions are met # Shade GREEN = RSI > 50 and SlowK > 50 and (macd)Value > (macd)Avg # Shade RED = RSI < 50 and SlowK < 50 and (macd)Value < (macd)Avg #REQUIREMENTS - RSI Set to 7, EXPONENTIAL # Stoch Slow 5(not14) and 3 WILDERS # MACD 12,26,9 WEIGHTED #CREDITS # requesed by "[USER=4682]@Joseph Patrick 18[/USER]" #LINK # [URL]https://rockwell-files.s3.amazonaws.com/PXCompanionGuide2ndEd_cover.pdf[/URL] # Markus Heikoetter who is the author of the Power X Strategy # [URL]https://usethinkscript.com/threads/mimicking-power-x-strategy-by-markus-heitkoetter.4283/[/URL] #Editeded by Chuck_E plot Value = MovingAverage(averageTypeMACD, close, fastLengthMACD) - MovingAverage(averageTypeMACD, close, slowLengthMACD); plot Avg = MovingAverage(averageTypeMACD, Value, MACDLength); plot Diff = Value - Avg; plot ZeroLine = 0; plot UpSignalMACD = if Diff crosses above ZeroLine then ZeroLine else Double.NaN; plot DownSignalMACD = if Diff crosses below ZeroLine then ZeroLine else Double.NaN; UpSignalMACD.SetHiding(!showBreakoutSignals); DownSignalMACD.SetHiding(!showBreakoutSignals); Value.SetDefaultColor(Color.GREEN); Avg.SetDefaultColor(Color.RED); Diff.SetDefaultColor(GetColor(5)); Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); Diff.SetLineWeight(4); Diff.DefineColor("Positive and Up", Color.GREEN); Diff.DefineColor("Positive and Down", Color.DARK_GREEN); Diff.DefineColor("Negative and Down", Color.RED); Diff.DefineColor("Negative and Up", Color.DARK_RED); Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up")); ZeroLine.SetDefaultColor(GetColor(0)); UpSignalMACD.SetDefaultColor(Color.UPTICK); UpSignalMACD.SetPaintingStrategy(PaintingStrategy.ARROW_UP); DownSignalMACD.SetDefaultColor(Color.DOWNTICK); DownSignalMACD.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); ###### RSI input lengthRSI = 7; input over_BoughtRSI = 70; input over_SoldRSI = 30; input averageTypeRSI = AverageType.EXPONENTIAL; def NetChgAvg = MovingAverage(averageTypeRSI, price - price[1], lengthRSI); def TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(price - price[1]), lengthRSI); def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0; def RSI = 50 * (ChgRatio + 1); ###### Stochastic Slow input over_boughtSt = 80; input over_soldSt = 20; input KPeriod = 5;#5 input DPeriod = 3; input priceH = high; input priceL = low; input priceC = close; input averageTypeStoch = AverageType.WILDERS; input showBreakoutSignalsStoch = {default "No", "On SlowK", "On SlowD", "On SlowK & SlowD"}; def SlowK = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullK; def SlowD = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullD; ###### Check for signals > 50 and macd Value > Avg def rsiGreen = if RSI >= 50 then 1 else Double.NaN; def rsiRed = if RSI < 50 then 1 else Double.NaN; def stochGreen = if SlowK >= 50 then 1 else Double.NaN; def stochRed = if SlowK < 50 then 1 else Double.NaN; def macdGreen = if Value > Avg then 1 else Double.NaN; def macdRed = if Value < Avg then 1 else Double.NaN; ###### Shade areas based on criteria; adjust as needed AddCloud(if rsiGreen and stochGreen and macdGreen then Double.POSITIVE_INFINITY else Double.NaN, if rsiGreen and stochGreen then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_Green); AddCloud(if rsiRed and stochRed and macdRed then Double.POSITIVE_INFINITY else Double.NaN, if rsiRed and stochRed then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_RED); ################################################################# ############ BALANCE OF POWER TREND ############################ ################################################################# # Assembled by BenTen at useThinkScript.com # Converted from [URL]https://www.tradingview.com/script/XldP1lmA/[/URL] input EMA = 20; input TEMA = 20; input high_l = 0.1; input low_l = -0.1; def THL = If(high != low, high - low, 0.01); def BullOpen = (high - open) / THL; def BearOpen = (open - low) / THL; def BullClose = (close - low) / THL; def BearClose = (high - close) / THL; def BullOC = If(close > open, (close - open) / THL, 0); def BearOC = If(open > close, (open - close) / THL, 0); def BullReward = (BullOpen + BullClose + BullOC) / 1; def BearReward = (BearOpen + BearClose + BearOC) / 1; def BOP = BullReward - BearReward; def SmoothBOP = ExpAverage(BOP, EMA); def xPrice = SmoothBOP; def xEMA1 = ExpAverage(SmoothBOP, TEMA); def xEMA2 = ExpAverage(xEMA1, TEMA); def xEMA3 = ExpAverage(xEMA2, TEMA); def nRes = 3 * xEMA1 - 3 * xEMA2 + xEMA3; def SmootherBOP = nRes; def s1 = SmoothBOP; def s2 = SmootherBOP; def s3 = SmootherBOP[2]; ####### Vertical Lines def short = s2 < s3 and s2[1] > s3[1]; def long = s2 > s3 and s2[1] < s3[1]; AddVerticalLine(short, close, Color.RED, Curve.SHORT_DASH); AddVerticalLine(long, close, Color.GREEN, Curve.SHORT_DASH); ###### P/L Statement input PandL_Label = Yes; def orderDir = CompoundValue(1, if s2 < s3 then 1 else if s2 > s3 then -1 else orderDir[1], 0); def isOrder = orderDir crosses 0; def orderCount = CompoundValue(1, if IsNaN(isOrder) then 0 else if isOrder then orderCount[1] + 1 else orderCount[1], 0); def noBar = IsNaN(open[-1]); def orderPrice = if isOrder then if noBar then close else open[-1] else orderPrice[1]; def profitLoss = if !isOrder or orderCount == 1 then 0 else if orderDir < 0 then orderPrice[1] - orderPrice else if orderDir > 0 then orderPrice - orderPrice[1] else 0; #else if orderDir > 0 then orderPrice[1] - orderPrice #else if orderDir < 0 then orderPrice - orderPrice[1] else 0; #def profitLoss = if !isOrder or orderCount == 1 then 0 else orderPrice - orderPrice[1]; def profitLossSum = CompoundValue(1, if IsNaN(isOrder) then 0 else if isOrder then profitLossSum[1] + profitLoss else profitLossSum[1], 0); def orderWinners = CompoundValue(1, if IsNaN(isOrder) then orderWinners[1] else if orderCount > 1 and profitLoss > 0 then orderWinners[1] + 1 else orderWinners[1], 0); ###### Add Label AddLabel(PandL_Label, orderCount + " Orders (" + AsPercent(orderWinners / orderCount) + ") | P/L " + AsDollars((profitLossSum / TickSize()) * TickValue()), if profitLossSum > 0 then Color.GREEN else if profitLossSum < 0 then Color.RED else Color.GRAY); #------ End Balanced BB Breakout Indicator
@Joseph Patrick 18, Hopefully you downloaded the updated version. The original sript posted did not have my defaulted settings. Editied the latest post to reflect. I am not a good coder, I just mixed this all together from some of my favorite lower indicators to have a all in one. Edited out a few conflicts. Maybe someone here can create a scan. but this is still experimental, use with caution.Hi Chuck, any chance for a scan for when one of the alerts or lines change color signaling sell or buy? Thanks
Thanks Chuck, I did and it looks awesome! Thanks!@Joseph Patrick 18, Hopefully you downloaded the updated version. The original sript posted did not have my defaulted settings. Editied the latest post to reflect. I am not a good coder, I just mixed this all together from some of my favorite lower indicators to have a all in one. Edited out a few conflicts. Maybe someone here can create a scan. but this is still experimental, use with caution.
Joe,
The first thing I do is backtest it on the instrument I want to trade. Using a one day chart with time intervals of 2m,3m,5m,10m,15m, etc. and check out the P/L to see what time frame is the most profitable, considering my risk and max drawdown.
Next I adjust the fast length macd, so that it matches my optimal entry/exit points on that timeframe.
After that to answer your question I watch the MACD line. Before the line turns grey it should turn dark red or dark green. Thats when I am alerted. I use that as my lead while using this indicator.
When the MACD line turns grey, that is an area of indecision and as soon as that line crosses the middle BB line, I look for secondary confirmation to confirm entry or exit, I do this on entries and exits.
I have all the arrows turned on on my version and I look for the arrows, or histogram, or colored cloud background, or balance of power line with price level for my entries also considering the other signals and price indications I am getting from the candles and other indicators in my final evaluation.
Hey Chuck, thanks for your explanation and for your work with this. Would you mind explaining further how you make the decision about what to adjust the MACD fast length to?Joe,
The first thing I do is backtest it on the instrument I want to trade. Using a one day chart with time intervals of 2m,3m,5m,10m,15m, etc. and check out the P/L to see what time frame is the most profitable, considering my risk and max drawdown.
Next I adjust the fast length macd, so that it matches my optimal entry/exit points on that timeframe.
After that to answer your question I watch the MACD line. Before the line turns grey it should turn dark red or dark green. Thats when I am alerted. I use that as my lead while using this indicator.
When the MACD line turns grey, that is an area of indecision and as soon as that line crosses the middle BB line, I look for secondary confirmation to confirm entry or exit, I do this on entries and exits.
I have all the arrows turned on on my version and I look for the arrows, or histogram, or colored cloud background, or balance of power line with price level for my entries also considering the other signals and price indications I am getting from the candles and other indicators in my final evaluation.
@JE $$ ,Hey Chuck, thanks for your explanation and for your work with this. Would you mind explaining further how you make the decision about what to adjust the MACD fast length to?
1)first you look at the P/L and how it differs based on changing the timeframe - so if 5m looks better than 3, you'd probably go with 5m
2)then you adjust the MACD fast line - this is the part i'm having difficulty with - what do you do to figure out how you should adjust it?
Chuck -thanks@JE $$ ,
I like to have probability in my favor. that’s why I put that strategy on my lower indicators.
For each instrument that I trade I can run a P/L analysis.
Once that’s locked into the optimal time frame, I like to adjust other indicators or in this instance studies within the indicator for maximum performance.
I personally open the study and adjust the fast length macd.
I adjust the fast length MACD by while looking at the histogram while trying to optimize it to the perfect high/ low pivot points.
I like to send it to eight out of 10 occurrences.
That is just my personal preference
Okay will do. Thanks Chuck for helping me out and I will try and reach out to try to get someone to help.Joe,
Some people may want to enter upon the bollinger band crossing that will be for earlier trade enties/exits. You will have to play with it and figure out what works best for you. I updated the link and the second post to add paint bars. I am not a coder and would not recommend trading live until all the kinks are worked out. I see several of the indicators on this forum were designed because of your requests. Perhaps you can reach out and get one of these guys to tweak this thing up a bit if you like it.
Hey, JoeOkay will do. Thanks Chuck for helping me out and I will try and reach out to try to get someone to help.
Joe
Check out our Buy the Dip indicator and see how it can help you find profitable swing trading ideas. Scanner, watchlist columns, and add-ons are included.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
RedK Chop & Breakout Scout V2.0 for ThinkOrSwim | Indicators | 16 | ||
G | Potential Breakout (PBO) Indicator for ThinkorSwim | Indicators | 8 | |
ThinkorSwim Stock Breakout Scanner | Indicators | 11 | ||
Potential Breakout Arrow Plots Indicator for ThinkorSwim | Indicators | 82 | ||
H | TOP Ultimate Breakout Indicator for ThinkorSwim | Indicators | 127 |
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.