ckryza

Murrey Lines v1.0.0

TradingView implementation of Murrey Math Lines
Remove from Favorite Scripts Add to Favorite Scripts
//-- Murrey Lines for TradingView
//-- 06/24/2016
//-- Chris Kryza - Divergence Software, Inc.
//-- Partial port from original eSignal version
//******************************************************************************
//-- Murrey Math is a trading methodology developed by Prof. TH Murrey
//-- and it is based on the theories of WD Gann. Prof. Murrey has
//-- written a book which describes his methodology in detail and he
//-- also offers seminars at various times during the year. More information
//-- on Prof. Murrey's methodology can be found at his web site, which is
//-- www.MurreyMathTrading.com.
//*********************************************************************
//-- This script generates a template that can be used in conjuction with
//-- Mr. Murrey's methodology. This script will only be useful to you if
//-- you have a good understanding of the Murrey Math trading methodology.
//-- This script can be used on any bar interval and with any security.
//******************************************************************************

//******************************************************************************
//-- Inputs
//-- Frame Size: Input 8, 16, 32,64, 128, or 256
//-- Frame Multiplier: Input 1.0, 1.5, or 2.0
//-- Ignore Wicks: Input true or false
//******************************************************************************

study("Murrey Lines v1.0.0", overlay=true)
//-- get inputs
frame = input(defval=64, title="Frame Size", type=integer, minval=8, maxval=256 )
mult = input( defval=1.5, title="Frame Multiplier", type=float, minval=1.0, maxval=2.0, step=0.5)
wicks = input( defval=true, title="Ignore Wicks?")

//-- defines
logTen = log(10)
log8 = log(8)
log2 = log(2)
lookback = round(frame * mult)

//-- determine price values based on ignore wick selection
uPrice = wicks==true ? max(open,close) : high
lPrice = wicks==true ? min(open,close) : low

//-- find highest/lowest price over specified lookback
vLow = lowest(lPrice,lookback)
vHigh = highest(uPrice,lookback)
vDist = vHigh-vLow
//-- if low price is < 0 then adjust accordingly
tmpHigh = vLow<0 ? (0-vLow) : vHigh
tmpLow = vLow<0 ? ((0-vLow)-vDist) : vLow

//-- determine if price shift is in place
shift = vLow<0 ? true : false

//-- calculate scale frame
sfVar = log(0.4*tmpHigh)/logTen-floor(log(0.4*tmpHigh)/logTen)
SR = tmpHigh>25 ? ( sfVar>0 ? exp(logTen*(floor(log(0.4*tmpHigh)/logTen)+1)) : exp(logTen*(floor(log(0.4*tmpHigh)/logTen))) ) : 100*exp(log8*(floor(log(0.005*tmpHigh)/log8)))
nVar1 = (log(SR/(tmpHigh-tmpLow))/log8)
nVar2 = nVar1-floor(nVar1)
N = nVar1<=0 ? 0 : ( nVar2==0 ? floor(nVar1) : floor(nVar1)+1 )

//-- calculate scale interval and temporary frame top and bottom
SI = SR*exp(-(N)*log8)
M = floor(((1.0/log2)*log((tmpHigh-tmpLow)/SI)) + 0.0000001)
I = round(((tmpHigh+tmpLow)*0.5)/(SI*exp((M-1)*log2)))

Bot = (I-1)*SI*exp((M-1)*log2)
Top = (I+1)*SI*exp((M-1)*log2)

//-- determine if frame shift is required
doShift = ((tmpHigh-Top)>0.25*(Top-Bot)) or ((Bot-tmpLow)>0.25*(Top-Bot))

ER = doShift==true ? 1 : 0

MM = ER==0 ? M : (ER==1 and M<2) ? M+1 : 0
NN = ER==0 ? N : (ER==1 and M<2) ? N : N-1

//-- recalculate scale interval and top and bottom of frame, if necessary
finalSI = ER==1 ? (SR*exp(-(NN)*log8)) : SI
finalI = ER==1 ? round(((tmpHigh+tmpLow)*0.5)/(finalSI*exp((MM-1)*log2))) : I
finalBot = ER==1 ? (finalI-1)*finalSI*exp((MM-1)*log2) : Bot
finalTop = ER==1 ? (finalI+1)*finalSI*exp((MM-1)*log2) : Top

//-- determine the increment
Increment = (finalTop-finalBot)/8

//-- determine the absolute top
absTop = shift==true ? -(finalBot-(3*Increment) ) : finalTop+(3*Increment)

//-- create our Murrey line variables based on absolute top and the increment
Plus38 = absTop
Plus28 = absTop - Increment
Plus18 = absTop - (2 * Increment)
EightEight = absTop - (3 * Increment)
SevenEight = absTop - (4 * Increment)
SixEight = absTop - (5 * Increment)
FiveEight = absTop - (6 * Increment)
FourEight = absTop - (7 * Increment)
ThreeEight = absTop - (8 * Increment)
TwoEight = absTop - (9 * Increment)
OneEight = absTop - (10 * Increment)
ZeroEight = absTop - (11 * Increment)
Minus18 = absTop - (12 * Increment)
Minus28 = absTop - (13 * Increment)
Minus38 = absTop - (14 * Increment)

//-- plot the lines and we are done
plot( Plus38, title="+3/8", style=line, color=green, linewidth = 1)
plot( Plus28, title="+2/8", style=line, color=red, linewidth = 1)
plot( Plus18, title="+1/8", style=line, color=gray, linewidth = 1)
plot(EightEight, title="8/8",style=line, color=blue,linewidth=2) 
plot(SevenEight, title="7/8",style=line, color=gray,linewidth=1) 
plot(SixEight, title="6/8",style=line, color=red,linewidth=1) 
plot(FiveEight, title="5/8",style=line, color=green,linewidth=1) 
plot(FourEight, title="4/8",style=line, color=blue,linewidth=2) 
plot(ThreeEight, title="3/8",style=line, color=green,linewidth=1) 
plot(TwoEight, title="2/8",style=line, color=red,linewidth=1) 
plot(OneEight, title="1/8",style=line, color=gray,linewidth=1) 
plot(ZeroEight, title="0/8",style=line, color=blue,linewidth=2) 
plot(Minus18, title="-1/8",style=line, color=gray,linewidth=1) 
plot(Minus28, title="-2/8",style=line, color=red,linewidth=1) 
plot(Minus38, title="-3/8",style=line, color=green,linewidth=1) 
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out