Draw Vertical Line for MACD crossover?

JP782

Active member
Im not having much luck with anyone answering any of the questions Ive been asking last couple weeks but Ill try again-

I want to have vertical lines drawn when the MACD crosses, I assumed the script would be similar to the one Im using..

def condM1CrossUndr0 = Value < 0 and Value > Avg;
Addlabel(condM1CrossUndr0, "M1”, Color.Green);

... to add a label when crossover happens: changing "addlabel" to "addverticalline" but of course not - clearly theres more to it, what am I missing?
 
Im not having much luck with anyone answering any of the questions Ive been asking last couple weeks but Ill try again-

I want to have vertical lines drawn when the MACD crosses, I assumed the script would be similar to the one Im using..

def condM1CrossUndr0 = Value < 0 and Value > Avg;
Addlabel(condM1CrossUndr0, "M1”, Color.Green);

... to add a label when crossover happens: changing "addlabel" to "addverticalline" but of course not - clearly theres more to it, what am I missing?

The following script will work in the upper panel as well as the lower.

Capture.jpg
Ruby:
def condM1CrossUndr0 = reference macd().Value < 0 and reference macd().Value > reference
macd().Avg;
Addlabel(condM1CrossUndr0, "M1”, Color.Green);
addverticalLine(condM1CrossUndr0[1]==0 and condm1CrossUndr0,"",color.green);
 
anyway it can be coded where it gives a signal or label if not a vertical line,,, when macd cross and histogram are broth above or under the Zero Line? any assistance would be greatly appreciated
 
anyway it can be coded where it gives a signal or label if not a vertical line,,, when macd cross and histogram are broth above or under the Zero Line? any assistance would be greatly appreciated

Input options to show or not: signals (arrows), alerts, verticallines, bubbles and/or labels.

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

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

def value = MACD(fastLength, slowLength, MACDLength, averageType);
def avg   = MACD(fastLength, slowLength, MACDLength, averageType).Avg;
def Diff  = MACD(fastLength, slowLength, MACDLength, averageType).Diff;

input signal = yes;
plot upsignal = if !signal then Double.NaN else value > 0 and Diff > 0 and value crosses avg;

upsignal.DefineColor("Negative to Positive", Color.GREEN);
upsignal.AssignValueColor(upsignal.Color("Negative to Positive"));
upsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
upsignal.SetLineWeight(3);

plot dnsignal = if !signal then Double.NaN else value < 0 and Diff < 0 and value crosses avg;

dnsignal.DefineColor("Positive to Negative", Color.RED);
dnsignal.AssignValueColor(dnsignal.Color("Positive to Negative"));
dnsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
dnsignal.SetLineWeight(3);

input label =  yes;
AddLabel(label, if upsignal then "(Cross and Histogram) > 0" else "(Cross and Histgram) < 0", if upsignal then Color.GREEN else Color.RED);

input bubbles = yes;
input bubbleoffset = 3;
addchartBubble(bubbles and (upsignal or dnsignal), if upsignal then low - ticksize() * bubbleoffset else high + ticksize() * bubbleoffset, if upsignal then "Up" else "Dn", if upsignal then color.green else color.red, if upsignal then no else yes);

input verticalline = yes;
AddVerticalLine(verticalline and upsignal, "", Color.GREEN, stroke = Curve.LONG_DASH);
AddVerticalLine(verticalline and dnsignal, "", Color.RED, stroke = Curve.LONG_DASH);

input alert = yes;
Alert(alert, if upsignal then "(Cross and Histogram) > 0" else "(Cross and Histgram) < 0", Alert.BAR, Sound.Chimes);
 
maybe i need to try it when market is open,, the label seems to be staying as is,,, even when i switch TF and macd is over 0 line,

Try replacing the label code with this and the label will now only appear on the bar when a signal happens.

Code:
input label =  yes;
AddLabel(label and (upsignal or dnsignal), if upsignal then "(Cross and Histogram) > 0" else if dnsignal then "(Cross and Histgram) < 0" else "", if upsignal then Color.GREEN else Color.RED);
 

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