# Murrey Math Indicator with Adjustable Bubbles
# Sept 16
# some of the basics from the here and Yahoo user group,
# SJ_MurrayMathFullRange / original on Yahoo -TOS
# original notes potentially look like from StockJock,
# Sept 18/11
# Thanks to Eric, Kumobob, Richard Houser, and a whole bunch of guys @ thinkscripter.com
# You guys really fly the TOS colors,
# This is one of my first code postings to your site,
# bring it back here as this is where some great users are,
# I saw a Murray Math variation on a buddies system who uses AmiBroker,
# did some quick checking on thinkscripter and yahoo, this is an update,
# I'm not 100% sure of all the math, but it seems to match the Amibroker math,
# and it seems to have a lot more functionality than they deliver,
# R1V2
# changed labels to make them smaller less intrusive,
# added add//remove labels to take them away entirely,
# added additional upper and lower dynamic ranges,
# added today only Yes / No - try keep this screen clean,
# added range to monitor (dynamic for the day as highs and lows are hit)
# added timeframe, works in combinatin with monitor range,
# added the Equity function for non - equity traders, (decimals),
#Hint Murray_Labels: will show all the lables,
#Hint Murray_OnlyToday: will display only today,
#Hint Murray_Autohide_Upper_Lower: will display the upper and lower potential support and resistance areas based on the current close reaching either the upper or lower pivot,
#Hint Murray_Range: specific time ranges to view,
#Hint Murray_timeFrame: this is important in combination with the range,
#Hint Murray_DataType: default is Equity so will be rounded to 2 decimal places, otherwise can use Forex, This is only used for S & R labels and easier screen presentation,
input Murray_Labels = Yes;
input Murray_OnlyToday = No;
input Murray_Range = {default "Regular Hours", "Today Opening", "Today HiLo", "Previous Range", "Screen HiLo"};
input Murray_timeFrame = {default Day, Week, Month, Year};
input Murray_DataType = {default "Equity", "Other"};
def Market_Open_Time = 0930;
def Market_Close_Time = 1615;
def day = GetDay();
def lastDay = GetLastDay();
def isToday = If(day == lastDay, 1, 0);
def shouldPlot = If(Murray_OnlyToday and isToday, 1, If(!Murray_OnlyToday, 1, 0));
def pastOpen = If((SecondsTillTime(Market_Open_Time) > 0), 0, 1);
def pastClose = If((SecondsTillTime(Market_Close_Time) > 0), 0, 1);
def marketOpen = If(pastOpen and !pastClose, 1, 0);
def firstBar = If (day[1] != day, day - 1, 0);
rec regHoursHigh = If(high > regHoursHigh[1] and marketOpen, high, If(marketOpen and !firstBar, regHoursHigh[1], high));
rec regHoursLow = If(low < regHoursLow[1] and marketOpen, low, If(marketOpen and regHoursLow[1] > 0 and !firstBar, regHoursLow[1], low));
def rangehigh;
def rangelow;
def type;
switch (Murray_Range) {
case "Previous Range":
rangehigh = high(period = Murray_timeFrame)[1];
rangelow = low(period = Murray_timeFrame)[1];
type = 1;
case "Today Opening":
rangehigh = high(period = Murray_timeFrame);
rangelow = low(period = Murray_timeFrame);
type = 2;
case "Regular Hours":
rangehigh = regHoursHigh;
rangelow = regHoursLow;
type = 3;
case "Today HiLo":
rangehigh = high(period = "day");
rangelow = low(period = "day");
type = 4;
case "Screen HiLo":
rangehigh = HighestAll(high);
rangelow = LowestAll(low);
type = 5;
}
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;
### if using Forex - remove the round function to get full decimal places,
# roundit(variable, 2) # number of decimels,
def MML8;
def MML7;
def MML6;
def MML5;
def MML4;
def MML3;
def MML2;
def MML1;
def MML0;
def UpperL2;
def UpperL1;
def LowerL1;
def LowerL2;
switch (Murray_DataType){
case "Equity":
MML8 = rangehigh;
MML7 = Round(rangelow + RangeSize * (MMLevel7), 1);
MML6 = Round(rangelow + RangeSize * (MMLevel6), 1);
MML5 = Round(rangelow + RangeSize * (MMLevel5), 1);
MML4 = Round(rangelow + RangeSize * (MMLevel4), 1);
MML3 = Round(rangelow + RangeSize * (MMLevel3), 1);
MML2 = Round(rangelow + RangeSize * (MMLevel2), 1);
MML1 = Round(rangelow + RangeSize * (MMLevel1), 1);
MML0 = Round(rangelow, 2);
# added 2 upper and lower potential Murray S & R levels,
UpperL2 = rangehigh + (RangeSize * 2 /8);
UpperL1 = rangehigh + RangeSize / 8;
LowerL1 = rangelow - RangeSize / 8;
LowerL2 = rangelow - (RangeSize * 2 / 8);
case "Other":
MML8 = rangehigh;
MML7 = rangelow + RangeSize * (MMLevel7);
MML6 = rangelow + RangeSize * (MMLevel6);
MML5 = rangelow + RangeSize * (MMLevel5);
MML4 = rangelow + RangeSize * (MMLevel4);
MML3 = rangelow + RangeSize * (MMLevel3);
MML2 = rangelow + RangeSize * (MMLevel2);
MML1 = rangelow + RangeSize * (MMLevel1);
MML0 = rangelow;
# added 2 upper and lower potential Murray S & R levels,
UpperL2 = rangehigh + (RangeSize * 2 /8);
UpperL1 = rangehigh + RangeSize / 8;
LowerL1 = rangelow - RangeSize / 8;
LowerL2 = rangelow - (RangeSize * 2 / 8);
}
plot Top;
plot Level7;
plot PivotUp;
plot Level5;
plot Mid;
plot Level3;
plot PivotDn;
plot Level1;
plot Base;
if Murray_OnlyToday
then {
Top = Double.NaN;
Level7 = Double.NaN;
PivotUp = Double.NaN;
Level5 = Double.NaN;
Mid = Double.NaN;
Level3 = Double.NaN;
PivotDn = Double.NaN;
Level1 = Double.NaN;
Base = Double.NaN;
} else {
Top = MML8;
Level7 = MML7;
PivotUp = MML6;
Level5 = MML5;
Mid = MML4;
Level3 = MML3;
PivotDn = MML2;
Level1 = MML1;
Base = MML0;
}
#plot UpperR2 = if type==1 then UpperL2 else Double.NaN;
#plot UpperR1 = if type==1 then UpperL1 else Double.NaN;
#plot LowerS1 = if type==1 then LowerL1 else Double.NaN;
#plot LowerS2 = if type==1 then LowerL2 else Double.NaN;
plot UpperR2 = UpperL2;
plot UpperR1 = UpperL1;
plot LowerS1 = LowerL1;
plot LowerS2 = LowerL2;
input n = 4;#Hint n: Move Chart Bubbles to right by "n" bars
def n1 = n - 1;
def TimeCondition = IsNaN(close[n1]) and !IsNaN(close[n]);
UpperR2.SetDefaultColor(Color.MAGENTA);
UpperR2.SetStyle(Curve.SHORT_DASH);
UpperR2.HideBubble();
AddChartBubble(Murray_Labels && TimeCondition , UpperL2[n], Concat("M-R2:", UpperL2[n]), Color.MAGENTA, yes);
UpperR1.SetDefaultColor(Color.GRAY);
UpperR1.SetStyle(Curve.SHORT_DASH);
UpperR1.HideBubble();
AddChartBubble(Murray_Labels && TimeCondition , UpperL1[n], Concat("M-R1:", UpperL1[n]), Color.GRAY, yes);
#8/8
Top.SetDefaultColor(Color.GRAY);
Top.SetStyle(Curve.LONG_DASH);
Top.HideBubble();
#AddChartBubble(Murray_Labels && TimeCondition , MML8[n], Concat("Top:", MML8[n]), Color.CYAN, yes);
AddChartBubble(Murray_Labels && TimeCondition , MML8[n], "8/8:" + astext(MML8[n]), Color.CYAN, yes);
#7/8
Level7.SetDefaultColor(Color.LIGHT_ORANGE);
Level7.SetStyle(Curve.SHORT_DASH);
Level7.HideBubble();
#AddChartBubble(Murray_Labels && TimeCondition , MML7[n], Concat("R:", MML7[n]), Color.LIGHT_ORANGE, yes);
AddChartBubble(Murray_Labels && TimeCondition , MML7[n], "7/8:" + astext(MML7[n]), Color.LIGHT_ORANGE, yes);
#6/8
PivotUp.SetDefaultColor(Color.PINK);
PivotUp.SetStyle(Curve.SHORT_DASH);
PivotUp.HideBubble();
#AddChartBubble(Murray_Labels && TimeCondition , MML6[n], Concat("P:", PivotUp), Color.PINK, yes);
AddChartBubble(Murray_Labels && TimeCondition , MML6[n], "6/8:" + astext(PivotUp), Color.PINK, yes);
#5/8
Level5.SetDefaultColor(Color.DARK_GREEN);
Level5.SetStyle(Curve.SHORT_DASH);
Level5.HideBubble();
#AddChartBubble(Murray_Labels && TimeCondition , MML5[n], Concat("R:", MML5[n]), Color.DARK_GREEN, yes);
AddChartBubble(Murray_Labels && TimeCondition , MML5[n], "5/8:" + astext(MML5[n]), Color.DARK_GREEN, yes);
#4/8
Mid.SetDefaultColor(Color.WHITE);
Mid.SetStyle(Curve.LONG_DASH);
Mid.HideBubble();
#AddChartBubble(Murray_Labels && TimeCondition , MML4[n], Concat("Mid:", MML4[n]), Color.WHITE, yes);
AddChartBubble(Murray_Labels && TimeCondition , MML4[n], "4/8:" + astext(MML4[n]), Color.WHITE, yes);
#3/8
Level3.SetDefaultColor(Color.DARK_GREEN);
Level3.SetStyle(Curve.SHORT_DASH);
Level3.HideBubble();
#AddChartBubble(Murray_Labels && TimeCondition , MML3[n], Concat("R:", MML3[n]), Color.DARK_GREEN, yes);
AddChartBubble(Murray_Labels && TimeCondition , MML3[n], "3/8:" + astext(MML3[n]), Color.DARK_GREEN, yes);
#2/8
PivotDn.SetDefaultColor(Color.PINK);
PivotDn.SetStyle(Curve.SHORT_DASH);
PivotDn.HideBubble();
#AddChartBubble(Murray_Labels && TimeCondition , MML2[n], Concat("P:", PivotDn[n]), Color.PINK, yes);
AddChartBubble(Murray_Labels && TimeCondition , MML2[n], "2/8:" + astext(PivotDn[n]), Color.PINK, yes);
#1/8
Level1.SetDefaultColor(Color.LIGHT_ORANGE);
Level1.SetStyle(Curve.SHORT_DASH);
Level1.HideBubble();
#AddChartBubble(Murray_Labels && TimeCondition , MML1[n], Concat("R:", MML1[n]), Color.LIGHT_ORANGE, yes);
AddChartBubble(Murray_Labels && TimeCondition , MML1[n], "1/8:" + astext(MML1[n]), Color.LIGHT_ORANGE, yes);
#0/8
Base.SetDefaultColor(Color.GRAY);
Base.SetStyle(Curve.SHORT_DASH);
Base.HideBubble();
#AddChartBubble(Murray_Labels && TimeCondition , MML0[n], Concat("Base:", MML0[n]), Color.CYAN, yes);
AddChartBubble(Murray_Labels && TimeCondition , MML0[n], "0/8:" + Astext(MML0[n]), Color.CYAN, yes);
LowerS1.SetDefaultColor(Color.GRAY);
LowerS1.SetStyle(Curve.SHORT_DASH);
LowerS1.HideBubble();
AddChartBubble(Murray_Labels && TimeCondition , LowerL1[n], Concat("M-S1:", LowerL1[n]), Color.GRAY, yes);
LowerS2.SetDefaultColor(Color.MAGENTA);
LowerS2.SetStyle(Curve.LONG_DASH);
LowerS2.HideBubble();
AddChartBubble(Murray_Labels && TimeCondition , LowerL2[n], Concat("M-S2:", LowerL2[n]), Color.MAGENTA, yes);
AddLabel(yes, Concat("*Murray- ", Concat(Murray_Range, Concat(" - ", Murray_timeFrame))),
if close > Level5 then Color.GREEN else
if close < Level3 then Color.RED else Color.GRAY );
#==============================================