Skip to content
DiceSim

Martingale · 49.5% chance

Martingale with profit vault dice bot script (Lua)

This martingale with profit vault script doubles the bet after each loss and resets it after a win, like the basic martingale script. Each time the session profit climbs another 1% of the starting balance, it moves 50% of that step to the vault with vault().

Vaulted money still counts as profit and can never be bet again. From a fresh start the losing streak that empties the balance is the same as for the basic script, 13 losses in a row at 49.5%. When it comes, it takes what is in the balance and leaves the vault alone.

The script

Lua 5.4 with DiceBot-style globals. The top level runs once to set chance and the first nextbet, then dobet() runs after every roll. Every global is described in the Lua reference.

luamartingale-vault.lua
-- Martingale with a profit vault
-- Classic martingale: multiply the bet after a loss, reset after a win. Each time the
-- session profit climbs another `step`, move part of that step to the vault with
-- vault(). Vaulted funds count as profit but can never be bet, so a later bust only
-- takes what is still in the balance.

chance  = 49.5
bethigh = false

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

local multiplier = params.multiplier or 2.0      -- bet multiplier after a loss
local step       = params.step or balance / 100   -- profit gained between two vault deposits
local share      = params.share or 0.5            -- fraction of each step moved to the vault

local nextLock = step

function dobet()
  if win then
    nextbet = basebet
  else
    nextbet = previousbet * multiplier
  end

  -- profit includes the vault, so vaulting does not move the next threshold
  while step > 0 and profit >= nextLock do
    vault(step * share)
    nextLock = nextLock + step
  end
end

How it works

  1. chance = 49.5 and bethigh = false win on a roll below 49.5, paying 2.00x.
  2. basebet is params.basebet or balance / 10000, which is 0.01% of the starting balance.
  3. multiplier is params.multiplier or 2.0, step is params.step or balance / 100 (0.0001 on a 0.01 balance), and share is params.share or 0.5. nextLock starts at step.
  4. dobet() first sets the bet: basebet after a win, previousbet * multiplier after a loss.
  5. Then, while profit is at or above nextLock, it calls vault(step * share) and raises nextLock by one step. profit includes vaulted funds, so a deposit does not lower it.
  6. There is no stop rule. The run ends at your roll count, when you stop it, or when nextbet is larger than balance. The vault stays part of the session profit in every case.

Risk at a glance

Settings: 49.5% chance, 1% house edge, starting balance 0.01 (the template default, BTC in the simulator), base bet 0.000001 (balance / 10000).

Payout2.00x(100 - 1) / 49.5
Losses in a row to empty it13Those bets total 0.008191; the next one is more than what is left.
Chance of that streak1 in 7,1980.014% that 13 given rolls all lose
Expected rolls before it14,539Average wait for the first such streak
Chance within 10,000 rolls49.7%Chance the streak shows up at least once

From a fresh start this script bets exactly like the basic martingale, so the calculator's model applies and the numbers below match the basic martingale page. The vault changes what a bust costs: the balance is lost and the vault is kept. Each deposit also leaves less in the balance, so later runs of doubled bets have less to draw on than they would without the vault.

Cost of a straight losing run from a fresh start
Losses in a rowChance of the streakResult from a fresh start
101 in 927 (0.108%)Lost 0.001023 (10.2%), next bet 0.001024
131 in 7,198 (0.014%)Lost 0.008191 (81.9%). The next bet, 0.008192, is more than the 0.001809 left
151 in 28,225 (0.0035%)Out of money after 13 losses
201 in 859,355 (0.00012%)Out of money after 13 losses

Theoretical figures for a fresh start, not a simulation. The chance of N losses in a row is qN with q = 1 - chance / 100, and the expected rolls before such a streak is (1 - qᴺ) / ((1 - q) × qᴺ). These are the same formulas the dice calculator uses. The 10,000-roll figure is 1 - e-10,000 / expected rolls, the chance that the streak shows up at least once. None of this changes the expected result: at a 1% house edge the average loss is 1% of the total wagered, whatever the progression.

Tuning it

Each setting below is read as params.name or default, so the script runs with the default until something passes a value in.

Parameters read by the Martingale + vault script
ParamDefaultWhat changing it does
params.basebetbalance / 10000Size of the first bet. Halving it lets the balance cover one more loss in a row and halves the profit per winning run.
params.multiplier2.0Growth per loss. At 2.00x, 2.0 is the smallest value where one win pays back a losing run of any length.
params.stepbalance / 100Profit between two vault deposits. A smaller step vaults sooner and more often, in smaller amounts.
params.share0.5Fraction of each step moved to the vault. 1 vaults the whole step and 0 turns the vault off.

FAQ

Does the vault make martingale profitable?

No. The vault moves money the script has already won out of reach of later bets. Each bet still loses 1% of its size on average, and a run of 13 losses still empties a fresh 0.01 balance. What changes is how much a bust takes: the balance goes, the vaulted profit stays.

How often does the script vault?

At 2.00x each win of a martingale run adds exactly one base bet to the profit, because it pays back the losses of the run plus one base bet. With the defaults the step is 100 base bets, so a deposit of 0.00005 happens every 100 wins, as long as no bust comes first.

What does vault() do?

It moves an amount from balance to the vault, never more than the balance holds, and returns the amount moved. Vaulted funds are included in profit and vaulted, and no bet can use them.

Can I run this script in DiceBot or another Lua dice bot?

The script uses the global names from Seuntjie's DiceBot (chance, bethigh, nextbet, previousbet, win, dobet()). The params table only exists in DiceSim, so replace each params.name or value with the value before you paste it into another bot. It also calls vault(), so check that your bot provides it. DiceSim itself never places bets on a casino.

Other scripts

Martingale

Doubles the bet after each loss and goes back to the base bet after a win.

Chance
49.5%
Type
Martingale

Delayed escalation

Bets 3.35% for a 29.55x payout. Flat bets through 50 losses, then 4% more per loss.

Chance
3.35%
Type
Dynamic scaling

Paroli 3-step

Doubles after a win, banks the profit after 3 wins in a row, resets on any loss.

Chance
49.5%
Type
Paroli

Dynamic recovery

Sizes each bet so one win recovers the drawdown plus one base bet, capped at 10% of balance.

Chance
33%
Type
Recovery

D'Alembert

Adds one unit after a loss and removes one after a win, never going below the base bet.

Chance
49.5%
Type
D'Alembert

Labouchere

Bets the first plus the last number of a list. Wins cross numbers off, losses add one.

Chance
49.5%
Type
Labouchere

Fibonacci

Bets follow the Fibonacci sequence: one step up after a loss, two steps back after a win.

Chance
49.5%
Type
Fibonacci

Oscar's Grind

Plays in cycles that aim for +1 unit: same bet after a loss, one unit more after a win.

Chance
49.5%
Type
Oscar's Grind

1-3-2-6

Bets 1, 3, 2 and 6 units on consecutive wins. Any loss, or the 4th win, resets to 1.

Chance
49.5%
Type
Positive progression

Flat betting

Same bet on every roll, with a stop loss and a take profit at 10% of the starting balance.

Chance
49.5%
Type
Flat betting