//@version=6 strategy("Strict fractal breakout", overlay = true, initial_capital = 10000, pyramiding = 0, default_qty_type = strategy.fixed, default_qty_value = 1, commission_type = strategy.commission.cash_per_order, commission_value = 1, slippage = 1, margin_long = 100, margin_short = 100) teethFilter = input.bool(true, "Teeth filter") buffer = input.float(0.05, "Price buffer", minval = 0.00001) life = input.int(5, "Eligible entry bars", minval = 1) teethRaw = ta.rma(hl2, 8) teethHere = teethRaw[5] teethAtCenter = teethRaw[7] up = high[2] > high and high[2] > high[1] and high[2] > high[3] and high[2] > high[4] down = low[2] < low and low[2] < low[1] and low[2] < low[3] and low[2] < low[4] var float knownLow = na var float knownHigh = na var bool highEligible = false var bool highUsed = false var float entryPrice = na var float stopPrice = na var int submitted = na var bool pending = false justExited = ta.change(strategy.closedtrades) > 0 if barstate.isconfirmed if up knownHigh := high[2] highUsed := false highEligible := not teethFilter or (not na(teethAtCenter) and high[2] > teethAtCenter) if down knownLow := low[2] if strategy.position_size > 0 pending := false if down stopPrice := math.max(stopPrice, knownLow - buffer) strategy.exit("X", "L", stop = stopPrice) if justExited pending := false strategy.cancel("L") if pending and strategy.position_size == 0 expired = bar_index - submitted >= life if expired or close <= stopPrice strategy.cancel("L") strategy.cancel("X") pending := false valid = not na(knownHigh) and not na(knownLow) valid := valid and highEligible and not highUsed if valid and not pending and not justExited and strategy.position_size == 0 entryPrice := knownHigh + buffer stopPrice := knownLow - buffer if entryPrice > close and stopPrice < close submitted := bar_index highUsed := true pending := true strategy.entry("L", strategy.long, stop = entryPrice) strategy.exit("X", "L", stop = stopPrice) plot(teethHere, "Displayed Teeth", color.blue) plot(pending ? entryPrice : na, "Pending buy stop", color.gray, style = plot.style_linebr) plot(strategy.position_size > 0 ? stopPrice : na, "Protective stop", color.red, style = plot.style_linebr)