price that would have the histogram go to a lower diff value ?

cpntexas

New member
Super nice !! I use this MACD
https://usethinkscript.com/threads/ct-reverse-macd-cross-for-thinkorswim.19031/
on 2 timeframes and when the two sync up with bullish histograms is normally a nice trade and exit when the higher timeframe histogram goes negative.

Is it possible to get one more label item? ...
the price that would have the histogram go to a lower diff value ?

Thanks for your consideration
Ruby:
#/ This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// @author  = The_Caretaker
#// © The_Caretaker
#// Much respect to the original creator of this idea Mr Johhny Dough
#// And the related works of Giorgos Siligardos and Dimitris Tsokakis
#// The prior work of the above mentioned inspired me to bring the idea to its logical conclusion on the MACD
#// by creating the reverse MACD EMA & SMA signal line cross functions
#// Feel free to reuse or develop this script further, please drop me a note below if you find it useful.
#indicator ( 'CT Reverse MACD Cross', 'CT_MACD', false, format.price, precision=2 )
# Converted by Sam4Cok@Samer800    - 06/2024
declare lower;

input avgType = AverageType.EXPONENTIAL;
input source    = close; #,          'Price Source'
input fast_length  = 12; #,             'Fast Period'
input slow_length  = 26; #,             'Slow Period'
input signalLength = 9; #,              'MA Length',
input showMacdLine = yes; #        'Show MACD'
input showSignalLine = yes; #        'Show EMA'
input showHistogram  = yes; #           'Show EMA Histogram',
input HistogramScalingFactor = 1.0; #        'Histogram Scaling Factor'
input showInfoLabel = yes;

def na = Double.NaN;
def last = IsNaN(close);

DefineGlobalColor("up", CreateColor(0, 94, 255));
DefineGlobalColor("dup", CreateColor(0, 51, 137));
DefineGlobalColor("dn", CreateColor(255, 157, 0));
DefineGlobalColor("ddn", CreateColor(137, 85, 0));
#// Function Declarations
script alpha {
    input len = 12;
    def alpha = 2 / (len + 1);
    plot out = alpha;
}
#    // returns exponential weighted multiplier for period len
script macd_eq {
    input price = close;
    input fast_len = 12;
    input slow_len = 26;
    def fastEMA = ExpAverage(price, fast_len)[1];
    def slowEMA = ExpAverage(price, slow_len)[1];
    def alphaFast = alpha(fast_len);
    def alphaSlow = alpha(slow_len);
    def macd_eq = (alphaFast * fastEMA - alphaSlow * slowEMA) / (alphaFast - alphaSlow);
    def level = ((1 - alphaSlow) * slowEMA - (1 - alphaFast) * fastEMA) / (alphaFast - alphaSlow);
    plot eq = macd_eq;
    plot lvl = level;
}
script macd_cross_ema {
    input price = close;
    input macd = close;
    input fast_len = 12;
    input slow_len = 26;
    input sig_len  = 9;
    def pEMAx = ExpAverage(price, fast_len)[1];
    def pEMAy = ExpAverage(price, slow_len)[1];
    def pEMAz = ExpAverage(macd, sig_len)[1];
    def alphaFast = alpha(fast_len);
    def alphaSlow = alpha(slow_len);
    def alphaSig = alpha(sig_len);
    def macd_cross_ema = (pEMAx * alphaFast * alphaSig - pEMAy * alphaSlow * alphaSig - pEMAx * alphaFast +
      pEMAy * alphaSlow + pEMAy * alphaSig + pEMAz * alphaSig -
      pEMAx * alphaSig - pEMAy - pEMAz + pEMAx ) / (alphaFast * alphaSig - alphaSlow * alphaSig - alphaFast + alphaSlow);
    plot out = macd_cross_ema;
}
#// Calculations

def fast_ema    = ExpAverage(source, fast_length );
def slow_ema    = ExpAverage (source, slow_length );
def macd        = fast_ema - slow_ema;
def c_macd      = if macd > macd[1] then 1 else 0;
def ema_sig_line = MovingAverage(avgType, macd, signalLength);
def c_ema        = if ema_sig_line > ema_sig_line[1] then 1 else 0;
def ema_hist     = macd - ema_sig_line;
def c_hist_e     = if ema_hist >= 0 then
                   if ema_hist[1] < ema_hist then 2 else 1 else
                   if ema_hist[1] < ema_hist then -1 else -2;
#-- plot
plot SignalLine = if showSignalLine then ema_sig_line else na; #, 'MACD EMA Signal Line'
plot macdLine = if showMacdLine then macd else na;
plot histo = if showHistogram then ema_hist * HistogramScalingFactor else na; #, 'EMA Histogram'
plot zero = if last then na else 0;

zero.SetDefaultColor(Color.DARK_GRAY);
macdLine.AssignValueColor(if c_macd then Color.GREEN else COlor.RED);
SignalLine.AssignValueColor(if c_ema then Color.CYAN else COlor.MAGENTA);
histo.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
histo.AssignValueColor(if c_hist_e== 2 then GlobalColor("up") else
                       if c_hist_e== 1 then GlobalColor("dup") else
                       if c_hist_e==-1 then GlobalColor("ddn") else
                       if c_hist_e==-2 then GlobalColor("dn") else Color.GRAY);

#-- Label
def reverse_macd    = macd_eq(source, fast_length, slow_length ).eq;
def macd_ema_cross  = macd_cross_ema(source, macd, fast_length, slow_length, signalLength );
def macd_zero_line  = macd_eq(source, fast_length, slow_length ).lvl;
def revMCD = Round(reverse_macd, 2);
def croMCD = Round(macd_ema_cross, 2);
def zroMCD = Round(macd_zero_line, 2);

def text_eq = source > reverse_macd;
def text_cross = source > macd_ema_cross;
def text_zero = source > macd_zero_line;


AddLabel(showInfoLabel,(if text_eq then "MACD: Continues Rising Above: " + AsDollars(revMCD) else
                            "MACD: Continues Falling Below (Eq): " + AsDollars(revMCD)) +
           (if text_cross then ", Cross Below Signal Line: " + AsDollars(croMCD) else
                               ", Cross Above Signal Line: " + AsDollars(croMCD)) +
           (if zroMCD then ", Cross Below Zero Line: " + AsDollars(zroMCD) else
                           ", Cross Above Zero Line: " + AsDollars(zroMCD)), if c_macd then Color.GREEN else Color.RED);

#-- END of CODE
 
Last edited by a moderator:

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
331 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