-- Delayed Escalation (low chance / high payout with pre-roll)
-- Bet the minimum for the first `preroll` losses in a row, then start multiplying.
-- At 3.35% chance the payout is ~29.5x, so one hit after a long drought clears the
-- escalation. The pre-roll keeps turnover tiny while waiting for the streak to mature.

chance  = params.chance or 3.35
bethigh = false

basebet = params.basebet or balance / 50000
nextbet = basebet

local preroll    = params.preroll or 50        -- losses to wait before escalating
local multiplier = params.multiplier or 1.04   -- growth per loss once escalating
local maxLosses  = params.maxlosses or 240     -- bail out (stop) if the drought is absurd

local lossRun = 0

function dobet()
  if win then
    lossRun = 0
    nextbet = basebet
    return
  end

  lossRun = lossRun + 1
  if lossRun >= maxLosses then
    print("Stopping: " .. lossRun .. " losses in a row, drawdown " .. string.format("%.8f", -profit))
    stop()
    return
  end

  if lossRun > preroll then
    nextbet = previousbet * multiplier
  else
    nextbet = basebet
  end
end
