I had to color the values green and red because this code would not allow me to apply the background color.
Here is the code that you requested:
input sequenceCount = 1;
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, -maxSideLength) > high or (GetValue(high, -i1, -maxSideLength) == high and count1 == 0) then -1
else if GetValue(high, -i1, -maxSideLength) < 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, maxSideLength) > high or (GetValue(high, i2, maxSideLength) == high and count2 >= 1) then -1
else if GetValue(high, i2, maxSideLength) < 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, -maxSideLength) < low or (GetValue(low, -i3, -maxSideLength) == low and count3 == 0) then -1 else if GetValue(high, -i3, -maxSideLength) > 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, maxSideLength) < low or (GetValue(low, i4, maxSideLength) == low and count4 >= 1) then -1
else if GetValue(low, i4, maxSideLength) > low then count4 + 1 else count4;
def upFractal = if upRightSide == sequenceCount and upLeftSide == sequenceCount then high else Double.NaN;
def downFractal = if downRightSide == sequenceCount and downLeftSide == sequenceCount then low else Double.NaN;
plot data = if !IsNaN(upFractal[1]) then 1 else if !IsNaN(downFractal[1]) then -1 else 0;
data.AssignValueColor(if data > 0 then Color.GREEN else if data < 0 then Color.RED else Color.CURRENT);