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

I am sure this has been asked before (please provide me a link or where to look). Where can I find a scan when both lines cross 0. Thanks in Advance.
 
I am sure this has been asked before (please provide me a link or where to look). Where can I find a scan when both lines cross 0. Thanks in Advance.
Using the built-in study MACDTwoLines scan for value crosses 0 and avg crosses 0
 
There is an error that says "Exactly one plot expected", what do I do here?
I am not seeing an error. I do see that you will seldom get results. For any indicator to be exactly equal to its average and for them both to be crossing any point would be a blue moon event:
QnndZB8.png
 
I am not seeing an error. I do see that you will seldom get results. For any indicator to be exactly equal to its average and for them both to be crossing any point would be a blue moon event:
QnndZB8.png

When adding the custom script, that is where I am getting the error. Could you send me the script.
 
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:
I'm trying this for a watchlist code for MACD Crossover, but can't get it to work correctly.

Def fastlength = 12;

Def slowlength = 26;

Def MACDLength = 9;

Def averageType = AverageType.Exponential;

Def showBreakoutSignals = no;

Def ZeroLine = 0;

Plot Value = Moving Average (averageType, close, fastlength) – MovingAverage (averageType, close, slowLength);

Plot Avg = MovingAverage (averageType, Value, MACDLength);

Plot Diff = Value – Avg;

Addlabel (yes,

If value >= zeroline and avg >= zeroline and value crosses below avg within 3 bars then “Cross OB”

Else if

Value <= zeroline and avg <= zeroline and value crosses above avg within 3 bars then “Cross OS”

Else if

Value >= zeroline and avg >= zeroline and value > avg then “Bull Acc”

Else if

Value >= zeroline and avg >= zeroline and value <avg then “Bull Dec”

Else if

Value <= zeroline and avg <= zeroline and value < then “Bear Acc”

Else if <= zeroline and avg <= zeroline and value > avg then “Bear Dec”
 
Hello everyone,

Thanks for the help in advance. What I am attempting to do is probably simple, and much of the codes I see on here seem complex, but I didn't see anything close to what I am trying to do. What I would like to do is plot an arrow on the chart that is base on when the MACD histogram turns from bright green to dark green. The arrow will plot on the chart on the candle that formed a dark green bar on the MACD histogram. It will only plot when this happens. I want it to be able to plot no matter which timeframe I am using. It will plot the same way on those bars only. Below is a link with a picture of what I am saying... any help will be greatly appreciate it!

30MIN Example: https://ibb.co/yS2h86Z
1HR Example: https://ibb.co/fknsSjK
4HR Example: https://ibb.co/mbg6DvQ
 
anyone have a think or swim script for this type of supply and demand indicator it starts in the video at 6:30 min the one
basically it changes the color of the candle from red or green to yellow thank you in advance for the help
 
Hello everyone,

Thanks for the help in advance. What I am attempting to do is probably simple, and much of the codes I see on here seem complex, but I didn't see anything close to what I am trying to do. What I would like to do is plot an arrow on the chart that is base on when the MACD histogram turns from bright green to dark green. The arrow will plot on the chart on the candle that formed a dark green bar on the MACD histogram. It will only plot when this happens. I want it to be able to plot no matter which timeframe I am using. It will plot the same way on those bars only. Below is a link with a picture of what I am saying... any help will be greatly appreciate it!

30MIN Example: https://ibb.co/yS2h86Z
1HR Example: https://ibb.co/fknsSjK
4HR Example: https://ibb.co/mbg6DvQ

here is a study will will draw arrows for each of the 4 colors. each can be turned on or off.
i put comments in the code, describing what i did.


Ruby:
# MACDHisto_arrows

#  plot an arrow on the chart, when the MACD histogram turns from bright green to dark green

#-------------------------------------------------
def na = double.nan;

# copy the MACDHistogram code and remove most of it

# change plot to def
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
#plot Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
def Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
#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"));

# -------------------------
# restucture AssignValueColor() formula, so it is easier to read.

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

# then create separate formulas for each color

def green1 = if Diff >= 0 and Diff > Diff[1] then 1 else 0;
def darkgreen1 = if Diff >= 0 and Diff < Diff[1] then 1 else 0;
def red1 =  if Diff < 0 and Diff < Diff[1] then 1 else 0;
def darkred1 =  if Diff < 0 and Diff > Diff[1] then 1 else 0;

input show_first_green_arrow = yes;
input show_first_darkgreen_arrow = yes;
input show_first_red_arrow = yes;
input show_first_darkred_arrow = yes;

def vert = 0.003;
def top = high * (1 + vert);
def bot = low * (1 - vert);

# create formulas to find the first of a color

plot arrow_gr = if show_first_green_arrow and green1 and !green1[1] then bot else na;
plot arrow_drkgr = if show_first_darkgreen_arrow and darkgreen1 and !darkgreen1[1] then top else na;
plot arrow_rd = if show_first_red_arrow and red1 and !red1[1] then top else na;
plot arrow_drkrd = if show_first_darkred_arrow and darkred1 and !darkred1[1] then bot else na;

arrow_gr.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
arrow_gr.SetDefaultColor(Color.green);
arrow_gr.setlineweight(2);
arrow_drkgr.SetPaintingStrategy(PaintingStrategy.ARROW_down);
arrow_drkgr.SetDefaultColor(Color.dark_green);
arrow_drkgr.setlineweight(2);
arrow_rd.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
arrow_rd.SetDefaultColor(Color.red);
arrow_rd.setlineweight(2);
arrow_drkrd.SetPaintingStrategy(PaintingStrategy.ARROW_up);
arrow_drkrd.SetDefaultColor(Color.dark_red);
arrow_drkrd.setlineweight(2);
#
 
Not sure why TOS decided to not have an option to show the value to avg crossover signal on MACD, here ya go
Screenshot_201.png


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 Value crosses above Avg then Avg else Double.NaN;
plot DownSignal = if Value crosses below Avg then Avg 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.POINTS;
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.POINTS);
 
@raymasa Actually, I was bored and curiosity got the best of me so I coded a replica based off the standard TOS MACD indicator... I never checked to see whether a comparable script might already be posted here in the forums... It didn't take long considering how my initial reply was only about 1H 15m ago, and I did a few other things along the way... Just goes to show how easy code can be tweaked with very little effort...

Ruby:
# MACD_with_Signals_and_ColorBars
# Adapted from Tradingview MACD_with_Signals
# https://www.tradingview.com/script/ETBoNc7O-MACD-with-Signals/
# Based on TOS MACD with additional features
# TD Ameritrade IP Company, Inc. (c) 2007-2021
# Created by rad14733 for usethinkscript.com
# v1.0 : 2021-02-25 : Initial release

declare lower;

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

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

plot UpSignal = if Diff crosses above 0 then 0 else Double.NaN;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetLineWeight(2);
UpSignal.SetHiding(!showBreakoutSignals);

plot DownSignal = if Diff crosses below 0 then 0 else Double.NaN;
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.SetLineWeight(2);
DownSignal.SetHiding(!showBreakoutSignals);

plot Value = MACD(fastLength, slowLength, MACDLength, averageType).Value;
Value.SetDefaultColor(Color.CYAN);
Value.DefineColor("UpTrend", Color.CYAN);
Value.DefineColor("DownTrend", Color.MAGENTA);
Value.AssignValueColor(if Value > Value[1] then Value.color("UpTrend") else if Value < Value[1] then Value.color("DownTrend") else Color.CURRENT);
Value.SetLineWeight(2);

plot Avg = MACD(fastLength, slowLength, MACDLength, averageType).Avg;
Avg.SetDefaultColor(Color.DARK_ORANGE);
Avg.SetLineWeight(1);

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.WHITE);
ZeroLine.SetLineWeight(1);

AssignPriceColor(if colorChartBars then 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") else Color.CURRENT);

# END - MACD_with_Signals_and_ColorBars

pS18n1I.png
Rad this is great work !!! I would like to make a watchlist that would label the Value of MACD with a background color of blue when up and magenta when going down like you have on above on the MACD. How would i go about that please ?
 
Good afternoon,
Trying to use the wizard in the scan area to look for where MACD is greater than or equal to MACD Signal, but can't find the signal value in the dropdowns. Any suggestions on how to do this?
 
Is there a way to create a watchlist for MACD for when the signal line crosses the zero line? To be clear, I'm talking about the two moving lines of the MACD that ToS labels as AVG and DIFF. This is where it shows the buy signals, which is what I want to show up in the watchlist column. I'm not looking for when either line crosses the purple horizontal line labeled zero on the chart. I want the coding for the buy signals/sell signals to show up in a watchlist. That would work far better than having to pick them off from a scanner or limiting yourself to just a few stocks. Maybe color code it with green for the buy signals, yellow for the neutral signals, and red for the sell signals.
 
Good afternoon,
Trying to use the wizard in the scan area to look for where MACD is greater than or equal to MACD Signal, but can't find the signal value in the dropdowns. Any suggestions on how to do this?
Here is your scan using the ToS Indicator MACDTwoLines. No custom study needed. Just load the link.
Shared Scan Link: http://tos.mx/rjv6fVZ Click here for --> Easiest way to load shared links
jITShEo.png
 
Last edited:
It's a simple label that shows: uptrend, downtrend, trending up, and trending down based on the MACD indicators you input for slow, fast, and MACD. If the diff is below the zero line and going down its "downtrend", if its below the zero line and coming up its "trending up", if its above the zero line and trending up its "uptrend" and if its above the zero line and making lower lows its "trending down". One less chart swapped for a label.

uptrend.png

trending-up.png

Rich (BB code):
declare lower;

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

def MA = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def A = MovingAverage(averageType, MA, MACDLength);
def dif = MA - A ;

Addlabel( yes, if Dif >= 0 then if Dif > Dif[1] then "UPTREND" else "TRENDING DOWN" else if Dif < Dif[1] then " DOWNTREND " else " TRENDING UP ", if Dif >= 0 then if Dif > Dif[1] then color.green else color.lIGHT_RED else if Dif < Dif[1] then color.red else color.lIGHT_GREEN);
 
Hey all,

I'm really really REALLY new to thinkscript and I'm trying to set an alert. I've been playing around with the existing TOS script for MACD crossovers.

But I'd like to have TOS also ding an alert when the AVG or VALUE line goes below the zeroline (see below in BOLD). It didn't work (DUH or I wouldn't be here :) so I'm asking this wonderful and smart community for some help.

Any thoughts?

Thanks!

PJ



#
# TD Ameritrade IP Company, Inc. (c) 2007-2017
#
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);
Alert(UpSignal >= ZeroLine, "Up Arrow Alert", Alert.BAR, Sound.BELL);
Alert(DownSignal < ZeroLine, "Down Arrow Alert", Alert.BAR, Sound.BELL);
Alert(Avg < ZeroLine, "red cross down", Alert.BAR, Sound.BELL);
Alert(Value < ZeroLine, "green cross down", Alert.BAR, Sound.BELL);
 
Hey all,

I'm really really REALLY new to thinkscript and I'm trying to set an alert. I've been playing around with the existing TOS script for MACD crossovers.

But I'd like to have TOS also ding an alert when the AVG or VALUE line goes below the zeroline (see below in BOLD). It didn't work (DUH or I wouldn't be here :) so I'm asking this wonderful and smart community for some help.

Code:
Alert(Avg crosses below ZeroLine, "red cross down", Alert.BAR, Sound.BELL);

Alert(Value crosses below ZeroLine, "green cross down", Alert.BAR, Sound.BELL);
Given these bearish times, your alerts should have been alerting all day long because your logic states alert when avg or value are less than zero.
If you weren't getting any alerts. Read more about how to use alerts:
https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-58010

If you only want alerts when they cross below zero, this would be the syntax:
Ruby:
Alert(Avg crosses below ZeroLine, "red cross down", Alert.BAR, Sound.BELL);
Alert(Value crosses below ZeroLine, "green cross down", Alert.BAR, Sound.BELL);
 
Here is your scan using the ToS Indicator MACDTwoLines. No custom study needed. Just load the link.
Shared Scan Link: http://tos.mx/rjv6fVZ Click here for --> Easiest way to load shared links
jITShEo.png



This is not quite it.
I am looking for the crossover up or down of the two MACD lines, that I can get in a scan query. I am not seeing that in the replies to my original question. I am not looking for greater than or less than, I am looking for the day when the cross over happens, so there has to be an evaluation of the prior day. Any luck finding what you are looking for.
 

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