Ok, that last answer provided the final piece needed to complete the code for this. I have simply copied the code from the built in versions of Ichimoku and CCI. I cleaned up the code so that it plots the standard Ichimoku along with 30 period ma. The last eight lines of code are the ones I added to do the pattern detection. See attached screenshot showing a green arrow pointing up where the signal occurs.
input tenkan_period = 9;
input kijun_period = 26;
plot Tenkan = (Highest(high, tenkan_period) + Lowest(low, tenkan_period)) / 2;
plot Kijun = (Highest(high, kijun_period) + Lowest(low, kijun_period)) / 2;
plot "Span A" = (Tenkan[kijun_period] + Kijun[kijun_period]) / 2;
plot "Span B" = (Highest(high[kijun_period], 2 * kijun_period) + Lowest(low[kijun_period], 2 * kijun_period)) / 2;
plot Chikou = close[-kijun_period];
Tenkan.SetDefaultColor(GetColor(1));
Kijun.SetDefaultColor(GetColor(2));
"Span A".SetDefaultColor(GetColor(3));
"Span B".SetDefaultColor(GetColor(4));
Chikou.SetDefaultColor(GetColor(5));
DefineGlobalColor("Bullish", Color.YELLOW);
DefineGlobalColor("Bearish", Color.RED);
AddCloud("Span A", "Span B", globalColor("Bullish"), globalColor("Bearish"));
input length = 14;
def price = close + low + high;
def linDev = lindev(price, length);
def CCI = if linDev == 0 then 0 else (price - Average(price, length)) / linDev / 0.015;
def ma1 = Average(close, 30);
def priceAboveCloud = close > "Span A" and close > "Span B";
def priceAboveMa1 = close > ma1;
def atLeastFiveBarsAboveMa1 = Lowest(priceAboveMa1, 5) > 0;
def firstTouchInFiveBars = atLeastFiveBarsAboveMa1[1] and close < ma1;
plot signal = if firstTouchInFiveBars and CCI < 100 then low else Double.NaN;
signal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
signal.SetDefaultColor(Color.GREEN);
The pullback part may seem easy enough until you start writing code. The other elements are very simple. But what exactly constitutes a pullback? Easy enough to spot them on a chart but the computer needs a perfectly precise definition. For your example screenshot you have 23 candles closing above the 30 MA then a close below it. So how many bars above the 30MA are required before you consider a close below it as a pullback? Greater than 10? Greater than 15? Some other number? And even after we define that rule in the code, you are still not assured of capturing the exact pattern that you consider a pullback. You may find that there are additional details required to get it just the way you expect.