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.
-- 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
chance = params.chance or 49.5withbethigh = falsewins on a roll below 49.5, paying 2.00x.basebetisparams.basebetorbalance / 500, which is 0.2% of the starting balance.nextbet = basebet, and every later bet is the same.stopLossisparams.stoplossor 0.10 andtakeProfitisparams.takeprofitor 0.10, both as a share of the starting balance, which the script keeps instart.epsis a tiny tolerance for rounding.- In
dobet(), ifprofitis at or below-start * stopLoss, the script prints the number of bets and the profit, then callsstop(). AstopLossof 0 turns this check off. - The take profit works the same way when
profitreachesstart * takeProfit. - 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).
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.
| Losses in a row | Chance of the streak | Result from a fresh start |
|---|---|---|
| 10 | 1 in 927 (0.108%) | Lost 0.0002 (2.0%), next bet 0.00002 |
| 20 | 1 in 859,355 (0.00012%) | Lost 0.0004 (4.0%), next bet 0.00002 |
| 50 | 1 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.
| Param | Default | What changing it does |
|---|---|---|
| params.chance | 49.5 | Win 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.basebet | balance / 500 | Size of every bet. Bigger bets reach either stop in fewer rolls, so less is wagered per session. |
| params.stoploss | 0.10 | Share of the starting balance the session may lose before stop(). 0 turns it off. |
| params.takeprofit | 0.10 | Share 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