Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //© ╦ ╦═╗ ╦
- //© ║ ╠╦╝ ║
- //© ╚╝ ╩╚═ ╩═╝
- //
- // Murrey Math Lines Indicator
- //@version=5
- // General information on trading with Murrey Math Lines can be found
- // here: (https://blog.roboforex.com/blog/2020/08/14/murrey-math-lines-how-to-set-and-trade-them/)
- // ---------------------------------------------------------------------------------------------------
- // If you'd like to go down the rabbit hole on the math formulas, more information can be found
- // here: (https://www.sierrachart.com/index.php?page=doc/StudiesReference.php&ID=238&Name=Murrey_Math)
- // and here: (https://www.forexfactory.com/attachment.php/3732227?attachmentid=3732227&d=1599144167)
- indicator(title='Murrey Math Lines', shorttitle='MM Lines [JRL]', precision=5, overlay=true)
- // ##############################################################################################
- // INPUTS #######################################################################################
- // ##############################################################################################
- showLabels = input.string(title='Show Labels', defval='Closest to Price Only', options=['All', 'Closest to Price Only', 'None'])
- // MM Lines
- altRes = input(title='Use Alternative Timeframe', defval=false)
- resolution = input.timeframe(title='Alternative Timeframe for MML', defval='60')
- priceSrc = input.string(title='Source', defval='High/Low', options=['High/Low', 'Open/Close'])
- frame = input.int(title='Frame Size', defval=64, minval=8, maxval=256)
- multiplier = input.float(title='Frame Multiplier', defval=1.5, minval=1.0, maxval=2.0, step=0.5)
- addXtraLines = input(title='Use Extended Octave (i.e., add extra interval lines at top and bottom)', defval=true)
- numXtraLines = input.string(title='Number of Additional Lines', defval='4', options=['2', '4', '6'])
- // Colors
- labelCol = input(#ffa726, 'Color of MML label text')
- majorCol = input(color.blue, 'Color of major lines (0/8, 4/8, and 8/8)')
- rangeCol = input(color.green, 'Color of trading range lines (3/8 and 5/8)')
- pivotCol = input(color.orange, 'Color of pivot lines (2/8 and 6/8)')
- weakCol = input(color.maroon, 'Color of weak support/resistance lines (1/8 and 7/8')
- xtraCol = input(color.silver, 'Color of additional lines')
- fiblabelCol = input(color.white, 'Color of MML label text')
- pvtCol = input(color.white, 'Color of fibonacci pivot')
- fibSCol = input(color.lime, 'Color of fibonacci support lines')
- fibRCol = input(color.red, 'Color of fibonacci resistance lines')
- // ##############################################################################################
- // CALCULATIONS #################################################################################
- // ##############################################################################################
- // Finding Prices and Range
- pHigh = priceSrc == 'High/Low' ? high : math.max(open, close)
- pLow = priceSrc == 'High/Low' ? low : math.min(open, close)
- h = ta.highest(pHigh, math.round(frame * multiplier))
- l = ta.lowest(pLow, math.round(frame * multiplier))
- nRes = altRes ? resolution : timeframe.period
- nHigh = request.security(syminfo.tickerid, nRes, h)
- nLow = request.security(syminfo.tickerid, nRes, l)
- range_1 = nHigh - nLow
- // Determining Applicable Fractal Value
- fractal = if nHigh <= 250000 and nHigh > 25000
- 100000
- else if nHigh <= 25000 and nHigh > 2500
- 10000
- else if nHigh <= 2500 and nHigh > 250
- 1000
- else if nHigh <= 250 and nHigh > 25
- 100
- else if nHigh <= 25 and nHigh > 6.25
- 12.5
- else if nHigh <= 6.25 and nHigh > 3.125
- 6.25
- else if nHigh <= 3.125 and nHigh > 1.5625
- 3.125
- else if nHigh <= 1.5625 and nHigh > 0.390625
- 1.5625
- else
- 0.1953125
- // Calculating the Octave
- sum = math.floor(math.log(fractal / range_1) / math.log(2))
- octave = fractal * math.pow(0.5, sum)
- minimum = math.floor(nLow / octave) * octave
- maximum = minimum + octave > nHigh ? minimum + octave : minimum + 2 * octave
- // Finding the Top
- t2 = if nLow >= 3 * (maximum - minimum) / 16 + minimum and nHigh <= 9 * (maximum - minimum) / 16 + minimum
- minimum + (maximum - minimum) / 2
- else
- 0
- t1 = if nLow >= minimum - (maximum - minimum) / 8 and nHigh <= 5 * (maximum - minimum) / 8 + minimum and t2 == 0
- minimum + (maximum - minimum) / 2
- else
- 0
- t4 = if nLow >= minimum + 7 * (maximum - minimum) / 16 and nHigh <= 13 * (maximum - minimum) / 16 + minimum
- minimum + 3 * (maximum - minimum) / 4
- else
- 0
- t5 = if nLow >= minimum + 3 * (maximum - minimum) / 8 and nHigh <= 9 * (maximum - minimum) / 8 + minimum and t4 == 0
- maximum
- else
- 0
- t3 = if nLow >= minimum + (maximum - minimum) / 8 and nHigh <= 7 * (maximum - minimum) / 8 + minimum and t1 == 0 and t2 == 0 and t4 == 0 and t5 == 0
- minimum + 3 * (maximum - minimum) / 4
- else
- 0
- t6 = if t1 + t2 + t3 + t4 + t5 == 0
- maximum
- else
- 0
- top = t1 + t2 + t3 + t4 + t5 + t6
- // Finding the Bottom
- b1 = if t1 > 0
- minimum
- else
- 0
- b2 = if t2 > 0
- minimum + (maximum - minimum) / 4
- else
- 0
- b3 = if t3 > 0
- minimum + (maximum - minimum) / 4
- else
- 0
- b4 = if t4 > 0
- minimum + (maximum - minimum) / 2
- else
- 0
- b5 = if t5 > 0
- minimum + (maximum - minimum) / 2
- else
- 0
- b6 = if top > 0 and b1 + b2 + b3 + b4 + b5 == 0
- minimum
- else
- 0
- bottom = b1 + b2 + b3 + b4 + b5 + b6
- // MMI
- mmi = (top - bottom) / 8
- // Set MM Lines
- plus3 = bottom + 11 * mmi
- plus2 = bottom + 10 * mmi
- plus1 = bottom + 9 * mmi
- eight = bottom + 8 * mmi
- seven = bottom + 7 * mmi
- six = bottom + 6 * mmi
- five = bottom + 5 * mmi
- four = bottom + 4 * mmi
- three = bottom + 3 * mmi
- two = bottom + 2 * mmi
- one = bottom + mmi
- zero = bottom
- minus1 = bottom - mmi
- minus2 = bottom - 2 * mmi
- minus3 = bottom - 3 * mmi
- // ##############################################################################################
- // MML PLOTS AND LABELS #########################################################################
- // ##############################################################################################
- plotPlus3 = addXtraLines and (numXtraLines == '8' or numXtraLines == '6') ? plus3 : na
- plotPlus2 = addXtraLines and (numXtraLines == '8' or numXtraLines == '6' or numXtraLines == '4') ? plus2 : na
- plotPlus1 = addXtraLines ? plus1 : na
- plotMinus3 = addXtraLines and (numXtraLines == '8' or numXtraLines == '6') ? minus3 : na
- plotMinus2 = addXtraLines and (numXtraLines == '8' or numXtraLines == '6' or numXtraLines == '4') ? minus2 : na
- plotMinus1 = addXtraLines ? minus1 : na
- // Plot Lines
- plot(plotPlus3, title='11/8 Line', style=plot.style_line, color=xtraCol, linewidth=2, trackprice=true, offset=-9999)
- plot(plotPlus2, title='10/8 Line', style=plot.style_line, color=xtraCol, linewidth=2, trackprice=true, offset=-9999)
- plot(plotPlus1, title='9/8 Line', style=plot.style_line, color=xtraCol, linewidth=2, trackprice=true, offset=-9999)
- plot(eight, title='8/8 Line', style=plot.style_line, color=majorCol, linewidth=4, trackprice=true, offset=-9999)
- plot(seven, title='7/8 Line', style=plot.style_line, color=weakCol, linewidth=2, trackprice=true, offset=-9999)
- plot(six, title='6/8 Line', style=plot.style_line, color=pivotCol, linewidth=2, trackprice=true, offset=-9999)
- plot(five, title='5/8 Line', style=plot.style_line, color=rangeCol, linewidth=2, trackprice=true, offset=-9999)
- plot(four, title='4/8 Line', style=plot.style_line, color=majorCol, linewidth=4, trackprice=true, offset=-9999)
- plot(three, title='3/8 Line', style=plot.style_line, color=rangeCol, linewidth=2, trackprice=true, offset=-9999)
- plot(two, title='2/8 Line', style=plot.style_line, color=pivotCol, linewidth=2, trackprice=true, offset=-9999)
- plot(one, title='1/8 Line', style=plot.style_line, color=weakCol, linewidth=2, trackprice=true, offset=-9999)
- plot(zero, title='0/8 Line', style=plot.style_line, color=majorCol, linewidth=4, trackprice=true, offset=-9999)
- plot(plotMinus1, title='-1/8 Line', style=plot.style_line, color=xtraCol, linewidth=2, trackprice=true, offset=-9999)
- plot(plotMinus2, title='-2/8 Line', style=plot.style_line, color=xtraCol, linewidth=2, trackprice=true, offset=-9999)
- plot(plotMinus3, title='-3/8 Line', style=plot.style_line, color=xtraCol, linewidth=2, trackprice=true, offset=-9999)
- // Labels
- plus3Label = addXtraLines and (showLabels == 'All' or showLabels == 'Closest to Price Only' and close > plus2) ? plus3 : na
- plotshape(plus3Label, style=shape.labeldown, location=location.absolute, color=#00000000, textcolor=labelCol, show_last=1, text='+3', offset=10)
- plus2Label = addXtraLines and (showLabels == 'All' or showLabels == 'Closest to Price Only' and close > plus1 and close < plus3) ? plus2 : na
- plotshape(plus2Label, style=shape.labeldown, location=location.absolute, color=#00000000, textcolor=labelCol, show_last=1, text='+2', offset=10)
- plus1Label = addXtraLines and (showLabels == 'All' or showLabels == 'Closest to Price Only' and close > eight and close < plus2) ? plus1 : na
- plotshape(plus1Label, style=shape.labeldown, location=location.absolute, color=#00000000, textcolor=labelCol, show_last=1, text='+1', offset=10)
- eightLabel = showLabels == 'All' or showLabels == 'Closest to Price Only' and close > seven and close < plus1 ? eight : na
- plotshape(eightLabel, style=shape.labeldown, location=location.absolute, color=#00000000, textcolor=labelCol, show_last=1, text='8/8', offset=10)
- sevenLabel = showLabels == 'All' or showLabels == 'Closest to Price Only' and close > six and close < eight ? seven : na
- plotshape(sevenLabel, style=shape.labeldown, location=location.absolute, color=#00000000, textcolor=labelCol, show_last=1, text='7/8', offset=10)
- sixLabel = showLabels == 'All' or showLabels == 'Closest to Price Only' and close > five and close < seven ? six : na
- plotshape(sixLabel, style=shape.labeldown, location=location.absolute, color=#00000000, textcolor=labelCol, show_last=1, text='6/8', offset=10)
- fiveLabel = showLabels == 'All' or showLabels == 'Closest to Price Only' and close > four and close < six ? five : na
- plotshape(fiveLabel, style=shape.labeldown, location=location.absolute, color=#00000000, textcolor=labelCol, show_last=1, text='5/8', offset=10)
- fourLabel = showLabels == 'All' or showLabels == 'Closest to Price Only' and close > three and close < five ? four : na
- plotshape(fourLabel, style=shape.labeldown, location=location.absolute, color=#00000000, textcolor=labelCol, show_last=1, text='4/8', offset=10)
- threeLabel = showLabels == 'All' or showLabels == 'Closest to Price Only' and close > two and close < four ? three : na
- plotshape(threeLabel, style=shape.labeldown, location=location.absolute, color=#00000000, textcolor=labelCol, show_last=1, text='3/8', offset=10)
- twoLabel = showLabels == 'All' or showLabels == 'Closest to Price Only' and close > one and close < three ? two : na
- plotshape(twoLabel, style=shape.labeldown, location=location.absolute, color=#00000000, textcolor=labelCol, show_last=1, text='2/8', offset=10)
- oneLabel = showLabels == 'All' or showLabels == 'Closest to Price Only' and close > zero and close < two ? one : na
- plotshape(oneLabel, style=shape.labeldown, location=location.absolute, color=#00000000, textcolor=labelCol, show_last=1, text='1/8', offset=10)
- zeroLabel = showLabels == 'All' or showLabels == 'Closest to Price Only' and close > minus1 and close < one ? zero : na
- plotshape(zeroLabel, style=shape.labeldown, location=location.absolute, color=#00000000, textcolor=labelCol, show_last=1, text='0/8', offset=10)
- minus1Label = addXtraLines and (showLabels == 'All' or showLabels == 'Closest to Price Only' and close > minus2 and close < zero) ? minus1 : na
- plotshape(minus1Label, style=shape.labeldown, location=location.absolute, color=#00000000, textcolor=labelCol, show_last=1, text='-1', offset=10)
- minus2Label = addXtraLines and (showLabels == 'All' or showLabels == 'Closest to Price Only' and close > minus3 and close < minus1) ? minus2 : na
- plotshape(minus2Label, style=shape.labeldown, location=location.absolute, color=#00000000, textcolor=labelCol, show_last=1, text='-2', offset=10)
- minus3Label = addXtraLines and (showLabels == 'All' or showLabels == 'Closest to Price Only' and close < minus2) ? minus3 : na
- plotshape(minus3Label, style=shape.labeldown, location=location.absolute, color=#00000000, textcolor=labelCol, show_last=1, text='-3', offset=10)
Advertisement
Add Comment
Please, Sign In to add comment