#### markos

##### Well-known member

**VIP**

Code:

```
# Fractal Boxes
# Mobius 2017
# Altered Fractals to show Box Breakouts
input sequenceCount = 4;
def maxSideLength = sequenceCount + 10;
def upRightSide = fold i1 = 1 to maxSideLength + 1
with count1
while count1 != sequenceCount and
count1 != -1
do if GetValue(high, -i1) > high or
(GetValue(high, -i1) == high and
count1 == 0)
then -1
else if GetValue(high, -i1) < high
then count1 + 1
else count1;
def upLeftSide = fold i2 = 1 to maxSideLength + 1
with count2
while count2 != sequenceCount and
count2 != -1
do if GetValue(high, i2) > high or
(GetValue(high, i2) == high and
count2 >= 1)
then -1
else if GetValue(high, i2) < high
then count2 + 1
else count2;
def downRightSide = fold i3 = 1 to maxSideLength + 1
with count3
while count3 != sequenceCount and
count3 != -1
do if GetValue(low, -i3) < low or
(GetValue(low, -i3) == low and
count3 == 0)
then -1
else if GetValue(high, -i3) > low
then count3 + 1
else count3;
def downLeftSide = fold i4 = 1 to maxSideLength + 1
with count4
while count4 != sequenceCount and
count4 != -1
do if GetValue(low, i4) < low or
(GetValue(low, i4) == low and
count4 >= 1)
then -1
else if GetValue(low, i4) > low
then count4 + 1
else count4;
def UF = if upRightSide == sequenceCount and
upLeftSide == sequenceCount
then high
else UF[1];
def pUF = if UF != UF[1]
then UF[1]
else pUF[1];
def DF = if downRightSide == sequenceCount and
downLeftSide == sequenceCount
then low
else DF[1];
def pDF = if DF != DF[1]
then DF[1]
else pDF[1];
plot UpFractal = UF;
plot DownFractal = DF;
def trend = if UF > pUF and DF > pDF
then 1
else if UF < pUF and DF < pDF
then -1
else 0;
UpFractal.SetPaintingStrategy(PaintingStrategy.Horizontal);
UpFractal.AssignValueColor(if Trend == 1
then color.green
else if Trend == -1
then color.red
else color.white);
UpFractal.SetLineWeight(2);
DownFractal.SetPaintingStrategy(PaintingStrategy.Horizontal);
DownFractal.AssignValueColor(if Trend == 1
then color.green
else if Trend == -1
then color.red
else color.white);
DownFractal.SetLineWeight(2);
AddCloud(if Trend == 1 then UpFractal else double.nan, DownFractal, Color.green, Color.green);
AddCloud(if Trend == -1 then UpFractal else double.nan, DownFractal, Color.red, Color.red);
AddCloud(if Trend == 0 then UpFractal else double.nan, DownFractal, Color.white, Color.white);
```

Last edited by a moderator: