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

Hello. I was wondering if there was a way we can have a MACD watchlist column when the value is greater than the average it turn green and vice versa red...thanks!!!
 

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

@maxthe300th Where you input your script for the watchlist column:

gFLsaBx.png
 
Can someone remove the "clouds" that are behind this indicator?

Code:
declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input showBreakoutSignals = yes;
input ma_length = 21; #Length(180-200 for floating S/R , 55 for swing entry)


# Four Pole Filter
script g {
    input length = 4;
    input betaDev = 2;
    input price = OHLC4;
    def c;
    def w;
    def beta;
    def alpha;
    def G;
    c = price;
    w = (2 * Double.Pi / length);
    beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDev) - 1 );
    alpha = (-beta + Sqrt(beta * beta + 2 * beta));
    G = Power(alpha, 4) * c +
4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +
4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4];
    plot Line = G;
}
# Modified MACD
plot MACD_Value = g(length = fastLength) - g(length = slowLength);
MACD_Value.Hide();
plot MACD_Avg = g(price = MACD_Value, length = MACDLength);
MACD_Avg.Hide();
addCloud(MACD_Value, MACD_Avg, Color.GREEN, Color.RED);

plot Diff = MACD_Value - MACD_Avg;
plot ZeroLine = 0;

MACD_Value.SetDefaultColor(GetColor(1));
MACD_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(4));
ZeroLine.HideTitle();

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);
Upsignal.SetLineWeight(3);
DownSignal.SetHiding(!showBreakoutSignals);
Downsignal.SetLineWeight(3);

UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.HideTitle();
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.HideTitle();

# Forward / Reverse EMA
# (c) 2017 John F. Ehlers
# Ported to TOS 07.16.2017
# Mobius

# Inputs:
input AA = .1;

# Vars:
def CC;
def RE1;
def RE2;
def RE3;
def RE4;
def RE5;
def RE6;
def RE7;
def RE8;
def EMA;
plot EMA_Signal;
plot plot0;

CC = if CC[1] == 0 then .9 else 1 – AA;
EMA = AA * close + CC * EMA[1];
RE1 = CC * EMA + EMA[1];
RE2 = Power(CC, 2) * RE1 + RE1[1];
RE3 = Power(CC, 4) * RE2 + RE2[1];
RE4 = Power(CC, 8) * RE3 + RE3[1];
RE5 = Power(CC, 16) * RE4 + RE4[1];
RE6 = Power(CC, 32) * RE5 + RE5[1];
RE7 = Power(CC, 64) * RE6 + RE6[1];
RE8 = Power(CC, 128) * RE7 + RE7[1];

EMA_Signal = EMA – AA * RE8;
EMA_Signal.AssignValueColor(if EMA_Signal > EMA_Signal[1]
                        then Color.GREEN
                        else Color.RED);
EMA_Signal.SetLineWeight(3);

plot0 = if IsNaN(close) then Double.NaN else 0;
plot0.SetDefaultColor(Color.GRAY);
plot0.HideTitle();



# Multi-moving average Component

#input length = 14; #hint Length: Number of periods to average the data.
input movingAverageType = {default "Simple MA", "Exponential MA", "Wilders Smoothing", "Weighted MA", "Hull MA", "Adaptive MA", "Triangular MA", "Variable MA", "Dema MA", "Tema MA", "EHMA", "THMA"};
input displace = 0;

def avg_MACD_Value = ExpAverage(2 * ExpAverage(MACD_Value, ma_length / 2) - ExpAverage(MACD_Value, ma_length), Round(Sqrt(ma_length)));
def avg_MACD_Avg = ExpAverage(2 * ExpAverage(MACD_Avg, ma_length / 2) - ExpAverage(MACD_Avg, ma_length), Round(Sqrt(ma_length)));

plot X;
X.SetDefaultColor(CreateColor(0, 102, 204));
X.SetLineWeight(3);
plot Y;
Y.SetDefaultColor(Color.WHITE);
Y.SetLineWeight(3);

switch (movingAverageType) {
case "Simple MA":
X = Average(MACD_Value, ma_length);
Y = Average(MACD_Avg, ma_length);

case "Exponential MA":
X = ExpAverage(MACD_Value, ma_length);
Y = ExpAverage(MACD_Avg, ma_length);

case "Wilders Smoothing":
X = WildersAverage(MACD_Value, ma_length);
Y = WildersAverage(MACD_Avg, ma_length);

case "Weighted MA":
X = wma(MACD_Value, ma_length);
Y = wma(MACD_Avg, ma_length);

case "Hull MA":
X = HullMovingAvg(MACD_Value, ma_length);
Y = HullMovingAvg(MACD_Avg, ma_length);

case "Adaptive MA":
X = MovAvgAdaptive(MACD_Value, ma_length);
Y = MovAvgAdaptive(MACD_Avg, ma_length);

case "Triangular MA":
X = MovAvgTriangular(MACD_Value, ma_length);
Y = MovAvgTriangular(MACD_Avg, ma_length);

case "Variable MA":
X = VariableMA(MACD_Value, ma_length);
Y = VariableMA(MACD_Avg, ma_length);

case "Dema MA":
X = DEMA(MACD_Value, ma_length);
Y = DEMA(MACD_Avg, ma_length);

case "Tema MA":
X = TEMA(MACD_Value, ma_length);
Y = TEMA(MACD_Avg, ma_length);

case EHMA:
X = ExpAverage(2 * ExpAverage(MACD_Value, ma_length / 2) - ExpAverage(MACD_Value, ma_length), Round(Sqrt(ma_length)));
Y = ExpAverage(2 * ExpAverage(MACD_Avg, ma_length / 2) - ExpAverage(MACD_Avg, ma_length), Round(Sqrt(ma_length)));

case THMA:
X = WMA(WMA(MACD_Value, (ma_length / 2) / 3) * 3 - WMA(MACD_Value, (ma_length / 2) / 2) - WMA(MACD_Value, (ma_length / 2)), (ma_length / 2));
Y = WMA(WMA(MACD_Avg, (ma_length / 2) / 3) * 3 - WMA(MACD_Avg, (ma_length / 2) / 2) - WMA(MACD_Avg, (ma_length / 2)), (ma_length / 2));
}
;
 
Last edited by a moderator:
Go to line 34 in the code and remove the following:

Code:
addCloud(MACD_Value, MACD_Avg, Color.GREEN, Color.RED);
 
Can anyone create a scanner that uses the MACD histogram crossover with the settings 12,26,9 and also 3,10,16 on Thinkorswim.
 
@BenTen of course i've tried this...but both don't work at the same time. I think this could be a very good indicator for intraday trading when both upsignals overlap each other. This worked for me on friday when i tested out the method and allowed me to have a decent green day. But i had to manually find the stocks with both macd settings of 12,26,19 and 3,10,16 upsignals to achieve my profits that day.

I don't normally use the one minute time frame to trade due to the noise but mostly the 5 minute. But i noticed a pattern a week ago. Whenever the 12,26,9 MACD settings and the 3,10,16 align with the upsignal. There seems to be a confirmation to buy like no other that i have come across. The reason the 3,10,16 is used is because after reading Tim Sykes comments about the MACD it works well with intraday trading.Here you go. Try this strategy with other stocks that are mainly above the vwap and uptrending and you will see.

Screen-Shot-2020-06-07-at-5-34-22-PM.png
 
@9ramone7 Here you go, use this with your scanner:

Code:
# Double MACD Signals
# Assembled by BenTen at useThinkScript.com
# Based on the request of 9ramone7

declare lower;

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

input fastLength2 = 3;
input slowLength2 = 10;
input MACDLength2 = 16;

input averageType = AverageType.EXPONENTIAL;

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

def Value2 = MovingAverage(averageType, close, fastLength2) - MovingAverage(averageType, close, slowLength2);
def Avg2 = MovingAverage(averageType, Value, MACDLength2);

def Diff = Value - Avg;
def Diff2 = Value2 - Avg2;
def ZeroLine = 0;

def UpSignal1 = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
def DownSignal1 = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

def UpSignal2 = if Diff2 crosses above ZeroLine then ZeroLine else Double.NaN;
def DownSignal2 = if Diff2 crosses below ZeroLine then ZeroLine else Double.NaN;

plot UpSignal = UpSignal1 and UpSignal2;
plot DownSignal = DownSignal1 and DownSignal2;

UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 
@BenTen you rock man...appreciate you taking the time out of your day to help out the community. It seems like its still missing certain arrows. If you kindly look at the image its missing the upsignal between 11:30AM and 12PM.

Screen-Shot-2020-06-07-at-8-17-17-PM.png
 
Last edited:
@BenTen I uploaded another picture for clarity. The upsignals circled in BLUE give the correct overlapping signals for my buy signals.
However, the signals circled in RED apparently is three candles apart even though it gives an upsignal incorrectly.
Then the final one circled in YELLOW is missing the upsignal for some reason

Screen-Shot-2020-06-07-at-9-02-42-PM.png
 
Last edited:
Hoping this is simple. Is it possible to scan for stocks that where the MACD is at it's lowest level of the day? I like using the WeeklyandDailyMACD from ToS. What type of scan can I do to find stocks that are X points apart on the 2 moving averages? I can't upload my pic for some reason, but I simply want to scan for stocks where the 2 moving averages are most divergent. Thanks
 
i cant seem to code this for some reason. any ideas. ive added a alert when the arrow comes in but its not working

Code:
input fastLength = 3;
input slowLength = 6;
input MACDLength = 8;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = yes;


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);
 
Not sure if this is what you're trying to achieve but it's working when I use your code as a lower study on GDX at the moment... I get Dings and TOS Messages... Lots of Dings... Try adding these lines to the bottom of your study... Edit it to display whatever message you prefer... I set it to Alert.ONCE because Alert.TICK was too noisy...

Code:
Alert(Diff crosses above ZeroLine, "Diff Above ZeroLine", Alert.ONCE, Sound.Ding);
Alert(Diff crosses below ZeroLine, "Diff Below ZeroLine", Alert.ONCE, Sound.Ding);
 
here is what i got but the word alert is red
Alert (Diff > ZeroLine, Alert.BAR, Sound.RING);
You are missing the alert text... I don't think it can be omitted...
Code:
Alert (Diff > ZeroLine, "Something or Anything Here, or just empty quotes", Alert.BAR, Sound.RING);

Edited to add: Minimum function parameters are condition and text...
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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