komandante
New member
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 0I 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.
There is an error that says "Exactly one plot expected", what do I do here?Using the built-in study MACDTwoLines scan for value crosses 0 and avg crosses 0
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:There is an error that says "Exactly one plot expected", what do I do here?
MACDTwoLines is not a custom script. Set up the scanner as shown in my above post:When adding the custom script, that is where I am getting the error. Could you send me the script.
I'm trying this for a watchlist code for MACD Crossover, but can't get it to work correctly.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
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
Credit:
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
# 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);
#
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 ?@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
Here is your scan using the ToS Indicator MACDTwoLines. No custom study needed. Just load the link.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?
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);
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.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);
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
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.