7 Closes above/below 5 SMA
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kulturdesken
// This script looks for 7 consecutive closes above/below the 5-period SMA. The indicator is inspired by trading legend Linda Raschke's ideas. 
// It can be used in at least two ways. I use it at a learning tool to test models. These are the two models I am testing, inspired by Raschke:
// 1) Persistency of trend / Extended run setup. Around 10-12 times per year we get a persistency of trend in instruments in general. 
// After 7 consecutive closes above/below the 5-period you can re-enter as it moves up/down again. Then try to hold as long as possible. Way longer than you can percieve or think of. Up to 24-28 periods is what we are looking for.
// 2) Normal usage is to use it as a possible oscillating signal, after which we can look for a reverse setup in price action.
// Read Linda Raschkes work to learn more about these ideas.

// I added settings so you can change preferences for changing shape, where to display the shape and in what color

//@version=5
indicator("Closes vs 5", overlay=true)
// Calculate the 5-period SMA
smaPeriod = 5
smaValue = ta.sma(close, smaPeriod)
// Initialize variables
var int consecutiveClosesAbove = 0
var int consecutiveClosesBelow = 0
// Check if the close is above the SMA
isAboveSMA = close > smaValue
// Count consecutive closes above and below the SMA
consecutiveClosesAbove := isAboveSMA ? nz(consecutiveClosesAbove[1]) + 1 : 0
consecutiveClosesBelow := isAboveSMA ? 0 : nz(consecutiveClosesBelow[1]) + 1
// Check if we have reached 7 consecutive closes above the SMA
sevenConsecutiveClosesAbove = consecutiveClosesAbove >= 7 and consecutiveClosesBelow < 7
// Check if we have reached 7 consecutive closes below the SMA
sevenConsecutiveClosesBelow = consecutiveClosesBelow >= 7 and consecutiveClosesAbove < 7
// Plot green dot when 7 consecutive closes above the SMA occur
plotshape(sevenConsecutiveClosesAbove, color=color.green, style=shape.circle, title="7 consecutive closes above SMA", location=location.belowbar)
// Plot red dot when 7 consecutive closes below the SMA occur
plotshape(sevenConsecutiveClosesBelow, color=color.red, style=shape.circle, title="7 consecutive closes below SMA", location=location.abovebar)