MACD Format, Triggers, Scan, Label, Watchlist For ThinkOrSwim

@Kapitalk12 The label in Post#80 Defines the triggers as follows:
Bullish when MACD is less than zero and MACD is uptrending and MACD crosses above its Average​
Bearish when MACD is less than its Average and is downtrending.​

Modify these lines in the above code to match your definition of breakout:
Ruby:
plot Buy_scan = MACD_value < 0 and MACD_value >= MACD_value[1] and MACD_Value crosses above MACD_Avg ;
plot Sell_scan =  MACD_value < MACD_avg and MACD_value < MACD_value[1] ;
 
Last edited:
One thing that has benefited me in the market has been attempting to avoid trades during periods of consolidation. There are multiple ways traders do this, however, the way I’ve enjoyed doing it involves the MACD indicator.

I like to wait for the MACD's histogram to signal 10 consecutive bars above or below the zeroline before taking on a trade.

I wanted to know if it is possible to turn that concept into a custom indicator?

Maybe a label is added to the MACD indicator, and it counts numerically (1,2,3…) the consecutive “bearish/bullish” histogram bars. Then, resets the count at the next convergence or divergence - MACDline & 9 period avg cross.

Maybe the label is grey as it counts the histogram bars 1-9 as they print beneath the zero line.

However when the 10th bar prints, the label turns green (when I get interested in taking a position) and continues to plot the count until it resets at the next cross.

I’ve attached pictures below to give better visualization of the concept.

Consecutive Histogram Bars

Non-Consecutive Histogram Bars (Consolidation)

Here is the original MACD code from Thinkorswim if anyone wants to take a stab.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2021
#

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
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);
 
Last edited:
This seems to work a bit better. :)
Code:
def trendLength = if diff crosses 0 then 1 else trendLength[1] + 1;
AddLabel(yes, "Histogram Trend Length: " + trendLength, if diff > 0 then Color.DARK_GREEN else Color.DARK_RED);

mashume
 
Hi everyone,
Can someone help me with the MACD histogram script below? as i try to plot arrow up and arrow down for Diff.color("Positive and Down") and Diff.color("Negative and Up"), could you please advise?


declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

plot Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
plot UpSignal = if Diff crosses above 0 then 0 else Double.NaN;
plot DownSignal = if Diff crosses below 0 then 0 else Double.NaN;

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

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"));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

Thanks alot,
 
Hi everyone,
Can someone help me with the MACD histogram script below? as i try to plot arrow up and arrow down for Diff.color("Positive and Down") and Diff.color("Negative and Up"), could you please advise?
a1.png

Ruby:
declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

plot Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;


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"));

plot UpSignal = if Diff < 0  and Diff > Diff[1] then diff else Double.NaN ;
plot DnSignal  = if Diff >= 0 and Diff < Diff[1] then diff
 else Double.NaN ;

UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetDefaultColor(Color.blue) ;
UpSignal.SetLineWeight(1);

DnSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DnSignal.SetDefaultColor(Color.MAGENTA) ;
DnSignal.SetLineWeight(1);
 
I was wondering if anyone knew how to make up arrows for the Macd before the reversal (shaded bars) I will leave the code down below and link an image of where I would like to see the arrow. Although I want to first plot this on the chart I would love for this to be implemented into a scan. Any help is truly appreciated.

**Edited. Found the solution:
I was playing with the code and the scanner and found the solution. That line of code is indeed correct but it just needs to be offset by whatever amount desired. ill leave the code down below and I would love to hear your thoughts. Maybe even attack it from another perspective.

Code:
input fastLength = 12;
input slowLength = 25;
input MACDLength = 10;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = yes;

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

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

def UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;



def buy = value[-2] > Avg[-2] and value[-2] > avg[-2];

plot ArrowUp = !Buy[1] and Buy ;
ArrowUp.SetDefaultColor(Color.GREEN);
ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
 
Last edited by a moderator:
I have been messing around with the Macd and the arrow function but for some reason, I cannot figure out how to get rid of the extra arrows. I'm only trying to get arrows when the Macd is starting to reverse from negative to positive and no arrows after it becomes positive. I will leave an image link and the code down below. Any help given is much appreciated.

Code:
input fastLength = 12;
input slowLength = 25;
input MACDLength = 10;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = yes;

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

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

def UpSignal = if Diff[-1] crosses above ZeroLine then ZeroLine else Double.NaN;


def buy = if value > Avg then 0 else value < Avg;


def Condition1 = if
buy
then 1 else Double.NaN;
plot x = Condition1;
x.SetPaintingStrategy(paintingStrategy = PaintingStrategy.BOOLEAN_ARROW_UP);


All the arrows in the white circle is what I'm trying to get rid of and all the arrows in the gold circle is what I'm trying to keep
2eBLf9N.png


Photo Example
 
Last edited by a moderator:
MACD Label & WatchList
@Baller4lfe When the value is greater than average AND is trending up it creates a positive momentum.
Instead of just above avg and below avg... Included is:

MACD TrendingMACD Watch ItMACD FallingMACD Rising
Value > Avg
Value is trending up
Value > Avg
Value is trending down
Value < Avg
Value is trending down
Value < Avg
Value is trending up
color greencolor dark graycolor redcolor dark green
The number in the label is the difference between value and average.

Upper Study Label and Lower Study Indicator
Shared Chart Link: http://tos.mx/6v2K0kT Click here for --> Easiest way to load shared links
View attachment 854
WatchList
View attachment 859


Upper Chart Study
Ruby:
# ########################################################
# MACD with a more Normal Distribution by Mobius V01.09.2015
#Hint: Plots a Gaussian distribution. If Normal Distribution is met, then at minimum, 68.2% of the close values should be inside a One Standard Deviation Envelope and 95.4% of the close values should be inside a 2 Standard Deviation Envelope.

input fastLength = 8 ; # short 6, 13, 6 BB length 5
input slowLength = 17; # default 8 17 9
input MACDLength = 9;
input showBreakoutSignals = yes;
input ma_length = 21; #Length(180-200 for floating S/R , 55 for swing entry)

# Four Pole Filter
script g {
    input length = 4;
    input betaDev = 2;
    input price = OHLC4;
    def c;
    def w;
    def beta;
    def alpha;
    def G;
    c = price;
    w = (2 * Double.Pi / length);
    beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDev) - 1 );
    alpha = (-beta + Sqrt(beta * beta + 2 * beta));
    G = Power(alpha, 4) * c +
4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +
4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4];
    plot Line = G;
}

#My Standard Chart Colors
# Modified MACD
def MACD_Value = g(length = fastLength) - g(length = slowLength);
def MACD_Avg = g(price = MACD_Value, length = MACDLength);
def Diff = MACD_Value - MACD_Avg;

def PositiveUp   = MACD_Value > MACD_Value[1] and MACD_Value > MACD_Avg ;
def NegativeUp   = MACD_Value < MACD_Value[1] and MACD_Value > MACD_Avg ;
def NegativeDown = MACD_Value < MACD_Value[1] and MACD_Value < MACD_Avg ;
def PostiveDown  = MACD_Value > MACD_Value[1] and MACD_Value < MACD_Avg ;

plot Buy_scan = MACD_value < 0 and MACD_value >= MACD_value[1] and MACD_Value crosses above MACD_Avg ;
plot Sell_scan =  MACD_value < MACD_avg and MACD_value < MACD_value[1] ;
Buy_scan.Hide();
Sell_scan.Hide();
plot Buy_signal = if Buy_scan and !Buy_scan[1] then MACD_value else double.NaN  ;
Buy_signal.SetPaintingStrategy(PaintingStrategy.LINE_Vs_poINTS);
Buy_signal.SetDefaultColor(color.cyan) ;
Buy_signal.SetLineWeight(5);
plot sell_signal = if sell_scan and !sell_scan[1] then MACD_value else double.NaN  ;
sell_signal.SetPaintingStrategy(PaintingStrategy.LINE_Vs_poINTS);
sell_signal.SetDefaultColor(color.magenta) ;
sell_signal.SetLineWeight(5);

# ########################################################
# Charting and Formatting
DefineGlobalColor("Pre_Cyan", CreateColor(50, 200, 255)) ;
DefineGlobalColor("LabelGreen",  CreateColor(0, 165, 0)) ;

input ShowLabels = yes ;
AddLabel(ShowLabels,
if buy_scan then "MACD Trend Begin" else
if sell_scan and !sell_scan[1] then "MACD Trend End" else
if PositiveUp then "MACD Trending " + Round(Diff, 1) else
if PostiveDown then "MACD Rising " + Round(Diff, 1) else
if NegativeUp then "MACD Watch It " + Round(Diff, 1) else
if NegativeDown then "MACD Falling " + Round(Diff, 1) else "MACD Wait ",
if buy_scan then GlobalColor("Pre_Cyan") else
if sell_scan and !sell_scan[1] then color.magenta else
if PositiveUp then GlobalColor("LabelGreen") else
if PostiveDown then color.dark_green else
if NegativeUp then Color.DARK_gray else
if NegativeDown then Color.RED else
 Color.GRAY);

Lower Study Indicator
Ruby:
declare lower;
# ########################################################
# MACD with a more Normal Distribution by Mobius V01.09.2015
#Hint: Plots a Gaussian distribution. If Normal Distribution is met, then at minimum, 68.2% of the close values should be inside a One Standard Deviation Envelope and 95.4% of the close values should be inside a 2 Standard Deviation Envelope.

input fastLength = 8 ; # short 6, 13, 6 BB length 5
input slowLength = 17; # default 8 17 9
input MACDLength = 9;
input showBreakoutSignals = yes;
input ma_length = 21; #Length(180-200 for floating S/R , 55 for swing entry)

# Four Pole Filter
script g {
    input length = 4;
    input betaDev = 2;
    input price = OHLC4;
    def c;
    def w;
    def beta;
    def alpha;
    def G;
    c = price;
    w = (2 * Double.Pi / length);
    beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDev) - 1 );
    alpha = (-beta + Sqrt(beta * beta + 2 * beta));
    G = Power(alpha, 4) * c +
4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +
4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4];
    plot Line = G;
}

plot zeroline = 0 ;
zeroline.SetDefaultColor(Color.GRAY);

# Modified MACD
def MACD_Value = g(length = fastLength) - g(length = slowLength);
plot MACD_Avg = g(price = MACD_Value, length = MACDLength);
def Diff = MACD_Value - MACD_Avg;
AddCloud(MACD_Value, MACD_Avg, Color.GREEN, Color.RED);

def PositiveUp   = MACD_Value > MACD_Value[1] and MACD_Value > MACD_Avg ;
def NegativeUp   = MACD_Value < MACD_Value[1] and MACD_Value > MACD_Avg ;
def NegativeDown = MACD_Value < MACD_Value[1] and MACD_Value < MACD_Avg ;
def PostiveDown  = MACD_Value > MACD_Value[1] and MACD_Value < MACD_Avg ;
# ########################################################
# Charting and Formatting
DefineGlobalColor("Pre_Cyan", CreateColor(50, 200, 255)) ;
DefineGlobalColor("LabelGreen",  CreateColor(0, 165, 0)) ;

plot Buy_scan = MACD_value < 0 and MACD_value >= MACD_value[1] and MACD_Value crosses above MACD_Avg ;
plot Sell_scan =  MACD_value < MACD_avg and MACD_value < MACD_value[1] ;
Buy_scan.Hide();
Sell_scan.Hide();
plot Buy_signal = if Buy_scan and !Buy_scan[1] then MACD_value else double.NaN  ;
Buy_signal.SetPaintingStrategy(PaintingStrategy.LINE_Vs_poINTS);
Buy_signal.SetDefaultColor(color.cyan) ;
Buy_signal.SetLineWeight(5);
plot sell_signal = if sell_scan and !sell_scan[1] then MACD_value else double.NaN  ;
sell_signal.SetPaintingStrategy(PaintingStrategy.LINE_Vs_poINTS);
sell_signal.SetDefaultColor(color.magenta) ;
sell_signal.SetLineWeight(5);
# ########################################################
plot MACD_dots = MACD_Value ;
MACD_dots.AssignValueColor(
if buy_scan then GlobalColor("Pre_Cyan") else
if sell_scan and !sell_scan[1] then color.magenta else
if PositiveUp then GlobalColor("LabelGreen") else
if PostiveDown then color.dark_green else
if NegativeUp then Color.DARK_gray else
if NegativeDown then Color.RED else
 Color.GRAY);
MACD_dots.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
MACD_dots.SetLineWeight(1);
# ########################################################
input ShowLabels = yes ;
AddLabel(ShowLabels,
if buy_scan then "MACD Trend Begin" else
if sell_scan and !sell_scan[1] then "MACD Trend End" else
if PositiveUp then "MACD Trending " + Round(Diff, 1) else
if PostiveDown then "MACD Rising " + Round(Diff, 1) else
if NegativeUp then "MACD Watch It " + Round(Diff, 1) else
if NegativeDown then "MACD Falling " + Round(Diff, 1) else "MACD Wait ",
if buy_scan then GlobalColor("Pre_Cyan") else
if sell_scan and !sell_scan[1] then color.magenta else
if PositiveUp then GlobalColor("LabelGreen") else
if PostiveDown then color.dark_green else
if NegativeUp then Color.DARK_gray else
if NegativeDown then Color.RED else
 Color.GRAY);

WatchList
Ruby:
# ########################################################
# MACD with a more Normal Distribution by Mobius V01.09.2015
#Hint: Plots a Gaussian distribution. If Normal Distribution is met, then at minimum, 68.2% of the close values should be inside a One Standard Deviation Envelope and 95.4% of the close values should be inside a 2 Standard Deviation Envelope.

input fastLength = 8 ; # short 6, 13, 6 BB length 5
input slowLength = 17; # default 8 17 9
input MACDLength = 9;
input showBreakoutSignals = yes;
input ma_length = 21; #Length(180-200 for floating S/R , 55 for swing entry)

# Four Pole Filter
script g {
    input length = 4;
    input betaDev = 2;
    input price = OHLC4;
    def c;
    def w;
    def beta;
    def alpha;
    def G;
    c = price;
    w = (2 * Double.Pi / length);
    beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDev) - 1 );
    alpha = (-beta + Sqrt(beta * beta + 2 * beta));
    G = Power(alpha, 4) * c +
4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +
4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4];
    plot Line = G;
}

#My Standard Chart Colors
# Modified MACD
def MACD_Value = g(length = fastLength) - g(length = slowLength);
def MACD_Avg = g(price = MACD_Value, length = MACDLength);
def Diff = MACD_Value - MACD_Avg;

def PositiveUp   = MACD_Value > MACD_Value[1] and MACD_Value > MACD_Avg ;
def NegativeUp   = MACD_Value < MACD_Value[1] and MACD_Value > MACD_Avg ;
def NegativeDown = MACD_Value < MACD_Value[1] and MACD_Value < MACD_Avg ;
def PostiveDown  = MACD_Value > MACD_Value[1] and MACD_Value < MACD_Avg ;

plot Buy_scan = MACD_value < 0 and MACD_value >= MACD_value[1] and MACD_Value crosses above MACD_Avg ;
plot Sell_scan =  MACD_value < MACD_avg and MACD_value < MACD_value[1] ;
Buy_scan.Hide();
Sell_scan.Hide();
plot Buy_signal = if Buy_scan and !Buy_scan[1] then MACD_value else double.NaN  ;
Buy_signal.SetPaintingStrategy(PaintingStrategy.LINE_Vs_poINTS);
Buy_signal.SetDefaultColor(color.cyan) ;
Buy_signal.SetLineWeight(5);
plot sell_signal = if sell_scan and !sell_scan[1] then MACD_value else double.NaN  ;
sell_signal.SetPaintingStrategy(PaintingStrategy.LINE_Vs_poINTS);
sell_signal.SetDefaultColor(color.magenta) ;
sell_signal.SetLineWeight(5);

# ########################################################
# Charting and Formatting
DefineGlobalColor("Pre_Cyan", CreateColor(50, 200, 255)) ;
DefineGlobalColor("LabelGreen",  CreateColor(0, 165, 0)) ;

input ShowLabels = yes ;
AddLabel(ShowLabels,
if buy_scan then "Begin" else
if sell_scan and !sell_scan[1] then "End" else
if PositiveUp then "👍 " + Round(Diff, 1) else
if PostiveDown then "👍 " + Round(Diff, 1) else
if NegativeUp then "Chg'g " + Round(Diff, 1) else
if NegativeDown then "👎 " + Round(Diff, 1) else " ");
AssignBackgroundColor(
if buy_scan then color.cyan else
if sell_scan and !sell_scan[1] then color.magenta else
if PositiveUp then CreateColor(50, 200, 255) else
if PostiveDown then CreateColor(0, 165, 0) else
if NegativeUp then Color.gray else
if NegativeDown then Color.RED else
 Color.GRAY);
Thanks a lot for the hard work and the other inputs throughout the site, it's greatly appreciated. Is there a way to change the watchlist script from white to black?
 
Thanks a lot for the hard work and the other inputs throughout the site, it's greatly appreciated. Is there a way to change the watchlist script from white to black?
There is green, red, and gray but no white to change to black?
 
MACD settings to Imitate Squeeze Indicator?

I was just wondering if anyone has ever figured out if there are MACD settings that imitate the momentum bars on the TTM Squeeze indicator?

Thanks!
 
Last edited by a moderator:
@Britt95 if you are referring to MACD Histogram Colors to match TTM_Squeeze colors then here is the code for that.

Ruby:
#MACD_Custom
#Just changed the Histogram colors to match TTM
declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
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.CYAN);
Diff.DefineColor("Positive and Down", Color.BLUE);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.YELLOW);
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);
 
How do you code to put arrows on my charts to show when MACD has crossed above and below the MACD zeroline?
 
How can I make a label turn green when RSI goes over 56 and MACD crosses over the zeroline with Value line being over Avg line and DMI crosses over the 25 with DI+ over DI-

And turn red when RSI is under 56, and MACD crosses under zero line with Value line under Avg line , and DMI DI+ cross below 25?
 
Last edited:
How can I make a label turn green when RSI goes over 56 and MACD crosses over the zeroline with Value line being over Avg line and DMI crosses over the 25 with DI+ over DI-

And turn red when RSI is under 56, and MACD crosses under zero line with Value line under Avg line , and DMI DI+ cross below 25?

to compare several signals, you create formulas to read the desired data.
then use other formulas to compare them.
finally, check several conditions , by combing them in a formula with AND.

you can find the original study and copy the nessesary code.
or read data from a study by referencing the study name and the plot name.
. ex. macd_value = reference macd().value;
. if no parameters are used, the defaults are used.

he is a study to check for a 'green' condition.


if one or more 'crosses above' conditions are used along with others, it may be highly unlikely that all signals are true at the same time. all the conditions use > , none use crosses above.

there are 2 formulas for , MACD crosses over the zeroline
this one is used, using a >
. def macdup = (macd_value > macd_zero);

i didn't see any green signals when i used this formula, so i disabled it
#def macdup = (macd_value crosses above macd_zero);


Ruby:
# compare_multi_rsi_macd_dmi_00

# ---RSI---------------------------------
input rsi_len = 14;
input rsi_obot = 70;
input rsi_osld = 30;
input rsi_price = close;
input rsi_averagetype = AverageType.wilders;

def rsi_rsi = reference rsi(
  length = rsi_len ,
  overbought = rsi_obot ,
  oversold = rsi_osld ,
  price = rsi_price ,
  averagetype = rsi_averagetype
).rsi;

# if using all default parameters, use this
#def rsi_rsi = reference rsi().rsi;

# ---MACD---------------------------------
input macd_fast = 12;
input macd_slow = 26;
input macd_len = 9;
input macd_averagetype = AverageType.EXPONENTIAL;

def macd_value = reference macd( fastlength = macd_fast , slowlength = macd_slow , macdlength = macd_len , averagetype = macd_averagetype ).value;
def macd_avg = reference macd( fastlength = macd_fast , slowlength = macd_slow , macdlength = macd_len , averagetype = macd_averagetype ).avg;
def macd_diff = reference macd( fastlength = macd_fast , slowlength = macd_slow , macdlength = macd_len , averagetype = macd_averagetype ).diff;
def macd_zero = reference macd( fastlength = macd_fast , slowlength = macd_slow , macdlength = macd_len , averagetype = macd_averagetype ).zeroline;

# ---DMI---------------------------------

input dmi_len = 14;
input dmi_averagetype = AverageType.wilders;

def dmi_diplus = reference dmi( length = dmi_len , averagetype = dmi_averagetype )."di+";
def dmi_diminus = reference dmi( length = dmi_len , averagetype = dmi_averagetype )."di-";
def dmi_adx = reference dmi( length = dmi_len , averagetype = dmi_averagetype ).adx;

# ==================================

#  make a label turn green when,
# ---------------------
# 1.  RSI goes over 56
input rsi_up_level = 56;
def rsiabovelevel = rsi_rsi > rsi_up_level;

# ---------------------
# 2.  MACD crosses over the zeroline
def macdup = (macd_value > macd_zero);

# didn't see any green signals with this formula used and prev one disabled
#def macdup = (macd_value crosses above macd_zero);

# ---------------------
# 3.  with MACD Value line being over Avg line
def macdabove = (macd_value > macd_avg);

# ---------------------
# 4.  DMI crosses over the 25
input dmi_level = 25;
def dmiadxabove = (dmi_adx > dmi_level);

# ---------------------
# 5.  with DI+ over DI-
def dmiplusabove = (dmi_diplus > dmi_diminus);

# ---------------------

def green = (rsiabovelevel and macdup and macdabove and dmiadxabove and dmiplusabove);

#addlabel(green, "up signals", color.green);
addlabel(1, (if green then "up signals" else "----"), (if green then color.green else color.gray));


input test1 = no;
addchartbubble(test1, low*0.97,
 rsiabovelevel + " rsi" + "\n" +
 macdup + " macd" + "\n" +
 macdabove + " macd" + "\n" +
 dmiadxabove + " dmi" + "\n" +
 dmiplusabove + "dmi"
, (if green then color.green else color.gray), no);


#And turn red when RSI is under 56, and MACD crosses under zero line with Value line under Avg line , and DMI DI+ cross below 25?
#

https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/M-N/MACD
 
is there a way to plot a horizontal line when a specific condition is met? For example, i want to draw a line connecting High of candle when MACD value crosses above avg to high of candle when MACD value crosses below AVG ( this just helps me visualize divergence in MACD). like shown below:
Thank you :)
SQj0Mgm.png
 
Last edited by a moderator:
is there a way to plot a horizontal line when a specific condition is met? For example, i want to draw a line connecting High of candle when MACD value crosses above avg to high of candle when MACD value crosses below AVG ( this just helps me visualize divergence in MACD). like shown below:
Thank you :)
SQj0Mgm.png
What "average" do you speak of?
 

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