Murrey Math Harmonics for ThinkorSwim

horserider

Well-known member
VIP
Support/resistance lines computed by Murray math. Similiar to other S/R studies so try it out then choose whatever study works best for you.

Code:
# SJ_Murray'sMathHarmonics

#In the study by SJ all lines were cyan. Changed the line colors to what made sense to me so no real significance to line colors. Adjust them as you wish. #Horserider 12/20/2019

input showOnlyToday = yes;

input timeFrame = {default DAY, "2 DAYS", "3 DAYS", "4 DAYS", WEEK, MONTH, "OPTEXP"};
def RangeHigh = high(period = "DAY")[0];
def RangeLow = low(period = "DAY")[0];
def RangeSize = AbsValue(RangeHigh - RangeLow);
def MMLevel8 = 8 / 8;
def MMLevel7 = 7 / 8;
def MMLevel6 = 6 / 8;
def MMLevel5 = 5 / 8;
def MMLevel4 = 4 / 8;
def MMLevel3 = 3 / 8;
def MMLevel2 = 2 / 8;
def MMLevel1 = 1 / 8;
def MMLevel0 = 0 / 8;

def TimeCondition = IsNaN(Close[-1]) and !IsNaN(close[0]);

def MML7 = RangeLow + RangeSize * (MMLevel7);
def MML6 = RangeLow + RangeSize * (MMLevel6);
def MML5 = RangeLow + RangeSize * (MMLevel5);
def MML4 = RangeLow + RangeSize * (MMLevel4);
def MML3 = RangeLow + RangeSize * (MMLevel3);
def MML2 = RangeLow + RangeSize * (MMLevel2);
def MML1 = RangeLow + RangeSize * (MMLevel1);
def MML0 = RangeLow;

plot Level8;
plot Level7;
plot Level6;
plot Level5;
plot Level4;
plot Level3;
plot Level2;
plot Level1;
plot Level0;

if showOnlyToday and !IsNaN(close(period = "DAY")[-1])
then {
Level8 = Double.NaN;
Level7 = Double.NaN;
Level6 = Double.NaN;
Level5 = Double.NaN;
Level4 = Double.NaN;
Level3 = Double.NaN;
Level2 = Double.NaN;
Level1 = Double.NaN;
Level0 = Double.NaN;
} else {
Level8 = RangeHigh;
Level7 = MML7;
Level6 = MML6;
Level5 = MML5;
Level4 = MML4;
Level3 = MML3;
Level2 = MML2;
Level1 = MML1;
Level0 = MML0;
}

Level8.SetDefaultColor(color.RED);
Level8.SetStyle(curve.Short_Dash);
Level8.setLineWeight (4) ;
Level8.HideBubble();

Level7.SetDefaultColor(color.YELLOW);
Level7.SetStyle(curve.Short_Dash);
#Level7.HideBubble();
#AddChartBubble(TimeCondition , MML7, "7/8ths Fast Reversal line: weak",color.yellow, yes);

Level6.SetDefaultColor(color.YELLOW);
Level6.SetStyle(curve.Short_Dash);
Level6.HideBubble();
#AddChartBubble(TimeCondition , MML6, "6/8", color.pink,yes);

Level5.SetDefaultColor(color.CYAN);
Level5.SetStyle(curve.Short_Dash);
Level5.HideBubble();
#AddChartBubble(TimeCondition , MML5, "5/8ths Upper Trading Range: ",color.green, yes);

Level4.SetDefaultColor(color.BLUE);
Level4.SetStyle(curve.Short_Dash);
Level4.setLineWeight (4) ;
Level4.HideBubble();
#AddChartBubble(TimeCondition ,MML4, "4/8", color.cyan, yes);

Level3.SetDefaultColor(color.CYAN);
Level3.SetStyle(curve.Short_Dash);
Level3.HideBubble();
#AddChartBubble(TimeCondition ,MML3, "3/8ths Lower Trading Range: ", color.green, yes);

Level2.SetDefaultColor(color.YELLOW);
Level2.SetStyle(curve.Short_Dash);
Level2.HideBubble();
#AddChartBubble(TimeCondition ,MML2, "2/8", color.pink, yes);

Level1.SetDefaultColor(color.YELLOW);
Level1.SetStyle(curve.Short_Dash);
Level1.HideBubble();
#AddChartBubble(TimeCondition ,MML1, "1/8ths Fast Reversal line: weak", color.yellow, yes);

Level0.SetDefaultColor(color.GREEN);
Level0.SetStyle(curve.Short_Dash);
Level0.setLineWeight (4) ;
Level0.HideBubble();
#AddChartBubble(TimeCondition ,MML0, "0/8", color.cyan, yes);
 

horserider

Well-known member
VIP
2019-12-24-TOS-CHARTS.png
 

Antares66

Member
I also noticed that changing the time frame to daily, weekly, monthly has no effects. The indicator stays unchanged.
Does someone know why? It would be nice to use it on a higher timeframe.
Thanks
 

Rhatten

New member
Thats not MMLs... MML its calculated based on bar count (on time based bars.. ie 64bars, 128, 256, 512bars and on a 15min, 1hour, 4hour, Daily ,weekly etc) and is user defined... Plus there are additional levels (+1/8, +2/8, -1/8, -2/8) and is calculated relative to swing pivots (not just today's or yesterdays range)... This is not even close...
 

horserider

Well-known member
VIP
@Rhatten I believe you are correct. It was done by somebody named SJ so not sure why he coded it that way. I find it difficult to see how someone could use it. It is finding the high and low and filling the range with the levels.
 

bobomatic

New member
Found this on the internets.. might be a true model of the indicator but not sure. I'm playing with it for now. Trying to figure out how to get the S/R labels to the left side of the chart. If you developer guru's can take it to another level, have at it.... Muchas Gracias.


Code:

Code:
# SJ_Murray'sMathHarmonics
def showOnlyToday = yes;
def RangeHigh = high(period = "DAY")[0];
def RangeLow = low(period = "DAY")[0];
def RangeSize = AbsValue(RangeHigh - RangeLow);
def MMLevel8 = 8 / 8;
def MMLevel7 = 7 / 8;
def MMLevel6 = 6 / 8;
def MMLevel5 = 5 / 8;
def MMLevel4 = 4 / 8;
def MMLevel3 = 3 / 8;
def MMLevel2 = 2 / 8;
def MMLevel1 = 1 / 8;
def MMLevel0 = 0 / 8;
def TimeCondition = IsNaN(Close[-1]) and !IsNaN(close[0]);
def MML8 = RangeHigh;
def MML7 = RangeLow + RangeSize * (MMLevel7);
def MML6 = RangeLow + RangeSize * (MMLevel6);
def MML5 = RangeLow + RangeSize * (MMLevel5);
def MML4 = RangeLow + RangeSize * (MMLevel4);
def MML3 = RangeLow + RangeSize * (MMLevel3);
def MML2 = RangeLow + RangeSize * (MMLevel2);
def MML1 = RangeLow + RangeSize * (MMLevel1);
def MML0 = RangeLow;
plot Level8;
plot Level7;
plot Level6;
plot Level5;
plot Level4;
plot Level3;
plot Level2;
plot Level1;
plot Level0;
if showOnlyToday and !IsNaN(close(period = "DAY")[-1])
then {
Level8 = Double.NaN;
Level7 = Double.NaN;
Level6 = Double.NaN;
Level5 = Double.NaN;
Level4 = Double.NaN;
Level3 = Double.NaN;
Level2 = Double.NaN;
Level1 = Double.NaN;
Level0 = Double.NaN;
} else {
Level8 = MML8;
Level7 = MML7;
Level6 = MML6;
Level5 = MML5;
Level4 = MML4;
Level3 = MML3;
Level2 = MML2;
Level1 = MML1;
Level0 = MML0;
}
Level8.SetDefaultColor(color.cyan);
Level8.SetStyle(curve.Short_Dash);
Level8.HideBubble();
AddChartBubble(TimeCondition , Level8, "Top of Octave = 8/8ths: Hardest line to rise above (overbought)", color.cyan, yes);
Level7.SetDefaultColor(color.cyan);
Level7.SetStyle(curve.Short_Dash);
Level7.HideBubble();
AddChartBubble(TimeCondition , MML7, "7/8ths Fast Reversal line: weak",
color.yellow, yes);
Level6.SetDefaultColor(color.cyan);
Level6.SetStyle(curve.Short_Dash);
Level6.HideBubble();
AddChartBubble(TimeCondition , MML6, "6/8ths Pivot Reversal line: ", color.pink,
yes);
Level5.SetDefaultColor(color.cyan);
Level5.SetStyle(curve.Short_Dash);
Level5.HideBubble();
AddChartBubble(TimeCondition , MML5, "5/8ths Upper Trading Range: ",
color.green, yes);
Level4.SetDefaultColor(color.cyan);
Level4.SetStyle(curve.Short_Dash);
Level4.HideBubble();
AddChartBubble(TimeCondition ,MML4, "4/8ths Major Reversal line", color.cyan, yes);
Level3.SetDefaultColor(color.cyan);
Level3.SetStyle(curve.Short_Dash);
Level3.HideBubble();
AddChartBubble(TimeCondition ,MML3, "3/8ths Lower Trading Range: ", color.green, yes);
Level2.SetDefaultColor(color.cyan);
Level2.SetStyle(curve.Short_Dash);
Level2.HideBubble();
AddChartBubble(TimeCondition ,MML2, "2/8ths Pivot Reversal line:", color.pink, yes);
Level1.SetDefaultColor(color.cyan);
Level1.SetStyle(curve.Short_Dash);
Level1.HideBubble();
AddChartBubble(TimeCondition ,MML1, "1/8ths Fast Reversal line: weak", color.yellow, yes);
Level0.SetDefaultColor(color.cyan);
Level0.SetStyle(curve.Short_Dash);
Level0.HideBubble();
AddChartBubble(TimeCondition ,MML0, "0/8ths Baseline: Hardest line to fall below (oversold)", color.cyan, yes);
 

bobomatic

New member
@horserider Thanks, bummer, but I'm gonna work with it for tad to get a feel for it. BTW, is getting those labels on the left side of the chart a big deal?

Edit: I have the mq4 file I found for free but have no clue how to convert it. If anyone who knows how to do that and is interested, let me know.
 
Last edited:

horserider

Well-known member
VIP
Use the " n " input to move the bubbles to right or input a negative number to move left. You can get them off the chart plot if move right and use expansion. Well should work, try it to get what you want.
 
Hey Horserider, good script. Works great for Day Trading! However, when I change the timeframe to Weekly the script does not work. I went into the script and changed the default to Weekly and it did not work either. What am I doing wrong? The MM levels stay in the Day setting.
 

horserider

Well-known member
VIP
@San @Antares66 @Ninja Bull Guess people want to input time frame for this. I see it was coded for "Day" so your efforts were ignored. Redid the code so give this one a try. May not be true MM Harmonics. Is SJ's version.

Code:
# SJ_Murray's Math Harmonics

# May not be true MM Harmonics.
#In the study by SJ all lines were cyan. Changed the line colors to what made sense to me so no real significance to line colors. Adjust them as you wish. #Horserider 12/20/2019

input showbubble = yes;
input showOnlyToday = yes;
input agg = aggregationPeriod.DAY;
def RangeHigh = high(period = agg)[0];
def RangeLow = low(period = agg)[0];
def RangeSize = AbsValue(RangeHigh - RangeLow);
def MMLevel8 = 8 / 8;
def MMLevel7 = 7 / 8;
def MMLevel6 = 6 / 8;
def MMLevel5 = 5 / 8;
def MMLevel4 = 4 / 8;
def MMLevel3 = 3 / 8;
def MMLevel2 = 2 / 8;
def MMLevel1 = 1 / 8;
def MMLevel0 = 0 / 8;



def MML7 = RangeLow + RangeSize * (MMLevel7);
def MML6 = RangeLow + RangeSize * (MMLevel6);
def MML5 = RangeLow + RangeSize * (MMLevel5);
def MML4 = RangeLow + RangeSize * (MMLevel4);
def MML3 = RangeLow + RangeSize * (MMLevel3);
def MML2 = RangeLow + RangeSize * (MMLevel2);
def MML1 = RangeLow + RangeSize * (MMLevel1);
def MML0 = RangeLow;

plot Level8;
plot Level7;
plot Level6;
plot Level5;
plot Level4;
plot Level3;
plot Level2;
plot Level1;
plot Level0;

if  showOnlyToday and !IsNaN(close(period = agg)[-1])
then {
Level8 = Double.NaN;
Level7 = Double.NaN;
Level6 = Double.NaN;
Level5 = Double.NaN;
Level4 = Double.NaN;
Level3 = Double.NaN;
Level2 = Double.NaN;
Level1 = Double.NaN;
Level0 = Double.NaN;
} else {
Level8 = RangeHigh;
Level7 = MML7;
Level6 = MML6;
Level5 = MML5;
Level4 = MML4;
Level3 = MML3;
Level2 = MML2;
Level1 = MML1;
Level0 = MML0;
}
def TimeCondition = IsNaN(Close[-1]) and !IsNaN(close[0]);

Level8.SetDefaultColor(color.RED);
Level8.SetStyle(curve.Short_Dash);
Level8.setLineWeight (4) ;
AddChartBubble(showbubble and TimeCondition ,RangeHigh, "8/8", color.red, yes);

Level7.SetDefaultColor(color.YELLOW);
Level7.SetStyle(curve.Short_Dash);
AddChartBubble(showbubble and TimeCondition , MML7, "7/8ths Fast Reversal line: weak",color.yellow, yes);

Level6.SetDefaultColor(color.YELLOW);
Level6.SetStyle(curve.Short_Dash);
AddChartBubble(showbubble and TimeCondition , MML6, "6/8", color.pink,yes);

Level5.SetDefaultColor(color.CYAN);
Level5.SetStyle(curve.Short_Dash);
AddChartBubble(showbubble and TimeCondition , MML5, "5/8ths Upper Trading Range: ",color.green, yes);

Level4.SetDefaultColor(color.BLUE);
Level4.SetStyle(curve.Short_Dash);
Level4.setLineWeight (4) ;
AddChartBubble(showbubble and TimeCondition ,MML4, "4/8", color.cyan, yes);

Level3.SetDefaultColor(color.CYAN);
Level3.SetStyle(curve.Short_Dash);
AddChartBubble(showbubble and TimeCondition ,MML3, "3/8ths Lower Trading Range: ", color.green, yes);

Level2.SetDefaultColor(color.YELLOW);
Level2.SetStyle(curve.Short_Dash);
AddChartBubble(showbubble and TimeCondition ,MML2, "2/8", color.pink, yes);

Level1.SetDefaultColor(color.YELLOW);
Level1.SetStyle(curve.Short_Dash);
AddChartBubble(showbubble and TimeCondition ,MML1, "1/8ths Fast Reversal line: weak", color.yellow, yes);

Level0.SetDefaultColor(color.GREEN);
Level0.SetStyle(curve.Short_Dash);
Level0.setLineWeight (4) ;
AddChartBubble(showbubble and TimeCondition ,MML0, "0/8", color.green, yes);
 

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.
Top