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

Can anyone provide a cloud script using MACD weighted avg like the example, in picture green macd cloud when up and red macd when the cross down.

picture__5.png
 

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

Can anyone provide a cloud script using MACD weighted avg like the example, in picture green macd cloud when up and red macd when the cross down.

picture__5.png

Here is the TOS MACD using a weighted average, with a cloud and DIff and Zero plots not showing

Capture.jpg
Ruby:
# TD Ameritrade IP Company, Inc. (c) 2007-2022
#

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.WEIGHTED;
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);

AddCloud(Value, Avg, color1 = Color.GREEN);
 
Hello! I am new to using think script but I was wondering if anyone can help me out. So I am trying to have the first candle in which MACD crosses over to turn to a certain color. I've found code that changes the candle color and keeps that same color constant throughout the trend until MACD crosses over again but I just want the first candle at crossover to turn a different color. Any and all help is very much appreciated! Thanks in advance!
 
@Jayabner
Ruby:
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;

def Value = MACD(fastLength, slowLength, MACDLength, averageType).Value;
def Avg = MACD(fastLength, slowLength, MACDLength, averageType).Avg;

AssignPriceColor(if crosses(Value,Avg,CrossingDirection.ANY) then Color.DARK_ORANGE else Color.CURRENT);
 
Hi Everyone,

I’m not sure if this can be done, but is there a screener where you can screen stocks using MACD to find where upward momentum is increasing (and conversely, downward momentum is decreasing)?
 
Hi, possible to draw the macd in the main chart? the values might be too small compared to most of the stock prices, possible to make macd to display even with zooming? thx

any way to overlap two charts with diff scales? I remember there was an overlapping with vol , but nice to have it for any indicators like macd
 
Last edited by a moderator:
any way to overlap two charts with diff scales? I remember there was an overlapping with vol , but nice to have it for any indicators like macd
You can drag your MACD indicator to the upper chart.
As you pointed out, it will be a failure due to the scaling issues.

I don't see how, you would overcome the scaling issues.
 
Hi there, I have the code for a crossover between the emas in the MACD lower chart; however I was wondering if it may be enhanced by saying: 'show an arrow when the EMA's have crossed over AND the Value line has crossed above the Zeroline or is already above Zeroline'

Same Idea for the down arrow: 'show a down arrow when the emas have crossed and Value line has crossed below or is below ZeroLine'

So this is the starting code:
Code:
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);

def SignalUP = Value[1] < Avg[1] and Value > Avg;
def SignalDown = Value[1] > Avg[1] and Value < Avg;

plot ArrowUp = if SignalUP then Avg
               else double.nan;
     ArrowUP.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
     ArrowUP.SetLineWeight(3);
     ArrowUP.SetDefaultColor(Color.PINK);
plot ArrowDN = if SignalDown then Avg
               else double.nan;
     ArrowDN.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
     ArrowDN.SetLineWeight(3);
     ArrowDN.SetDefaultColor(Color.Yellow);
AddCloud(Value,Avg,color.green,color.red);


So for Example, right now the chart shows the following arrow but I would rather it show here:

CDPY9nN.png


Another Example would be the following:

15tb7Pb.png


Thank you for anyone's help - I came on here because I really couldn't figure out the entire ask I had.
 
Last edited by a moderator:
Hi there, I have the code for a crossover between the emas in the MACD lower chart; however I was wondering if it may be enhanced by saying: 'show an arrow when the EMA's have crossed over AND the Value line has crossed above the Zeroline or is already above Zeroline'

Same Idea for the down arrow: 'show a down arrow when the emas have crossed and Value line has crossed below or is below ZeroLine'

So this is the starting code:
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); def SignalUP = Value[1] < Avg[1] and Value > Avg; def SignalDown = Value[1] > Avg[1] and Value < Avg; plot ArrowUp = if SignalUP then Avg else double.nan; ArrowUP.SetPaintingStrategy(PaintingStrategy.Arrow_UP); ArrowUP.SetLineWeight(3); ArrowUP.SetDefaultColor(Color.PINK); plot ArrowDN = if SignalDown then Avg else double.nan; ArrowDN.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN); ArrowDN.SetLineWeight(3); ArrowDN.SetDefaultColor(Color.Yellow); AddCloud(Value,Avg,color.green,color.red);


So for Example, right now the chart shows the following arrow but I would rather it show here:

CDPY9nN.png


Another Example would be the following:

15tb7Pb.png


Thank you for anyone's help - I came on here because I really couldn't figure out the entire ask I had.

This redefines signalup/signaldown to be below/above zero line when the value line crosses above/below zero line and value is above/below avg before the cross.

Capture.jpg
Ruby:
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);
def SignalUP = if Value < 0 and Avg < 0 and Value[1] < Avg[1] and Value > Avg
               then 1
               else if Value > 0 or Avg > 0 
               then 0
               else SignalUP[1];
def SignalDown = if Value > 0 and Avg > 0 and Value[1] > Avg[1] and Value < Avg
                 then 1
                 else if Value < 0 and Avg < 0
                 then 0
                 else SignalDown[1];
plot ArrowUp = if SignalUP[1] and Value crosses above 0 then 0
else Double.NaN;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.SetLineWeight(3);
ArrowUp.SetDefaultColor(Color.PINK);
plot ArrowDN = if SignalDown[1] and Value crosses below 0 then 0
else Double.NaN;
ArrowDN.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDN.SetLineWeight(3);
ArrowDN.SetDefaultColor(Color.YELLOW);
AddCloud(Value, Avg, Color.GREEN, Color.RED);
 
This is super close - Thank you so much!

We would want an up arrow : 1) if the emas cross 2) The Value line crosses above the Zero Line OR already above the Zero Line
Down arrow: 1) emas cross 2) Value line crosses below zero line OR already below the Zero line.
Using the snippet above from your post, these two spots would also have arrows:

as8wVoV.png

thank you so much for your help!
 
Hello,

I've modified the MACD for my own needs as shown below. The main objective was to not display the inputs. This was done by replacing "input" with "def".
I was unable to accomplish this with the input averageType = AverageType.Exponential. Any help would be greatly appreciated!
declare lower;

#
# TD Ameritrade IP Company, Inc. (c) 2007-2022
#
#Modified M.S.

def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;

input averageType = AverageType.EMA;

plot Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Dark_GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.DARK_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"));
 
Hello,

I've modified the MACD for my own needs as shown below. The main objective was to not display the inputs. This was done by replacing "input" with "def".
I was unable to accomplish this with the input averageType = AverageType.Exponential. Any help would be greatly appreciated!
declare lower;

#
# TD Ameritrade IP Company, Inc. (c) 2007-2022
#
#Modified M.S.
declare lower;
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;

input averageType = AverageType.EMA;

plot Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Dark_GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.DARK_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"));

This should work for you.

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2022
#
#Modified M.S.

def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;

plot Diff = MACD(fastLength, slowLength, MACDLength, averageType.EXPONENTIAL ).Diff;
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", color.Dark_GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.DARK_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"));
 
Last edited:
This indicator will scan for stocks with bearish and bullish MACD crossover on your watchlist and display it via a column. By default, it will look for crossover within the last 5 bars. You can change the lookback period to your liking in the code below. It works on all timeframe. Be sure to select the timeframe you want when adding the script.

Notes:
  • Orange = Neutral. No crossover within the last X bars
  • Red = Bearish crossover within the last X bars
  • Green = Bullish crossover on MACD within the last X bars
fsstyZX.png


thinkScript Code

Rich (BB code):
# WalkingBallista MACD Lookback Cross
# https://usethinkscript.com/d/191-macd-bullish-bearish-crossover-watchlist-column-for-thinkorswim

declare lower;

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

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

def bull_cross = value crosses above avg;
def bear_cross = value crosses below avg;

def bull_lookback = highest(bull_cross, lookback);
def bear_lookback = highest(bear_cross, lookback);

plot signal = if bull_lookback then 2 else if bear_lookback then 1 else 0;
signal.AssignValueColor(if signal == 2 then Color.Dark_Green else if signal == 1 then Color.Dark_Red else Color.Dark_Orange);
AssignBackgroundCOlor(if signal == 2 then Color.Dark_Green else if signal == 1 then Color.Dark_Red else Color.Dark_Orange);

Shareable Link

https://tos.mx/pFX3vh

9qEjpEk.png


Credit:
This has been very helpful to me. What would make this even better for my situation is to have the ability to work with my time frames. I cant do that with the default drop down menu. I use the weekly, daily, (both of witch are in the dropdown menu) but I need 233, 55,34,,21,13,8,5,2 minute time frames. Can you modify the script to input what ever time frames I need.

Thanks in advance.
 
This has been very helpful to me. What would make this even better for my situation is to have the ability to work with my time frames. I cant do that with the default drop down menu. I use the weekly, daily, (both of witch are in the dropdown menu) but I need 233, 55,34,,21,13,8,5,2 minute time frames. Can you modify the script to input what ever time frames I need.

Thanks in advance.
The ToS platform aggregation periods are pre-defined and limited to:
https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/AggregationPeriod
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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