Is there a way to call pattern in thinkscript ? I want draw an arrow when price at certain level when there is a pattern form, for example when there is fractal pattern form I want to know when the price close above/below the up/down fractal, or when there is a doji form I want to draw arrows when price close below that doji, the code I have only show the fractals but it doesn't show arrow when price is close above/below last fractal, I also try to use wizard but it complete trash.
Code:# Fractal Boxes # Mobius 2017 # Altered Fractals to show Box Breakouts input sequenceCount = 2; 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; plot UpFractal = if upRightSide == sequenceCount and upLeftSide == sequenceCount then high else Double.NaN; plot DownFractal = if downRightSide == sequenceCount and downLeftSide == sequenceCount then low else Double.NaN; UpFractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP); UpFractal.SetDefaultColor(GetColor(3)); UpFractal.SetLineWeight(5); DownFractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN); DownFractal.SetDefaultColor(GetColor(4)); DownFractal.SetLineWeight(5); plot upside = close > UpFractal ; upside.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN); upside.SetDefaultColor(GetColor(3)); upside.SetLineWeight(5); plot Data = close crosses above WilliamsFractal()."UpFractal" within 15 bars; Data.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN); Data.SetDefaultColor(GetColor(3)); Data.SetLineWeight(5);
This may help you develop the code as you want. It adds the TOS doji indicator from the patterns dropdown in the upper right corner of the charr to the code you posted. It is displayed as a Line.
Code:# Fractal Boxes # Mobius 2017 # Altered Fractals to show Box Breakouts input sequenceCount = 2; 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; plot UpFractal = if upRightSide == sequenceCount and upLeftSide == sequenceCount then high else Double.NaN; plot DownFractal = if downRightSide == sequenceCount and downLeftSide == sequenceCount then low else Double.NaN; UpFractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP); UpFractal.SetDefaultColor(GetColor(3)); UpFractal.SetLineWeight(5); DownFractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN); DownFractal.SetDefaultColor(GetColor(4)); DownFractal.SetLineWeight(5); plot upside = close > UpFractal ; upside.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN); upside.SetDefaultColor(GetColor(3)); upside.SetLineWeight(5); plot Data = close crosses above WilliamsFractal()."UpFractal" within 15 bars; Data.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN); Data.SetDefaultColor(GetColor(3)); Data.SetLineWeight(5); # # TD Ameritrade IP Company, Inc. (c) 2007-2023 # #wizard text: Inputs: length: #wizard input: length #wizard text: body factor: #wizard input: bodyFactor input length = 20; input bodyFactor = 0.05; assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor); def d = if IsDoji(length, bodyFactor) then close else d[1]; plot Doji = d; Doji.SetPaintingStrategy(PaintingStrategy.LINE); Doji.SetDefaultColor(CreateColor(153, 153, 255)); Doji.SetLineWeight(3);