Multiple timeframe macd histogram.

westsail5000

New member
hey yall hope everyone is having a wonderful holiday season. Im looking for the code that allows me to have multiple different mac/d histograms on different timeframes all on the same chart. Would greatly appreciate any help. thanks!
 
Solution
#Here is a version that I created. It incorporates 2 additional time frames. It is important to adjust the "LengthLT" and "LengthMT" in conjunction with the time frame that you are using otherwise the coloring will not be correct. In other words. The following is setup for a daily chart and a 3 day and weekly MACD shown as well. But if you wanted to use it with say a one minute then a 5 minute midterm chart and a 15 minute long term then set the "LengthLT" to 15, and the "LengthMT" to 5. It is all about taking the LengthLT and LengthMT and dividing them by chart that you are using. If the number comes to a fraction like using a 2 minute chart with a 5 minute midterm and a 15 minute longterm. Then set your LengthMT to 3 instead of 2.5...
#Here is a version that I created. It incorporates 2 additional time frames. It is important to adjust the "LengthLT" and "LengthMT" in conjunction with the time frame that you are using otherwise the coloring will not be correct. In other words. The following is setup for a daily chart and a 3 day and weekly MACD shown as well. But if you wanted to use it with say a one minute then a 5 minute midterm chart and a 15 minute long term then set the "LengthLT" to 15, and the "LengthMT" to 5. It is all about taking the LengthLT and LengthMT and dividing them by chart that you are using. If the number comes to a fraction like using a 2 minute chart with a 5 minute midterm and a 15 minute longterm. Then set your LengthMT to 3 instead of 2.5, and your LengthLT to 8.

declare lower;

input aggregationPeriodLT = AggregationPeriod.Week; #(period = aggregationPeriod)
input LengthLT =5.0;

def fastLengthLT = 12;
def slowLengthLT = 26;
def MACDLengthLT = 9;

def ValueLT = MovingAverage(AverageType.EXPONENTIAL, close (period = aggregationPeriodLT), fastLengthLT) - MovingAverage(AverageType.EXPONENTIAL, close (period = aggregationPeriodLT), slowLengthLT);
def AvgLT = MovingAverage(AverageType.EXPONENTIAL, ValueLT, MACDLengthLT);

Plot DiffLT = ValueLT - AvgLT;
DiffLT.SetDefaultColor(GetColor(5));
DiffLT.SetPaintingStrategy(PaintingStrategy.Squared_HISTOGRAM);
DiffLT.SetLineWeight(5);
DiffLT.DefineColor("Positive and Up", Color.Cyan);
DiffLT.DefineColor("Positive and Down", Color.Blue);
DiffLT.DefineColor("Negative and Down", Color.RED);
DiffLT.DefineColor("Negative and Up", Color.Yellow);
DiffLT.AssignValueColor(if DiffLT >= 0 then if DiffLT > DiffLT[LengthLT] then DiffLT.color("Positive and Up") else DiffLT.color("Positive and Down") else if DiffLT < DiffLT[LengthLT] then DiffLT.color("Negative and Down") else DiffLT.color("Negative and Up")); #

AddLabel(yes, "LT", if DiffLT >= 0 then if DiffLT > DiffLT[LengthLT] then DiffLT.color("Positive and Up") else DiffLT.color("Positive and Down") else if DiffLT < DiffLT[LengthLT] then DiffLT.color("Negative and Down") else DiffLT.color("Negative and Up"));

input aggregationPeriodMT = AggregationPeriod.Three_Days;
input LengthMT =3.0;
def fastLengthMT = 12;
def slowLengthMT = 26;
def MACDLengthMT = 9;


plot ValueMT = MovingAverage(AverageType.EXPONENTIAL, close (period = aggregationPeriodMT), fastLengthMT) - MovingAverage(AverageType.EXPONENTIAL, close (period = aggregationPeriodMT), slowLengthMT);
plot AvgMT = MovingAverage(AverageType.EXPONENTIAL, ValueMT, MACDLengthMT);

AvgMT.DefineColor("Up", Color.WHITE);
AvgMT.DefineColor("Down", Color.PLUM);
AvgMT.AssignValueColor(if AvgMT > AvgMT[LengthMT] then AvgMT.Color("Up") else AvgMT.Color("Down"));
AvgMT.SetLineWeight(2);
AvgMT.Hide();
ValueMT.DefineColor("Up", Color.GREEN);
ValueMT.DefineColor("Down", Color.DARK_RED);
ValueMT.AssignValueColor(if ValueMT > ValueMT[LengthMT] then ValueMT.Color("Up") else ValueMT.Color("Down"));
ValueMT.SetLineWeight(3);
ValueMT.Hide();

Plot DiffMT = ValueMT - AvgMT;
DiffMT.SetDefaultColor(GetColor(5));
DiffMT.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
DiffMT.SetLineWeight(3);
DiffMT.DefineColor("Positive and Up", Color.Cyan);
DiffMT.DefineColor("Positive and Down", Color.Blue);
DiffMT.DefineColor("Negative and Down", Color.RED);
DiffMT.DefineColor("Negative and Up", Color.Yellow);
DiffMT.AssignValueColor(if DiffMT >= 0 then if DiffMT > DiffMT[LengthMT] then DiffMT.color("Positive and Up") else DiffMT.color("Positive and Down") else if DiffMT < DiffMT[LengthMT] then DiffMT.color("Negative and Down") else DiffMT.color("Negative and Up"));

AddLabel(yes, "MT", if DiffMT >= 0 then if DiffMT > DiffMT[LengthMT] then DiffMT.color("Positive and Up") else DiffMT.color("Positive and Down") else if DiffMT < DiffMT[LengthMT] then DiffMT.color("Negative and Down") else DiffMT.color("Negative and Up"));

plot ZeroLine3 = 0;
ZeroLine3.SetDefaultColor(Color.Pink);
ZeroLine3.HideTitle();

def fastLengthCONFIRMATION = 3;
def slowLengthCONFIRMATION = 10;
def MACDLengthCONFIRMATION = 15;

#def showBreakoutSignals = no;

plot ValueCONFIRMATION = MovingAverage(AverageType.EXPONENTIAL, close (period = aggregationPeriodMT), fastLengthCONFIRMATION) - MovingAverage(AverageType.EXPONENTIAL, close (period = aggregationPeriodMT), slowLengthCONFIRMATION);
plot AvgCONFIRMATION = MovingAverage(AverageType.EXPONENTIAL, ValueCONFIRMATION, MACDLengthCONFIRMATION);

AvgCONFIRMATION.DefineColor("Up", Color.WHITE);
AvgCONFIRMATION.DefineColor("Down", Color.PLUM);
AvgCONFIRMATION.AssignValueColor(if AvgCONFIRMATION > AvgCONFIRMATION[LengthMT] then AvgCONFIRMATION.Color("Up") else AvgCONFIRMATION.Color("Down"));
AvgCONFIRMATION.SetLineWeight(2);
AvgCONFIRMATION.Hide();
ValueCONFIRMATION.DefineColor("Up", Color.GREEN);
ValueCONFIRMATION.DefineColor("Down", Color.DARK_RED);
ValueCONFIRMATION.AssignValueColor(if ValueCONFIRMATION > ValueCONFIRMATION[LengthMT] then ValueCONFIRMATION.Color("Up") else ValueCONFIRMATION.Color("Down"));
ValueCONFIRMATION.SetLineWeight(3);
ValueCONFIRMATION.Hide();


def fast1 = 12;
def slow1 = 26;
def MACD1 = 9;

def ValueST = MovingAverage(AverageType.EXPONENTIAL, close, fast1) - MovingAverage(AverageType.EXPONENTIAL, close, slow1);
def AvgST = MovingAverage(AverageType.EXPONENTIAL, ValueST, MACD1);

Plot DiffST = ValueST - AvgST;
DiffST.SetDefaultColor(GetColor(5));
DiffST.SetPaintingStrategy(PaintingStrategy.Squared_HISTOGRAM);
DiffST.SetLineWeight(5);
DiffST.DefineColor("Positive and Up", Color.Cyan);
DiffST.DefineColor("Positive and Down", Color.Blue);
DiffST.DefineColor("Negative and Down", Color.RED);
DiffST.DefineColor("Negative and Up", Color.Yellow);
DiffST.AssignValueColor(if DiffST >= 0 then if DiffST > DiffST[1] then DiffST.color("Positive and Up") else DiffST.color("Positive and Down") else if DiffST < DiffST[1] then DiffST.color("Negative and Down") else DiffST.color("Negative and Up"));
DiffST.Hide();
AddLabel(yes, "ST", if DiffST >= 0 then if DiffST > DiffST[1] then DiffST.color("Positive and Up") else DiffST.color("Positive and Down") else if DiffST < DiffST[1] then DiffST.color("Negative and Down") else DiffST.color("Negative and Up"));
 
Solution

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