That looks relatively simple... so I think this code should work.
NOTE: As always, I have not thoroughly tested this... so I accept no responsibility if you lose your entire balance! 
chance = 49.5
basebet = 0.00000001
nextbet = basebet
bethigh = true
lossStreak = 0
hibernate = false
lastMartingale = 0
hibernatebet = 0.00000000 -- primedice zero bets!
function dobet()
if win then
if hibernate then
-- first win after losing streak
-- restart Martingale
nextbet = lastMartingale * 2
lossStreak = 0
hibernate = false
else
nextbet = basebet
lossStreak = 0
end
else
lossStreak = lossStreak + 1
if (lossStreak == 3) then
--losing streak detected, hibernate
hibernate = true
lastMartingale = previousbet
end
if hibernate then
nextbet = hibernatebet
else
nextbet = previousbet * 2
end
end
end