Macd Histogram Stall

stevemend0za

New member
VIP
I was hopping to get a label, anything really, of some sort to display the Macd diff differences once the histogram is crossed to bull or bear. Take for instance SPY on the 13 min. 10/13/22 at 7:48 am Pacific time. When histogram crossed over to bullish the candle close gave a diff value of.....

1 candle cross over Macd diff of 0.01415 (which I input as 0.0142).
2nd candle close gave 0.3638. The difference from prior is = 0.3297.
3rd candle close is 0.7777 = The difference from prior = 0.4139 (label green if possible when difference increasing)
4th candle close is 1.2628 = The difference form prior = 0.4851
5the candle close is 1.3005 = The difference from prior = 0.0377 (Stalled) (label red if possible when decreasing)
6th candle close is 1.1590 = The difference from prior = -0.1415

I would prefer to keep calculating until three candles past stalled.

By the way my Macd settings are....
Fast length 8
Slow length 21
Macd length 5
Average type Exponential.

lF8inyo.png

Z7rfF9S.png

yIAnle9.png

mogyd69.png

N6ZfLF5.png

misrzlp.png


I thank you in advance.
 
Solution
@SleepyZ it works great!!! Is there any way to make it display X amount of candles back as a label. Lets say I needed to know the difference of the last 4 or 8 histograms back which means I would have 4 or 8 labels. Would be perfect to be able to modify that via inputs. I turned off the bubble, is more visible with the label. Thank you for the amazing work sir.

This will display up to 8 labels (@input show_last_x_bars) showing the current bull/bear trend. A label at the beginning will indicate the current trend and then the labels are displayed left to right from the last bar's label to the max of 8 labels in the past.

Screenshot-2022-10-15-194419.png
Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2022
#

declare lower;

input fastLength =...
I was hopping to get a label, anything really, of some sort to display the Macd diff differences once the histogram is crossed to bull or bear. Take for instance SPY on the 13 min. 10/13/22 at 7:48 am Pacific time. When histogram crossed over to bullish the candle close gave a diff value of.....

1 candle cross over Macd diff of 0.01415 (which I input as 0.0142).
2nd candle close gave 0.3638. The difference from prior is = 0.3297.
3rd candle close is 0.7777 = The difference from prior = 0.4139 (label green if possible when difference increasing)
4th candle close is 1.2628 = The difference form prior = 0.4851
5the candle close is 1.3005 = The difference from prior = 0.0377 (Stalled) (label red if possible when decreasing)
6th candle close is 1.1590 = The difference from prior = -0.1415

I would prefer to keep calculating until three candles past stalled.

By the way my Macd settings are....
Fast length 8
Slow length 21
Macd length 5
Average type Exponential.

lF8inyo.png

Z7rfF9S.png

yIAnle9.png

mogyd69.png

N6ZfLF5.png

misrzlp.png


I thank you in advance.

Here are 2 options, label and/or bubble, that you can turn on/off at the input screen

Screenshot-2022-10-15-064918.png
Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2022
#

declare lower;

input fastLength = 8;
input slowLength = 21;
input MACDLength = 5;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

plot Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
plot Avg = MovingAverage(averageType, Value, MACDLength);

plot Diff = Value - Avg;
plot ZeroLine = 0;

plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
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));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

def bull = if Diff crosses above 0 then 1 else if Diff crosses below 0 then 0 else bull[1];
input showbubble = yes;
AddChartBubble(showbubble and bull, Diff, Diff - Diff[1], if Diff > Diff[1] then Color.GREEN else Color.RED);
AddChartBubble(showbubble and !bull, Diff, Diff - Diff[1], if Diff < Diff[1] then Color.GREEN else Color.RED, no);

input showlabel = yes;
AddLabel(showlabel and bull, "Bull: " + (Diff - Diff[1]), if Diff > Diff[1] then Color.GREEN else Color.RED);
AddLabel(showlabel and !bull, "Bear: " + (Diff - Diff[1]), if Diff < Diff[1] then Color.GREEN else Color.RED);
 
Last edited:
Here are 2 options, label and/or bubble, that you can turn on/off at the input screen
@SleepyZ it works great!!! Is there any way to make it display X amount of candles back as a label. Lets say I needed to know the difference of the last 4 or 8 histograms back which means I would have 4 or 8 labels. Would be perfect to be able to modify that via inputs. I turned off the bubble, is more visible with the label. Thank you for the amazing work sir.
 
@SleepyZ it works great!!! Is there any way to make it display X amount of candles back as a label. Lets say I needed to know the difference of the last 4 or 8 histograms back which means I would have 4 or 8 labels. Would be perfect to be able to modify that via inputs. I turned off the bubble, is more visible with the label. Thank you for the amazing work sir.

This will display up to 8 labels (@input show_last_x_bars) showing the current bull/bear trend. A label at the beginning will indicate the current trend and then the labels are displayed left to right from the last bar's label to the max of 8 labels in the past.

Screenshot-2022-10-15-194419.png
Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2022
#

declare lower;

input fastLength = 8;
input slowLength = 21;
input MACDLength = 5;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

plot Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
plot Avg = MovingAverage(averageType, Value, MACDLength);

plot Diff = Value - Avg;
plot ZeroLine = 0;

plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
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));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

def bull = if Diff crosses above 0 then 1 else if Diff crosses below 0 then -1 else bull[1];

input showbubble = no;
AddChartBubble(showbubble and bull, Diff, Diff - Diff[1], if Diff > Diff[1] then Color.GREEN else Color.RED);
AddChartBubble(showbubble and !bull, Diff, Diff - Diff[1], if Diff < Diff[1] then Color.GREEN else Color.RED, no);

input showlabel = no;
AddLabel(showlabel and bull, "Bull: " + (Diff - Diff[1]), if Diff > Diff[1] then Color.GREEN else Color.RED);
AddLabel(showlabel and !bull, "Bear: " + (Diff - Diff[1]), if Diff < Diff[1] then Color.GREEN else Color.RED);


input show_x_labels    = yes;
input show_last_x_bars = 8;
def bn = BarNumber();
def lastbar   = if IsNaN(close[-1]) and !IsNaN(close) then bn else Double.NaN;
def lastdiff  = if bn == HighestAll(lastbar)     then Diff - Diff[1] else lastdiff[1];
def lastdiff1 = if bn == HighestAll(lastbar - 1) then Diff - Diff[1] else lastdiff1[1];
def lastdiff2 = if bn == HighestAll(lastbar - 2) then Diff - Diff[1] else lastdiff2[1];
def lastdiff3 = if bn == HighestAll(lastbar - 3) then Diff - Diff[1] else lastdiff3[1];
def lastdiff4 = if bn == HighestAll(lastbar - 4) then Diff - Diff[1] else lastdiff4[1];
def lastdiff5 = if bn == HighestAll(lastbar - 5) then Diff - Diff[1] else lastdiff5[1];
def lastdiff6 = if bn == HighestAll(lastbar - 6) then Diff - Diff[1] else lastdiff6[1];
def lastdiff7 = if bn == HighestAll(lastbar - 7) then Diff - Diff[1] else lastdiff7[1];
def lastdiff8 = if bn == HighestAll(lastbar - 8) then Diff - Diff[1] else lastdiff8[1];

def lastbull  = if bn == HighestAll(lastbar)     then bull else lastbull[1];
def lastbull1 = if bn == HighestAll(lastbar - 1) then bull else lastbull1[1];
def lastbull2 = if bn == HighestAll(lastbar - 2) then bull else lastbull2[1];
def lastbull3 = if bn == HighestAll(lastbar - 3) then bull else lastbull3[1];
def lastbull4 = if bn == HighestAll(lastbar - 4) then bull else lastbull4[1];
def lastbull5 = if bn == HighestAll(lastbar - 5) then bull else lastbull5[1];
def lastbull6 = if bn == HighestAll(lastbar - 6) then bull else lastbull6[1];
def lastbull7 = if bn == HighestAll(lastbar - 7) then bull else lastbull7[1];
def lastbull8 = if bn == HighestAll(lastbar - 8) then bull else lastbull8[1];

AddLabel(show_x_labels, if lastbull == 1 then "BULL: " else "BEAR: ", Color.WHITE);

AddLabel(show_x_labels and show_last_x_bars >= 1 and lastbull == 1 and lastbull == 1, lastdiff, if lastdiff > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 2 and lastbull == 1  and lastbull1 == 1, lastdiff1, if lastdiff1 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 3 and lastbull == 1  and lastbull2 == 1, lastdiff2, if lastdiff2 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 4 and lastbull == 1  and lastbull3 == 1, lastdiff3, if lastdiff3 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 5 and lastbull == 1  and lastbull4 == 1, lastdiff4, if lastdiff4 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 6 and lastbull == 1  and lastbull5 == 1, lastdiff5, if lastdiff5 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 7 and lastbull == 1  and lastbull6 == 1, lastdiff6, if lastdiff6 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 8 and lastbull == 1  and lastbull7 == 1, lastdiff7, if lastdiff7 > 0 then Color.GREEN else Color.RED);


AddLabel(show_x_labels and show_last_x_bars >= 1 and lastbull == -1, lastdiff, if lastdiff > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 2 and lastbull == -1 and lastbull1 == -1, lastdiff1, if lastdiff1 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 3 and lastbull == -1 and lastbull2 == -1, lastdiff2, if lastdiff2 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 4 and lastbull == -1 and lastbull3 == -1, lastdiff3, if lastdiff3 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 5 and lastbull == -1 and lastbull4 == -1, lastdiff4, if lastdiff4 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 6 and lastbull == -1 and lastbull5 == -1, lastdiff5, if lastdiff5 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 7 and lastbull == -1 and lastbull6 == -1, lastdiff6, if lastdiff6 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 8 and lastbull == -1 and lastbull7 == -1, lastdiff7, if lastdiff7 > 0 then Color.GREEN else Color.RED);
 
Solution
This will display up to 8 labels (@input show_last_x_bars) showing the current bull/bear trend. A label at the beginning will indicate the current trend and then the labels are displayed left to right from the last bar's label to the max of 8 labels in the past.
@SleepyZ What an amazing job you did sir. Works as needed, thank you for your skills and time. (y)
 
@SleepyZ Is there no way to display the labels from right to left. Please advise, thank you.

Sure,

Screenshot-2022-10-16-043145.png
Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2022
#

declare lower;

input fastLength = 8;
input slowLength = 21;
input MACDLength = 5;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

plot Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
plot Avg = MovingAverage(averageType, Value, MACDLength);

plot Diff = Value - Avg;
plot ZeroLine = 0;

plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
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));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

def bull = if Diff crosses above 0 then 1 else if Diff crosses below 0 then -1 else bull[1];

input showbubble = no;
AddChartBubble(showbubble and bull, Diff, Diff - Diff[1], if Diff > Diff[1] then Color.GREEN else Color.RED);
AddChartBubble(showbubble and !bull, Diff, Diff - Diff[1], if Diff < Diff[1] then Color.GREEN else Color.RED, no);

input showlabel = no;
AddLabel(showlabel and bull, "Bull: " + (Diff - Diff[1]), if Diff > Diff[1] then Color.GREEN else Color.RED);
AddLabel(showlabel and !bull, "Bear: " + (Diff - Diff[1]), if Diff < Diff[1] then Color.GREEN else Color.RED);


input show_x_labels    = yes;
input show_last_x_bars = 8;
def bn = BarNumber();
def lastbar   = if IsNaN(close[-1]) and !IsNaN(close) then bn else Double.NaN;
def lastdiff  = if bn == HighestAll(lastbar)     then Diff - Diff[1] else lastdiff[1];
def lastdiff1 = if bn == HighestAll(lastbar - 1) then Diff - Diff[1] else lastdiff1[1];
def lastdiff2 = if bn == HighestAll(lastbar - 2) then Diff - Diff[1] else lastdiff2[1];
def lastdiff3 = if bn == HighestAll(lastbar - 3) then Diff - Diff[1] else lastdiff3[1];
def lastdiff4 = if bn == HighestAll(lastbar - 4) then Diff - Diff[1] else lastdiff4[1];
def lastdiff5 = if bn == HighestAll(lastbar - 5) then Diff - Diff[1] else lastdiff5[1];
def lastdiff6 = if bn == HighestAll(lastbar - 6) then Diff - Diff[1] else lastdiff6[1];
def lastdiff7 = if bn == HighestAll(lastbar - 7) then Diff - Diff[1] else lastdiff7[1];
def lastdiff8 = if bn == HighestAll(lastbar - 8) then Diff - Diff[1] else lastdiff8[1];

def lastbull  = if bn == HighestAll(lastbar)     then bull else lastbull[1];
def lastbull1 = if bn == HighestAll(lastbar - 1) then bull else lastbull1[1];
def lastbull2 = if bn == HighestAll(lastbar - 2) then bull else lastbull2[1];
def lastbull3 = if bn == HighestAll(lastbar - 3) then bull else lastbull3[1];
def lastbull4 = if bn == HighestAll(lastbar - 4) then bull else lastbull4[1];
def lastbull5 = if bn == HighestAll(lastbar - 5) then bull else lastbull5[1];
def lastbull6 = if bn == HighestAll(lastbar - 6) then bull else lastbull6[1];
def lastbull7 = if bn == HighestAll(lastbar - 7) then bull else lastbull7[1];
def lastbull8 = if bn == HighestAll(lastbar - 8) then bull else lastbull8[1];

AddLabel(show_x_labels and show_last_x_bars >= 8 and lastbull == 1  and lastbull7 == 1, lastdiff7, if lastdiff7 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 7 and lastbull == 1  and lastbull6 == 1, lastdiff6, if lastdiff6 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 6 and lastbull == 1  and lastbull5 == 1, lastdiff5, if lastdiff5 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 5 and lastbull == 1  and lastbull4 == 1, lastdiff4, if lastdiff4 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 4 and lastbull == 1  and lastbull3 == 1, lastdiff3, if lastdiff3 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 3 and lastbull == 1  and lastbull2 == 1, lastdiff2, if lastdiff2 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 2 and lastbull == 1  and lastbull1 == 1, lastdiff1, if lastdiff1 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 1 and lastbull == 1 and lastbull == 1, lastdiff, if lastdiff > 0 then Color.GREEN else Color.RED);

AddLabel(show_x_labels and show_last_x_bars >= 8 and lastbull == -1 and lastbull7 == -1, lastdiff7, if lastdiff7 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 7 and lastbull == -1 and lastbull6 == -1, lastdiff6, if lastdiff6 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 6 and lastbull == -1 and lastbull5 == -1, lastdiff5, if lastdiff5 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 5 and lastbull == -1 and lastbull4 == -1, lastdiff4, if lastdiff4 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 4 and lastbull == -1 and lastbull3 == -1, lastdiff3, if lastdiff3 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 3 and lastbull == -1 and lastbull2 == -1, lastdiff2, if lastdiff2 > 0 then Color.GREEN else Color.RED);AddLabel(show_x_labels and show_last_x_bars >= 2 and lastbull == -1 and lastbull1 == -1, lastdiff1, if lastdiff1 > 0 then Color.GREEN else Color.RED);
AddLabel(show_x_labels and show_last_x_bars >= 1 and lastbull == -1, lastdiff, if lastdiff > 0 then Color.GREEN else Color.RED);

AddLabel(show_x_labels, if lastbull == 1 then " :BULL " else " :BEAR ", Color.WHITE);

#
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
464 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