Answer provided first by vitruvius.
Personally, I simply prefer using simple functions.
//@version=5
strategy("Example", overlay = true, process_orders_on_close = true)
//#region -------------------------- INPUT
i_bullLookback = input.int(5, 'Bullish Lookback', inline = '', group = 'Max History', minval = 1)
i_bearLookback = input.int(3, 'Bearish Lookback', inline = '', group = 'Max History', minval = 1)
//#region ---------------------- FUNCTIONS
// @function when a defnied condition is met, count consecutive candles until a given number is reached and returns true as its done.
// @param condition (series bool) provided condtion(s). Here: bullCondition/bearCondition.
// @param lookback (simple int) user input
// @returns (simple bool) true/false
// Dependencies user input.
checkCondition(series bool _condition, simple int _lookback) =>
count = math.sum(_condition ? 1 : 0, _lookback)
count == _lookback ? 1 : 0
//#region ------------------- DECLARATIONS
bool bullCondition = close >= open
bool bearCondition = not bullCondition
// function call
bool longCondition = checkCondition(bullCondition, i_bullLookback)
bool shortCondition = checkCondition(bearCondition, i_bearLookback)
//#region --------------------- STRATEGIES
switch
longCondition =>
strategy.entry("Long ID", strategy.long)
// add more logic as needed
shortCondition =>
strategy.entry("Short ID", strategy.short)
// add more logic as needed