MACD High Variable

shockwave

New member
Good morning all, I'm trying to figure out how to call out the high of the period of time between when the MACD crosses under the signal line and when it crosses back above. I'm in IT and have scripting history so can do this logically just can transfer that into ThinkScript without some help. The end-state here is to create a scanner that tells me when the current price action is within a few percent of that so I can pull up that chart. Thanks in advance!
 
Good morning all, I'm trying to figure out how to call out the high of the period of time between when the MACD crosses under the signal line and when it crosses back above. I'm in IT and have scripting history so can do this logically just can transfer that into ThinkScript without some help. The end-state here is to create a scanner that tells me when the current price action is within a few percent of that so I can pull up that chart. Thanks in advance!

hello and welcome,

MACD doesn't have a signal , or a macd plot.
programming is specific. please review the MACD study code and restate your question, using actual parameters/plots used in the study.
https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/M-N/MACD

what is 'high of the period' ? highest high of period?

call out the high of the period of time between when the MACD crosses under the signal line and when it crosses back above
do you mean ,
define a period, between when macd().value crosses below macd().avg until it crosses back above the avg
within this period of bars, find the highest high,
( so when histo is red )
when a cross below happens, run a loop to look at future bars and find the highest high

---------------------------------------


take a look at this modified MACD and see if it is close
draws vertical lines

Code:
#macd_period_middle

#https://usethinkscript.com/threads/macd-high-variable.19613/
#MACD High Variable

# call out the high of the period of time
# between when
# the MACD crosses under the signal line
# and when it crosses back above.


# MACD
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 na = double.nan;
def bn = barnumber();

# max bars between crossings
def n = 200;

def xup = value crosses above avg;
def xdwn = value crosses below avg;

# when a cross down happens, find highest high, during a period
def hihi;
def hibn;
#def lo;
if bn == 1 then {
 hihi = 0;
 hibn = 0;
#} else if xup then {
# hihi = 0;
# hibn = 0;
} else if xdwn then {
 # find highest high between crossings
 hihi = fold a = 1 to n
    with b
 # loop until a cross up
    while getvalue(xup, -a) == 0
    do max(b, getvalue(high, -a));

# find the highest high and read the barnumber
 hibn = fold c = 1 to n
    with d
    while getvalue(xup, -c) == 0
    do if hihi == getvalue(high,-c) then getvalue(bn,-c) else d;

} else {
 hihi = hihi[1];
 hibn = hibn[1];
}

# draw vert line on the highest high, during macd period
addverticalline(bn == hibn, "-");
#
 

Attachments

  • img1.JPG
    img1.JPG
    80.1 KB · Views: 53
Last edited:

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