Murrey's Math Trend System for ThinkorSwim

BenTen

Staff member
Staff
VIP
This indicator was created & developed by Ucsgears, based on Murrey Math Line Principle.

Hello, Murrey Math lovers, Thanks for those who showed interest on this. Based on a request, I have updated the plot / candle coloring, for Version - 2. This has been in the queue for a while. There was a Glitch found with the Multiplier. Will Fix in the next version. The Current Version (and the previous version) only supports 1/8 fractions. Will not support 0.25. The code needs to be updated, to automate the fractal line glitches for other ratios, Planned for future update. Good Luck and Enjoy the Colorful Oscillator. Please keep your suggestions flowing. Lets make it better.

Script #1: Simple. No lower study. Just paint bars (green = bullish and red = bearish)

Code:
``````# Murrey's Math Oscillator
# Assembled by BenTen at useThinkScript.com

# This is a stripped down or the original version. No lower study. Just simple paint bars.

input length = 100;
input mult = 0.125;

def hi = highest(high, length);
def lo = lowest(low, length);
def range = hi - lo;
def multiplier = (range) * mult;
def midline = lo + multiplier * 4;

def oscillator = (close - midline) / (range / 2);

def a = oscillator > 0 and oscillator<mult*2;
def b = oscillator > 0 and oscillator < mult*4;
def c = oscillator > 0 and oscillator < mult*6;
def d = oscillator > 0 and oscillator < mult*8;

def z = oscillator < 0 and oscillator > -mult*2;
def y = oscillator < 0 and oscillator > -mult*4;
def x = oscillator < 0 and oscillator > -mult*6;
def w = oscillator < 0 and oscillator > -mult*8;

assignPriceColor(if a or b or c or d then color.green else if w or z or y or x then color.red else color.white);``````

Script #2: Just paint bars. No lower study. But with color variations added.

Code:
``````# Murrey's Math Oscillator
# Assembled by BenTen at useThinkScript.com

# This is also a stripped down version. But it has color variations for paint bars.

input length = 100;
input mult = 0.125;

def hi = highest(high, length);
def lo = lowest(low, length);
def range = hi - lo;
def multiplier = (range) * mult;
def midline = lo + multiplier * 4;

def oscillator = (close - midline) / (range / 2);

def a = oscillator > 0 and oscillator<mult*2;
def b = oscillator > 0 and oscillator < mult*4;
def c = oscillator > 0 and oscillator<mult*6;
def d = oscillator > 0 and oscillator < mult*8;

def z = oscillator < 0 and oscillator > -mult*2;
def y = oscillator < 0 and oscillator > -mult*4;
def x = oscillator < 0 and oscillator > -mult*6;
def w = oscillator < 0 and oscillator > -mult*8;

assignPriceColor(if a then CreateColor(173, 255, 47) else if b then CreateColor(50, 205, 50) else if c then CreateColor(60, 179, 113) else if d then CreateColor(0, 128, 0) else if z then CreateColor(205, 92, 92) else if y then CreateColor(250, 128, 114) else if x then CreateColor(255, 160, 122) else if w then CreateColor(255, 0, 0) else color.white);``````

Script #3: Complete version. Just like the original script from TradingView.

Code:
``````# Murrey's Math Oscillator
# Assembled by BenTen at useThinkScript.com

declare lower;

input length = 100;
input mult = 0.125;

def hi = highest(high, length);
def lo = lowest(low, length);
def range = hi - lo;
def multiplier = (range) * mult;
def midline = lo + multiplier * 4;

def oscillator = (close - midline) / (range / 2);

def a = oscillator > 0 and oscillator<mult*2;
def b = oscillator > 0 and oscillator < mult*4;
def c = oscillator > 0 and oscillator<mult*6;
def d = oscillator > 0 and oscillator < mult*8;

def z = oscillator < 0 and oscillator > -mult*2;
def y = oscillator < 0 and oscillator > -mult*4;
def x = oscillator < 0 and oscillator > -mult*6;
def w = oscillator < 0 and oscillator > -mult*8;

plot histogram = oscillator;
histogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
histogram.AssignValueColor(if a then CreateColor(173, 255, 47) else if b then CreateColor(50, 205, 50) else if c then CreateColor(60, 179, 113) else if d then CreateColor(0, 128, 0) else if z then CreateColor(205, 92, 92) else if y then CreateColor(250, 128, 114) else if x then CreateColor(255, 160, 122) else if w then CreateColor(255, 0, 0) else color.white);

plot upper_l1 = mult*6;
plot upper_l2 = mult*8;
plot lower_l1 = -mult*6;
plot lower_l2 = -mult*8;

upper_l1.AssignValueColor(color.gray);
upper_l2.AssignValueColor(color.gray);
lower_l1.AssignValueColor(color.gray);
lower_l2.AssignValueColor(color.gray);

#assignPriceColor(if a or b or c or d then color.green else if w or z or y or x then color.red else color.white);

assignPriceColor(if a then CreateColor(173, 255, 47) else if b then CreateColor(50, 205, 50) else if c then CreateColor(60, 179, 113) else if d then CreateColor(0, 128, 0) else if z then CreateColor(205, 92, 92) else if y then CreateColor(250, 128, 114) else if x then CreateColor(255, 160, 122) else if w then CreateColor(255, 0, 0) else color.white);``````

Can't get enough of Murrey Math?
Here are all the indicators included in this thread; which provide a variety of customizations to the Murrey Math logic.

1. A Trending Indicator calculated with Murrey Math

2. Support & Resistance calculated with Murrey Math

3. Murrey Math Levels with bubbles

4. MTF Multi-Timeframe Murrey Math

5. Mobius's version of Murrey Math Lines

6. Murrey Math Full Range Study

7. Converted Tradingview version of Murrey Math Support & Resistance

8. Converted Tradingview version of Murrey Math Levels

Last edited:
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();

Level5.SetDefaultColor(color.CYAN);
Level5.SetStyle(curve.Short_Dash);
Level5.HideBubble();

Level4.SetDefaultColor(color.BLUE);
Level4.SetStyle(curve.Short_Dash);
Level4.setLineWeight (4) ;
Level4.HideBubble();

Level3.SetDefaultColor(color.CYAN);
Level3.SetStyle(curve.Short_Dash);
Level3.HideBubble();

Level2.SetDefaultColor(color.YELLOW);
Level2.SetStyle(curve.Short_Dash);
Level2.HideBubble();

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();

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

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

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

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();
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();
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);``````

Sorry same code for the plots. Still not real thing I guess.

@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:
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.

Ive read on Murry's lines where each line is proportional to 1/8. from what I can tell
Oscillator Color Definition -
Green = Above MidLine
Red = Below Midline
Blue = Below Negative 3rd Quadrant
Orange = Above Positive 3rd Quadrant

Last edited:
based on research and some testing, I find in the lower time frame, it does a pretty good job finding tops and bottoms on OB and OS conditions.

if oscillator crosses below (mult * 6) then short else
if oscillator crosses above (-mult * 6) then long.

if anyone has any other test results or experiences please share.

Apart from circles, speed lines, and frames, Murrey math is the same as Fibonacci ratios.

Do we have the original Murrey math with all of the levels for TOS, the video's for the original are extensive and detailed. The levels make the application clearer for me.

Thanks

John3, this video link for Murrey Math is a detailed explanation, a little long.

Let me know if this is useful for you.

@Lambert58 Thank you for the video. I've seen it before. I thought maybe you were talking about a video that I haven't seen.

That and all other videos/discussions of Murrey Math/Fibs miss several key points, i.e., they don't discuss progression and how the price interacts with key injection pivots.

Not the exact question you're looking for?

87k+ Posts
375 Online

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?