# Mobius
# Mobius on My Trade
# High_Low_Pivots(n value below 10) (Swing High Swing Low n value +21)
# V001.06.2012
# modified by vollermist in 2023, includes HH,LH,HL,LL bubbles
#input bias = {default long, short};
input n = 9;
def decimal_places = 2; #input decimal_places = 2 for stocks; #default 5 for forex etc.
input showPricesHL = yes;
input ShowLines = yes;
input showBubblesHL = yes;
def o = open;
def h = high;
def l = low;
def c = close;
def nan = Double.NaN;
def bar1 = BarNumber();
def ph;
def pl;
def isH = fold i = 1
to n + 1
with p = 1
while p
do h > GetValue(h, -i);
ph = if (bar1 > n
and h == Highest(h, n)
and isH)
then RoundUp(h,decimal_places)
else Double.NaN;
def isL = fold j = 1
to n + 1
with q = 1
while q
do l < GetValue(low, -j);
pl = if (bar1 > n
and l == Lowest(l, n)
and isL)
then RoundDown(l,decimal_places)
else Double.NaN;
rec phl = if !IsNaN(ph)
then RoundUp(ph,decimal_places)
else phl[1];
rec pll = if !IsNaN(pl)
then RoundDown(pl,decimal_places)
else pll[1];
def pivotH = if showPricesHL then ph else nan;
plot pivotHigh = if showPricesHL then pivotH else nan;
pivotHigh.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
pivotHigh.SetDefaultColor(CreateColor(255,0,0));
plot pivotHighLine = if phl > 0
then phl
else Double.NaN;
pivotHighLine.SetHiding(!ShowLines);
pivotHighLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotHighLine.SetDefaultColor(CreateColor(255,0,0));
plot pivotLow = if showPricesHL then pl else nan;
pivotLow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
pivotLow.SetDefaultColor(CreateColor(0,255,0));
plot pivotLowLine = if pll > 0
then pll
else Double.NaN;
pivotLowLine.SetHiding(!ShowLines);
pivotLowLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotLowLine.SetDefaultColor(CreateColor(0,255,0));
##############################################################
### Additions by vollermist
def unitriskA = pivotHighLine - pivotLow;
def unitriskB = pivotHigh - pivotLowLine;
def unitriskC = pivotHighLine - pivotLowLine;
def unitrisk = AbsValue(if !IsNaN(unitriskA) then unitriskA else if !IsNaN(unitriskB) then unitriskB else unitriskC);
############################
########## Bubbles #########
############################
def barnow = IsNaN(close[-1]) and !IsNaN(close);
def bubbleoffset = 0.01;
######################################
### HH, LH, HL, LL bubbles
def pHigh = GetValue(if !IsNaN(pivotHigh) then pivotHighLine[1] else pHigh[1], 0);
def pLow = GetValue(if !IsNaN(pivotLow) then pivotLowLine[1] else pLow[1], 0);
def HH = pivotHigh > pHigh;
def LH = pivotHigh < pHigh;
def HL = pivotLow > pLow;
def LL = pivotLow < pLow;
AddChartBubble(showBubblesHL and HH, text = "HH", "price location" = high + bubbleoffset, color = Color.LIME, yes);
AddChartBubble(showBubblesHL and LH, text = "LH", "price location" = high + bubbleoffset, color = Color.PINK, yes);
AddChartBubble(showBubblesHL and HL, text = "HL", "price location" = low - bubbleoffset, color = Color.LIGHT_GREEN, no);
AddChartBubble(showBubblesHL and LL, text = "LL", "price location" = low - bubbleoffset, color = Color.LIGHT_RED, no);