stocksniper
Member
Can anyone provide a cloud script using MACD weighted avg like the example, in picture green macd cloud when up and red macd when the cross down.
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Can anyone provide a cloud script using MACD weighted avg like the example, in picture green macd cloud when up and red macd when the cross down.
Ruby:# TD Ameritrade IP Company, Inc. (c) 2007-2022 # declare lower; input fastLength = 12; input slowLength = 26; input MACDLength = 9; input averageType = AverageType.WEIGHTED; 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); AddCloud(Value, Avg, color1 = Color.GREEN);
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
def Value = MACD(fastLength, slowLength, MACDLength, averageType).Value;
def Avg = MACD(fastLength, slowLength, MACDLength, averageType).Avg;
AssignPriceColor(if crosses(Value,Avg,CrossingDirection.ANY) then Color.DARK_ORANGE else Color.CURRENT);
You will find several examples in this thread. You should be able to customize one of these to your liking:Hi Everyone,
I’m not sure if this can be done, but is there a screener where you can screen stocks using MACD to find where upward momentum is increasing (and conversely, downward momentum is decreasing)?
You can drag your MACD indicator to the upper chart.any way to overlap two charts with diff scales? I remember there was an overlapping with vol , but nice to have it for any indicators like 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 SignalUP = Value[1] < Avg[1] and Value > Avg;
def SignalDown = Value[1] > Avg[1] and Value < Avg;
plot ArrowUp = if SignalUP then Avg
else double.nan;
ArrowUP.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
ArrowUP.SetLineWeight(3);
ArrowUP.SetDefaultColor(Color.PINK);
plot ArrowDN = if SignalDown then Avg
else double.nan;
ArrowDN.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
ArrowDN.SetLineWeight(3);
ArrowDN.SetDefaultColor(Color.Yellow);
AddCloud(Value,Avg,color.green,color.red);
Hi there, I have the code for a crossover between the emas in the MACD lower chart; however I was wondering if it may be enhanced by saying: 'show an arrow when the EMA's have crossed over AND the Value line has crossed above the Zeroline or is already above Zeroline'
Same Idea for the down arrow: 'show a down arrow when the emas have crossed and Value line has crossed below or is below ZeroLine'
So this is the starting code:
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 SignalUP = Value[1] < Avg[1] and Value > Avg; def SignalDown = Value[1] > Avg[1] and Value < Avg; plot ArrowUp = if SignalUP then Avg else double.nan; ArrowUP.SetPaintingStrategy(PaintingStrategy.Arrow_UP); ArrowUP.SetLineWeight(3); ArrowUP.SetDefaultColor(Color.PINK); plot ArrowDN = if SignalDown then Avg else double.nan; ArrowDN.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN); ArrowDN.SetLineWeight(3); ArrowDN.SetDefaultColor(Color.Yellow); AddCloud(Value,Avg,color.green,color.red);
So for Example, right now the chart shows the following arrow but I would rather it show here:
Another Example would be the following:
Thank you for anyone's help - I came on here because I really couldn't figure out the entire ask I had.
Ruby: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 SignalUP = if Value < 0 and Avg < 0 and Value[1] < Avg[1] and Value > Avg then 1 else if Value > 0 or Avg > 0 then 0 else SignalUP[1]; def SignalDown = if Value > 0 and Avg > 0 and Value[1] > Avg[1] and Value < Avg then 1 else if Value < 0 and Avg < 0 then 0 else SignalDown[1]; plot ArrowUp = if SignalUP[1] and Value crosses above 0 then 0 else Double.NaN; ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP); ArrowUp.SetLineWeight(3); ArrowUp.SetDefaultColor(Color.PINK); plot ArrowDN = if SignalDown[1] and Value crosses below 0 then 0 else Double.NaN; ArrowDN.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); ArrowDN.SetLineWeight(3); ArrowDN.SetDefaultColor(Color.YELLOW); AddCloud(Value, Avg, Color.GREEN, Color.RED);
Hello,
I've modified the MACD for my own needs as shown below. The main objective was to not display the inputs. This was done by replacing "input" with "def".
I was unable to accomplish this with the input averageType = AverageType.Exponential. Any help would be greatly appreciated!
declare lower;
#
# TD Ameritrade IP Company, Inc. (c) 2007-2022
#
#Modified M.S.
declare lower;
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
input averageType = AverageType.EMA;
plot Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Dark_GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.DARK_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"));
Ruby:# # TD Ameritrade IP Company, Inc. (c) 2007-2022 # #Modified M.S. def fastLength = 12; def slowLength = 26; def MACDLength = 9; plot Diff = MACD(fastLength, slowLength, MACDLength, averageType.EXPONENTIAL ).Diff; Diff.SetDefaultColor(GetColor(5)); Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); Diff.SetLineWeight(3); Diff.DefineColor("Positive and Up", color.Dark_GREEN); Diff.DefineColor("Positive and Down", Color.DARK_GREEN); Diff.DefineColor("Negative and Down", Color.DARK_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"));
Nothing appears on the screenThis should work for you.
Try again. The original did not have declare lower; (which I added for you in the above code) in it and I was only answering the question. It is the standard macd histogram.Nothing appears on the screen
This has been very helpful to me. What would make this even better for my situation is to have the ability to work with my time frames. I cant do that with the default drop down menu. I use the weekly, daily, (both of witch are in the dropdown menu) but I need 233, 55,34,,21,13,8,5,2 minute time frames. Can you modify the script to input what ever time frames I need.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:
The ToS platform aggregation periods are pre-defined and limited to:This has been very helpful to me. What would make this even better for my situation is to have the ability to work with my time frames. I cant do that with the default drop down menu. I use the weekly, daily, (both of witch are in the dropdown menu) but I need 233, 55,34,,21,13,8,5,2 minute time frames. Can you modify the script to input what ever time frames I need.
Thanks in advance.
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.