# Support and Resistance # Mobius # V01.01.2011 # User Inputs input n = 5; #hint n: Length for calculations. # Internal Script Reference script LinePlot { input LineLimit = 0; input OnExpansion = yes; input data = close; input bar = 0; def ThisBar = HighestAll(bar); def cLine = if bar == ThisBar then data else Double.NaN; plot P = if ThisBar - LineLimit <= bar then HighestAll(cLine) else Double.NaN; } # Variables def o = open; def h = high; def l = low; def c = close; def bar = BarNumber(); def hh = fold i = 1 to n + 1 with p = 1 while p do h > GetValue(h, -i); def PH = if (bar > n and h == Highest(h, n) and hh) then h else Double.NaN; def ll = fold j = 1 to n + 1 with q = 1 while q do l < GetValue(l, -j); def PL = if (bar > n and l == Lowest(l, n) and ll) then l else Double.NaN; def PHBar = if !IsNaN(PH) then bar else PHBar[1]; def PLBar = if !IsNaN(PL) then bar else PLBar[1]; def PHL = if !IsNaN(PH) then PH else PHL[1]; def priorPHBar = if PHL != PHL[1] then PHBar[1] else priorPHBar[1]; def PLL = if !IsNaN(PL) then PL else PLL[1]; def priorPLBar = if PLL != PLL[1] then PLBar[1] else priorPLBar[1]; def HighPivots = bar >= HighestAll(priorPHBar); def LowPivots = bar >= HighestAll(priorPLBar); def R1pivot = if PHL > 0 and HighPivots then PHL else Double.NaN; def S1pivot = if LowPivots then PL else Double.NaN; def R1value = R1pivot; def R1bar = PHbar; def R1limit = bar - R1bar; def R2bar = priorPHbar; def R2limit = bar - R2bar; def R2value = if barNumber() == HighestAll(R2bar) then h else R2value[1]; def R3bar = if priorPHbar != priorPHbar[1] then priorPHbar[1] else R3bar[1]; def R3limit = bar - R3bar; def R3value = if barNumber() == HighestAll(R3bar) then h else R3value[1]; def S1value = S1pivot; def S1bar = PLbar; def S1limit = bar - S1bar; def S2bAR = PriorPLBar; def S2limit = bar - S2bar; def S2value = if bar == HighestAll(S2bar) then l else S2value[1]; def S3bar = if priorPLbar != priorPLbar[1] then priorPLbar[1] else S3bar[1]; def S3limit = bar - S3bar; def S3value = if barNumber() == HighestAll(S3bar) then l else S3value[1]; def BubbleLocation = isNaN(close[1]) and !isNaN(close[2]); # Plots plot FP4 = LinePlot(Linelimit = R1Limit, data = R1value, bar = R1bar); plot FP5 = LinePlot(LineLimit = R2limit, data = R2value, bar = R2bar).P; plot FP6 = LinePlot(LineLimit = R3limit, data = R3value, bar = R3bar).P; plot FP1 = LinePlot(LineLimit = S1limit, data = S1value, bar = S1bar).P; plot FP2 = LinePlot(LineLimit = S2limit, data = S2value, bar = S2bar).P; plot FP3 = LinePlot(LineLimit = S3limit, data = S3value, bar = S3bar).P; FP4.AssignValueColor(if FP4 == Min(Min(FP4, FP5), FP6) then Color.white else if FP4 == Max(Max(FP4, FP5), FP6) then Color.white else Color.white); addChartBubble(BubbleLocation, FP4, if FP4 == Min(Min(FP4, FP5),FP6) then "FP4" else if FP4 == Max(Max(FP4, FP5), FP6) then "FP6" else "FP5", if FP4 == Min(Min(FP4, FP5), FP6) then Color.white else if FP4 == Max(Max(FP4, FP5), FP6) then Color.white else Color.white); FP5.AssignValueColor(if FP5 == Min(Min(FP4,FP5), FP6) then Color.white else if FP5 == Max(Max(FP4, FP5), FP6) then Color.white else Color.white); addChartBubble(BubbleLocation, FP5, if FP5 == Min(Min(FP4, FP5), FP6) then "FP4" else if FP5 == Max(Max(FP4, FP5), FP6) then "FP6" else "FP5", if FP5 == Min(Min(FP4, FP5), FP6) then Color.white else if FP5 == Max(Max(FP4, FP5), FP6) then Color.white else Color.white); FP6.AssignValueColor(if FP6 == Min(Min(FP4, FP5), FP6) then Color.white else if FP6 == Max(Max(FP4, FP5), FP6) then Color.white else Color.white); addChartBubble(BubbleLocation, FP6, if FP6 == Min(Min(FP4, FP5), FP6) then "FP4" else if FP6 == Max(Max(FP4, FP5), FP6) then "FP6" else "FP5", if FP6 == Min(Min(FP4, FP5), FP6) then Color.white else if FP6 == Max(Max(FP4, FP5), FP6) then Color.white else Color.white); FP1.AssignValueColor(if FP1 == Min(Min(FP1, FP2), FP3) then Color.white else if FP1 == Max(Max(FP1, FP2), FP3) then Color.white else Color.white); addChartBubble(BubbleLocation, FP1, if FP1 == Min(Min(FP1, FP2), FP3) then "FP3" else if FP1 == Max(Max(FP1, FP2), FP3) then "FP1" else "FP2", if FP1 == Min(Min(FP1, FP2), FP3) then Color.white else if FP1 == Max(Max(FP1, FP2), FP3) then Color.white else Color.white); FP2.AssignValueColor(if FP2 == Min(Min(FP1, FP2), FP3) then Color.white else if FP2 == Max(Max(FP1, FP2), FP3) then Color.white else Color.white); addChartBubble(BubbleLocation, FP2, if FP2 == Min(Min(FP1, FP2), Fp3) then "FP3" else if FP2 == Max(Max(FP1, FP2), FP3) then "FP1" else "FP2", if FP2 == Min(Min(FP1, FP2), FP3) then Color.white else if FP2 == Max(Max(FP1, FP2), FP3) then Color.white else Color.white); FP3.AssignValueColor(if FP3 == Min(Min(FP1, FP2), FP3) then Color.white else if FP3 == Max(Max(FP1, FP2), FP3) then Color.white else Color.white); addChartBubble(BubbleLocation, FP3, if FP3 == Min(Min(FP1, FP2), FP3) then "FP3" else if FP3 == Max(Max(FP1, FP2), FP3) then "FP1" else "FP2", if FP3 == Min(Min(FP1, FP2), FP3) then Color.white else if FP3 == Max(Max(FP1, FP2), FP3) then Color.white else Color.white); #alert(close crosses above RS, "", Alert.Bar, Sound.Chimes); #alert(close crosses above R2, "", Alert.Bar, Sound.Chimes); #alert(close crosses above R3, "", Alert.Bar, Sound.Chimes); #alert(close crosses below S1, "", Alert.Bar, Sound.Ring); #alert(close crosses below S2, "", Alert.Bar, Sound.Ring); #alert(close crosses below S3, "", Alert.Bar, Sound.Ring); # End Code Support and Resistance