Weighted MTF MACD

shellyonthepelli

New member
Plus
i've been trying to learn the language of the charts and i'm struggling to learn but i'll get there. im trying to update your code for the timeframes that i have which adds 2 min, 4 min, 10min, 6min, 7min, 8min, 10min, 20 min, 3 hour, 4 hour, 2day, 3day, and 4day. any assistance you are willing to share would be greatly appreciated.

here is what i'm trying to do:
1- on each timeframe, on the MACD (WEIGHTED) graph, put a box and highlight Green or Red based on the slope being increasing or decreasing for one bar. similar to the boxes you have above.

2-put the same label on the price chart with the same box with a green or red label box to indicate if the 8WMA price slope is up or down for one bar. and

3- an indicator arrow (or something else-maybe a label as well) on the price chart any time for one bar that the slope of one is up and the other is down (MACD - WEIGHTED/ 8WMA). to indicate if 8WMA is down and MACD (WEIGHTED) is up (maybe blue) and when 8WMA is up and MACD(WEIGHTED) is down (maybe pink).
 
Last edited by a moderator:
i've been trying to learn the language of the charts and i'm struggling to learn but i'll get there. im trying to update your code for the timeframes that i have which adds 2 min, 4 min, 10min, 6min, 7min, 8min, 10min, 20 min, 3 hour, 4 hour, 2day, 3day, and 4day. any assistance you are willing to share would be greatly appreciated.

here is what i'm trying to do:
1- on each timeframe, on the MACD (WEIGHTED) graph, put a box and highlight Green or Red based on the slope being increasing or decreasing for one bar. similar to the boxes you have above.

2-put the same label on the price chart with the same box with a green or red label box to indicate if the 8WMA price slope is up or down for one bar. and

3- an indicator arrow (or something else-maybe a label as well) on the price chart any time for one bar that the slope of one is up and the other is down (MACD - WEIGHTED/ 8WMA). to indicate if 8WMA is down and MACD (WEIGHTED) is up (maybe blue) and when 8WMA is up and MACD(WEIGHTED) is down (maybe pink).

please provide a link or code for a weighted MACD
MACD has 3 plots. assuming weighted does also? which one is supposed to be used ?
 

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

i really like this,
https://usethinkscript.com/threads/multi-timeframe-mtf-macd-indicator-for-thinkorswim.474/
but need to update it to use the WEIGHTED MACD and extend the timeframes and reduce the text in the boxes. i made the edits, but it doesn't work. any thoughts on what's wrong with it?

Code:
# Code from Hahn Tech had no header.
# Added labels for three time frames.
# The chart time frame and two user chosen higher time frames. Labels turn red or green depending on MACD.
# Additions by Horserider 9/30/2019

input midTermPeriod = {"1 min", "2 min", "3 min", "4 min", "5 min", "10 min", "15 min", "20 min", "30 min", "60 min", "120 min", "4 hours", "Daily", "2 days", "3 days", "4 days", default "Weekly", "Monthly"};
input longTermPeriod = { "2 min", "3 min", "4 min", "5 min", "10 min", "15 min", "20 min", "30 min", "60 min", "120 min", "4 hours", "Daily", "2 days", "3 days", "4 days", "Weekly", default "Monthly"};

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


input midTermFastLength = 12;
input midTermSlowLength = 26;
input midTermMACDLength = 9;
input midTermaverageType = AverageType.WEIGHTED;


input longTermFastLength = 12;
input longTermSlowLength = 26;
input longTermMACDLength = 9;
input longTermaverageType = AverageType.WEIGHTED;


def middleAggregation;

switch (midTermPeriod) {
case "1 min":
    middleAggregation = AggregationPeriod.MIN;
case "2 min":
    middleAggregation = AggregationPeriod.TWO_MIN;
case "3 min":
    middleAggregation = AggregationPeriod.THREE_MIN;
case "4 min":
    middleAggregation = AggregationPeriod.FOUR_MIN;
case "5 min":
    middleAggregation = AggregationPeriod.FIVE_MIN;
case "10 min":
    middleAggregation = AggregationPeriod.TEN_MIN;
case "15 min":
    middleAggregation = AggregationPeriod.FIFTEEN_MIN;
case "20 min":
    middleAggregation = AggregationPeriod.TWENTY_MIN;
case "30 min":
    middleAggregation = AggregationPeriod.THIRTY_MIN;
case "60 min":
    middleAggregation = AggregationPeriod.HOUR;
case "120 min":
    middleAggregation = AggregationPeriod.TWO_HOURS;
case "4 hours":
    middleAggregation = AggregationPeriod.FOUR_HOURS;
case "Daily":
    middleAggregation = AggregationPeriod.DAY;
case "2 days":
    middleAggregation = AggregationPeriod.TWO_DAYS;
case "3 days":
    middleAggregation = AggregationPeriod.THREE_DAYS;
case "4 days":
    middleAggregation = AggregationPeriod.FOUR_DAYS;
case "Weekly":
    middleAggregation = AggregationPeriod.WEEK;
case "Monthly":
    middleAggregation = AggregationPeriod.MONTH;
}

def highestAggregation;
switch (longTermPeriod) {
case "2 min":
    highestAggregation = AggregationPeriod.TWO_MIN;
case "3 min":
    highestAggregation = AggregationPeriod.THREE_MIN;
case "4 min":
    highestAggregation = AggregationPeriod.FOUR_MIN;
case "5 min":
    highestAggregation = AggregationPeriod.FIVE_MIN;
case "10 min":
    highestAggregation = AggregationPeriod.TEN_MIN;
case "15 min":
    highestAggregation = AggregationPeriod.FIFTEEN_MIN;
case "20 min":
    highestAggregation = AggregationPeriod.TWENTY_MIN;
case "30 min":
    highestAggregation = AggregationPeriod.THIRTY_MIN;
case "60 min":
    highestAggregation = AggregationPeriod.HOUR;
case "120 min":
    highestAggregation = AggregationPeriod.TWO_HOURS;
case "4 hours":
    highestAggregation = AggregationPeriod.FOUR_HOURS;
case "Daily":
    highestAggregation = AggregationPeriod.DAY;
case "2 days":
    highestAggregation = AggregationPeriod.TWO_DAYS;
case "3 days":
    highestAggregation = AggregationPeriod.THREE_DAYS;
case "4 days":
    highestAggregation = AggregationPeriod.FOUR_DAYS;
case "Weekly":
    highestAggregation = AggregationPeriod.WEEK;
case "Monthly":
    highestAggregation = AggregationPeriod.MONTH;
}

DefineGlobalColor("UpTrend", Color.GREEN);
DefineGlobalColor("DownTrend", Color.RED);
DefineGlobalColor("NoTrend", Color.LIGHT_GRAY);

def timeFrame = GetAggregationPeriod();
def testTimeFrames = if timeFrame < middleAggregation and middleAggregation < highestAggregation then yes else no;

AddLabel(yes, if testTimeFrames  then "TF Correct" else "TF Wrong", if testTimeFrames  then Color.GREEN else Color.RED);

# This section is for the chart level MACD
def fastAvg = WMA(close, fastLength);
def slowAvg = WMA(close, slowLength);

plot Value = fastAvg - slowAvg;
Value.SetDefaultColor(Color.CYAN);
plot Avg = WMA(Value, MACDLength);
Avg.SetDefaultColor(Color.YELLOW);
plot Diff = (Value - Avg) * 3;

# This section is for the medium term MACD
def midTermFastAvg = WMA(close(period = middleAggregation) , midTermFastLength);
def midTermSlowAvg = WMA(close(period = middleAggregation) , midTermSlowLength);

def midTermValue = midTermFastAvg - midTermSlowAvg;
def midTermAvg = WMA(midTermValue, midTermMACDLength);
plot midTermDiff = (midTermValue - midTermAvg) * 3;
midTermDiff.Hide();
midTermDiff.HideBubble();

# This section is for the long term MACD
def longTermFastAvg = WMA(close(period = highestAggregation) , longTermFastLength);
def longTermSlowAvg = WMA(close(period = highestAggregation) , longTermSlowLength);

def longTermValue = longTermFastAvg - longTermSlowAvg;
def longTermAvg = WMA(longTermValue, longTermMACDLength);
plot longTermDiff = (longTermValue - longTermAvg) * 3;
longTermDiff.Hide();
longTermDiff.HideBubble();


def midTermLower = midTermDiff < midTermDiff[1];
def midTermHigher = midTermDiff > midTermDiff[1];
rec midTermSignal = if midTermLower then  yes  else if midTermSignal[1] == yes and midTermHigher == no then yes else no;
#plot test = midTermSignal;
def longTermLower = longTermDiff < longTermDiff[1];
def longTermHigher = longTermDiff > longTermDiff[1];
rec longTermSignal = if longTermLower then  yes  else if longTermSignal[1] == yes and longTermHigher == no then yes else no;

midTermDiff.AssignValueColor(if midTermSignal then Color.RED else Color.BLUE);
longTermDiff.AssignValueColor(if longTermSignal then Color.RED else Color.BLUE);

Diff.AssignValueColor(if Diff > Diff[1] and midTermSignal == no and longTermSignal == no then GlobalColor("UpTrend") else if Diff < Diff[1] and midTermSignal == yes and longTermSignal == yes then GlobalColor("DownTrend") else GlobalColor("NoTrend") );
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);

plot zeroLine = if close[-1] > 0 then 0 else Double.NaN;
zeroLine.AssignValueColor(if Diff > Diff[1] and midTermSignal == no and longTermSignal == no then GlobalColor("UpTrend") else if Diff < Diff[1] and midTermSignal == yes and longTermSignal == yes then GlobalColor("DownTrend") else GlobalColor("NoTrend") );
zeroLine.SetPaintingStrategy(PaintingStrategy.POINTS);
zeroLine.SetLineWeight(3);

AddLabel(yes, if Value > Avg == yes  then "SHORT" else "Short", if Value < Avg == no then Color.GREEN else Color.RED);

AddLabel(yes, if midTermSignal == yes  then "MID" else "Mid", if midTermSignal == no then Color.GREEN else Color.RED);

AddLabel(yes, if longTermSignal == yes  then "LONG" else "Long", if longTermSignal == no then Color.GREEN else Color.RED);
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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