Skip to content
DiceSim

Flat betting · 49.5% chance

Flat betting dice script with stop loss and take profit

Flat betting means staking the same amount on every roll. This dice script bets 0.00002 at 49.5% for a 2.00x payout and uses stop() for a stop loss at 10% and a take profit at 10% of the starting balance.

With no progression it is the baseline for every other script here. The expected loss is the house edge times the total wagered, and a progression only changes how that loss is spread out. With the defaults the stop loss is reached first 73.1% of the time.

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.

luaflat-betting.lua
-- Flat betting with stop loss and take profit
-- Bet the same amount on every roll and stop when the session is down or up by a set
-- share of the starting balance. No progression, so this is the baseline to compare
-- other systems against: the expected loss is the house edge times the total wagered.

chance  = params.chance or 49.5
bethigh = false

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

local stopLoss   = params.stoploss or 0.10     -- stop when down 10% of the starting balance (0 = off)
local takeProfit = params.takeprofit or 0.10   -- stop when up 10% of the starting balance (0 = off)

local start = balance
local eps   = basebet * 1e-6   -- float tolerance on the thresholds

function dobet()
  if stopLoss > 0 and profit <= eps - start * stopLoss then
    print("Stop loss hit after " .. bets .. " bets, profit " .. string.format("%.8f", profit))
    stop()
    return
  end
  if takeProfit > 0 and profit >= start * takeProfit - eps then
    print("Take profit hit after " .. bets .. " bets, profit " .. string.format("%.8f", profit))
    stop()
    return
  end
  nextbet = basebet
end

How it works

  1. chance = params.chance or 49.5 with bethigh = false wins on a roll below 49.5, paying 2.00x.
  2. basebet is params.basebet or balance / 500, which is 0.2% of the starting balance. nextbet = basebet, and every later bet is the same.
  3. stopLoss is params.stoploss or 0.10 and takeProfit is params.takeprofit or 0.10, both as a share of the starting balance, which the script keeps in start. eps is a tiny tolerance for rounding.
  4. In dobet(), if profit is at or below -start * stopLoss, the script prints the number of bets and the profit, then calls stop(). A stopLoss of 0 turns this check off.
  5. The take profit works the same way when profit reaches start * takeProfit.
  6. Otherwise nextbet = basebet.

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.00002 (balance / 500).

Payout2.00x(100 - 1) / 49.5
Chance the stop loss hits first73.1%Down 50 base bets (10%) before up 50 (10%)
Chance the take profit hits first26.9%Up 50 base bets before down 50
Expected bets per session2,311Average number of bets until one of the two stops
Expected loss per session0.000462131% of the 0.04621303 wagered on average

A flat bet never grows, so a losing streak costs one base bet per loss. The table mostly shows where the stop loss ends the session: 50 losses in a row from the start. Since such a streak almost never happens, sessions end through a slow drift over many bets. The tiles above use the gambler's ruin formula for a bet that wins or loses exactly one base bet, which holds at 49.5% and a 2.00x payout.

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.0002 (2.0%), next bet 0.00002
201 in 859,355 (0.00012%)Lost 0.0004 (4.0%), next bet 0.00002
501 in 6.8e14 (1.5e-13%)Script stops. Lost 0.001 (10.0%)

Theoretical figures for a fresh start, not a simulation. The chance of N losses in a row is qN with q = 1 - chance / 100, the same formula the dice calculator uses. The stop loss and take profit figures are the gambler’s ruin formulas for a bet that wins or loses one base bet: with r = q / p, the chance of reaching the take profit first is (1 - rL) / (1 - rL+W), where L and W are the two thresholds in base bets. 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 Flat betting script
ParamDefaultWhat changing it does
params.chance49.5Win chance per roll. It changes the payout and how much the balance swings, while the expected loss stays 1% of the amount wagered. The stop odds on this page assume 49.5%.
params.basebetbalance / 500Size of every bet. Bigger bets reach either stop in fewer rolls, so less is wagered per session.
params.stoploss0.10Share of the starting balance the session may lose before stop(). 0 turns it off.
params.takeprofit0.10Share of the starting balance to win before stop(). 0 turns it off. A target further away takes more bets to reach, so it is reached less often.

FAQ

Do a stop loss and take profit improve the odds?

No. They decide when a session ends, and with that the spread of results, but each bet still loses 1% of its size on average. With the defaults the average session places 2,311 bets, wagers 0.04621303 and loses 0.00046213, which is 1% of the amount wagered.

Why is the stop loss hit more often than the take profit when both are 10%?

Each bet wins 49.5% of the time, a little under half, and the session has to travel 50 base bets either way. Over the 2,311 bets of an average session that small gap adds up, so the stop loss comes first 73.1% of the time and the take profit 26.9%.

Does a bigger flat bet change the result?

It shortens the session. With bets of 1% of the starting balance instead of 0.2%, each stop is 10 base bets away, an average session takes 100 bets, and the take profit comes first 45.0% of the time. Less is wagered, so the expected loss per session drops to 0.00009967 from 0.00046213. Each bet still loses 1% of its size on average.

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. 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

Martingale + vault

Martingale that moves half of every 1% profit step to the vault with vault().

Chance
49.5%
Type
Martingale