Guest User

Martingale-logging.lua

a guest
Jul 26th, 2021
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.19 KB | None | 0 0
  1. -- *******************************************************
  2. -- Martingale with logging  
  3. -- Use any of these ref links to support this code:
  4. --
  5. -- Script name: Martingale-logging.lua
  6. --
  7. -- *******************************************************
  8.  
  9. -- Default logging goes to the directory where DiceBot is run from.
  10. -- To specify a different log location, you need to edit the 2 lines below.  
  11. -- The two files must be in the same directory!  
  12. filename = "Martingale.log"
  13. csvfile = "Martingale.csv"
  14. tempfile = "tempfile.log"
  15. timeStart = os.time()
  16.  
  17. -- ************************************
  18. -- Comment these next 3 lines if you want to append to the old file.
  19. -- These 3 lines must be un-commented on the very first run, otherwise
  20. -- the script will crash with a LUA error, due to the file not existing.
  21. -- ************************************
  22. fin = assert(io.open(filename, "w"))
  23. fin:write("\n")
  24. fin:close()
  25. -- ************************************
  26. -- Comment the above 3 lines if you want to append to the old file
  27. -- These 3 lines must be un-commented on the very first run, otherwise
  28. -- the script will crash with a LUA error, due to the file not existing.
  29. -- ************************************
  30.  
  31. -- ************************************
  32. -- Comment these next 3 lines if you want to append to the old file.
  33. -- These 3 lines must be un-commented on the very first run, otherwise
  34. -- the script will crash with a LUA error, due to the file not existing.
  35. -- ************************************
  36. fin = assert(io.open(csvfile, "w"))
  37. fin:write("Rolls, Opposites, High Bets, High Rolls, Low Rolls, Low Bets, High Rolls, Low Rolls, Multiplier, Last Bet, Winning Chance, Winning Roll, Spent, Win Amount, Win Profit, Balance, Run Profit\n")
  38. fin:close()
  39. -- ************************************
  40. -- Comment the above 3 lines if you want to append to the old file
  41. -- These 3 lines must be un-commented on the very first run, otherwise
  42. -- the script will crash with a LUA error, due to the file not existing.
  43. -- ************************************
  44.  
  45. -- initialize custom settings
  46. autotune = true
  47. slowdown = 0.5 -- In seconds.  Set this to 0.0 to run at full speed.  Need to slow down for FreeBitco.in
  48. basebet = 0.00000001 -- Your starting bet
  49. maxSlots = 21 -- Need to win by this loss run
  50. logroll = 10 -- Only make a log entry after this many or more rolls per win
  51. minmult = 1.75
  52.  
  53. -- If you want to just play steady, put this at 2.0
  54. multiplier = 2.125 -- Might need to fine tune this one
  55.  
  56. basechance = 45
  57.  
  58. lastWinRollCount = 0
  59. currentRollCount = 0
  60. balanceLastWin = balance
  61. startingBalance = balance
  62. oppositeRolls = 0
  63. oppositeArray = {}
  64. oppositeArrayCount = {}
  65. winCount = 0
  66. rollHighHigh = 0
  67. rollHighLow = 0
  68. rollLowHigh = 0
  69. rollLowLow = 0
  70. SeedResetMax = 100 -- Bitsler does not reset the seed anymore anyway
  71. -- SeedResetMax = (98.5 / chance) / 2 -- Just testing for the shorter reset times
  72. seedResets = 0
  73. roundSpent = 0
  74.  
  75. -- Initialize system settings
  76. nextbet = basebet
  77. chance = basechance
  78. satoshi = 0.00000001
  79.  
  80. -- set up the logging for this run.
  81. -- timestamps are screwed up, otherwise I would have added them
  82. fin = assert(io.open(filename, "r"))
  83. content = fin:read("*a")
  84. fin:close()
  85. fout = assert(io.open(tempfile, "w"))
  86. fout:write(content)
  87. tempstr = "********************************** New run **********************************\r\n"
  88. fout:write(tempstr)
  89. tempstr1 = "Starting balance: replace\r\n"
  90. tempcalc = string.format("%.8f", balance)
  91. tempstr = string.gsub(tempstr1, "replace", tempcalc)
  92. fout:write(tempstr)
  93. fout:close()
  94. os.remove(filename)
  95. os.rename(tempfile, filename)
  96.  
  97. rollCountAverage = {}
  98. rollAverageCount = 0
  99. rollAverageIndex = 0
  100. rollAverageMax = 3 -- Average roll count before a win.  How many wins do you want to average?
  101.  
  102. -- Initialize the array
  103. for i=0, rollAverageMax do
  104.     rollCountAverage[i] = 0
  105. end
  106.  
  107. highLowAverage = {}
  108. averageCount = 0
  109. averageIndex = 0
  110. averageMax = 8 -- High / Low average switching.  How many rolls do you want to average?
  111.  
  112. rollCount = 0
  113. rollSeedCount = 0
  114.  
  115. -- Initialize the array
  116. for i=0, averageMax do
  117.     highLowAverage[i] = 0
  118. end
  119.  
  120.  
  121. local clock = os.clock
  122. function sleep(n)  -- seconds
  123.     local t0 = clock()
  124.     while clock() - t0 <= n do end
  125. end
  126.  
  127. -- Call this routine while it is running to auto-set the multiplier without restarting
  128. -- maxSlots must be set to 0 or autotune set to false for this to stick
  129. function setmult(newmult)
  130.     multiplier = newmult
  131. end
  132.  
  133. -- Call this routine while it is running to set the number of losses + win in a row
  134. -- for the multiplier.
  135. -- set to 0 to use use the manually set setmult() routine
  136. function setslots(newslots)
  137.     maxSlots = newslots
  138. end
  139.  
  140. if(autotune) then
  141.     tempstr = "Setting multiplier for xxx roll loss streak"
  142.     tempstr = string.gsub(tempstr, "xxx", maxSlots)
  143.     print(tempstr) 
  144. end
  145.  
  146. -- auto calculate the multiplier per the slots requested
  147. function tunemult()
  148.     if(autotune and maxSlots > 0) then
  149.         newmult = multiplier
  150.         oldmult = multiplier
  151.         tuned = false
  152.         -- print("Tuning the multiplier.  Please wait")
  153.         while(tuned == false) do -- start with our current multiplier and test
  154.             -- tempstr = "testing: newmult"
  155.             -- tempstr = string.gsub(tempstr, "newmult", newmult)
  156.             -- print(tempstr)
  157.             -- templow = (newmult ^ (maxSlots + 5)) * (basebet) * 0.1
  158.             -- temphigh = (newmult ^ (maxSlots + 6)) * (basebet) * 0.1
  159.             templow = (newmult * basebet * 100000000) ^ (maxSlots + 1)
  160.             temphigh = (newmult * basebet * 100000000) ^ (maxSlots + 2)
  161.             templow /= 100000000
  162.             temphigh /= 100000000
  163.             tempstr = "Balance: bal, Low: low, High: high"
  164.             tempcalc = string.format("%.8f", balance)
  165.             tempstr = string.gsub(tempstr, "bal", tempcalc)
  166.             tempcalc = string.format("%.8f", templow)
  167.             tempstr = string.gsub(tempstr, "low", tempcalc)
  168.             tempcalc = string.format("%.8f", temphigh)
  169.             tempstr = string.gsub(tempstr, "high", tempcalc)
  170.             -- print(tempstr)
  171.             if(templow <= balance and temphigh >= balance) then
  172.                 multiplier = newmult
  173.                 -- round to 0.000 instead of 0.0000000000000000            
  174.                 multiplier *= 1000
  175.                 multiplier = math.floor(multiplier)
  176.                 multiplier /= 1000
  177.                 if(multiplier != oldmult) then
  178.                     tempstr = "New Multiplier: newmult"
  179.                     tempstr = string.gsub(tempstr, "newmult", multiplier)
  180.                     print(tempstr)             
  181.                 end
  182.                 tuned = true
  183.             else
  184.                 if(templow >= balance) then -- multiplier is too high
  185.                     newmult -= 0.001 -- step down till we find a good value
  186.                 end
  187.                 if(temphigh <= balance) then -- multiplier is too low
  188.                     newmult += 0.001 -- step up till we find a good value
  189.                 end
  190.             end
  191.             if(newmult <= minmult) then -- Lowest we can go for now and still make some profit
  192.                 if(oldmult != minmult) then
  193.                     print("Lowest multiplier we can go and still profit")
  194.                     multiplier = minmult
  195.                     tempstr = "New Multiplier: newmult"
  196.                     tempstr = string.gsub(tempstr, "newmult", minmult)
  197.                     print(tempstr)
  198.                 end            
  199.                 tuned = true
  200.             end
  201.            
  202.         end
  203.     end
  204. end
  205.  
  206. -- Start the actual betting
  207. function dobet()
  208.  
  209.     tunemult()
  210.  
  211.     currentRollCount += 1
  212.     rollCount += 1
  213.     roundSpent += lastBet.Amount
  214.    
  215.     -- Store statistics for high / low rolls
  216.     if(lastBet.Roll > 50 and bethigh == true) then -- High roll and was high
  217.         rollHighHigh += 1
  218.     end
  219.     if(lastBet.Roll <= 50 and bethigh == true) then -- High roll and was low
  220.         rollHighLow += 1
  221.     end
  222.     if(lastBet.Roll > 50 and bethigh == false) then -- Low roll and was high
  223.         rollLowHigh += 1
  224.     end
  225.     if(lastBet.Roll <= 50 and bethigh == false) then -- Low roll and was low
  226.         rollLowLow += 1
  227.     end
  228.  
  229.     -- We got a win, let's store some averages
  230.     if(win) then
  231.         -- roundSpent -= lastBet.Amount -- You get your bet back on win
  232.         winCount += 1
  233.         if(rollAverageCount == 0) then -- Initialize so we get a good starting average
  234.             for i=0, rollAverageMax do
  235.                 rollCountAverage[i] = rollCount
  236.             end
  237.             rollAverageIndex += 1
  238.         else
  239.             rollCountAverage[rollAverageIndex] = rollCount
  240.             rollAverageIndex += 1
  241.         end
  242.        
  243.         rollAverageCount += 1
  244.         if(rollAverageCount >= rollAverageMax) then
  245.             rollAverageCount = rollAverageMax -- no need to keep this one climbing
  246.         end
  247.         if(rollAverageIndex >= rollAverageMax) then
  248.             rollAverageIndex = 0 -- reset
  249.         end
  250.         if(rollCount > logroll) then
  251.             -- Write to the log file for review
  252.             fin = assert(io.open(filename, "r"))
  253.             content = fin:read("*a")
  254.             -- print(content)
  255.             fin:close()
  256.            
  257.             fout = assert(io.open(tempfile, "w"))
  258.             fout:write(content)
  259.            
  260.             oppositeTemp = ", , Roll #, Value, , , , , , , , , , , , , , , "
  261.             csvtemp = "Num Rolls, Opposites, High Bets, High High Rolls, High Low Rolls, Low Bets, Low High Rolls, Low Low Rolls, Multiplier, Last Bet, Winning Chance, Winning Roll, Spent, Win Amount, Win Profit, Balance, Run Profit\r\n"
  262.             tempstr = "************************************ Win ************************************\r\n"
  263.             fout:write(tempstr)
  264.             tempstr1 = "Win #: replace\r\n"
  265.             tempstr = string.gsub(tempstr1, "replace", winCount)
  266.             fout:write(tempstr)
  267.             tempstr1 = "Rolls: replace\r\n"
  268.             tempstr = string.gsub(tempstr1, "replace", rollCount)
  269.             csvtemp = string.gsub(csvtemp, "Num Rolls", rollCount)
  270.             fout:write(tempstr)
  271.             tempstr1 = "Opposites: replace\r\n"
  272.             tempstr = string.gsub(tempstr1, "replace", oppositeRolls)
  273.             csvtemp = string.gsub(csvtemp, "Opposites", oppositeRolls)
  274.             fout:write(tempstr)
  275.             oppositeOut = ""
  276.             -- if(oppositeRolls > 0) then
  277.             --  for i=0, oppositeRolls - 1 do
  278.             --      oppositeOut = oppositeOut .. oppositeTemp
  279.             --      tempstr1 = "-- Roll#: rollcount, Value: opposite\r\n"
  280.             --      tempstr = string.gsub(tempstr1, "rollcount", oppositeArrayCount[i])
  281.             --      oppositeOut = string.gsub(oppositeOut, "Roll #", oppositeArrayCount[i])            
  282.             --      tempstr = string.gsub(tempstr, "opposite", oppositeArray[i])
  283.             --      oppositeOut = string.gsub(oppositeOut, "Value", oppositeArray[i])
  284.             --      oppositeOut = oppositeOut .. "\r\n"
  285.             --      fout:write(tempstr)
  286.             --  end
  287.             -- end
  288.             tempstr = "High Bets: hightotal, High Rolls: highrolls, Low Rolls: lowrolls\r\n"
  289.             tempstr = string.gsub(tempstr, "hightotal", rollHighHigh + rollHighLow)
  290.             csvtemp = string.gsub(csvtemp, "High Bets", rollHighHigh + rollHighLow)
  291.             tempstr = string.gsub(tempstr, "highrolls", rollHighHigh)
  292.             csvtemp = string.gsub(csvtemp, "High High Rolls", rollHighHigh)
  293.             tempstr = string.gsub(tempstr, "lowrolls", rollHighLow)
  294.             csvtemp = string.gsub(csvtemp, "High Low Rolls", rollHighLow)
  295.             fout:write(tempstr)
  296.             tempstr = "Low Bets: lowtotal, High Rolls: highrolls, Low Rolls: lowrolls\r\n"
  297.             tempstr = string.gsub(tempstr, "lowtotal", rollLowHigh + rollLowLow)
  298.             csvtemp = string.gsub(csvtemp, "Low Bets", rollLowHigh + rollLowLow)
  299.             tempstr = string.gsub(tempstr, "highrolls", rollLowHigh)
  300.             csvtemp = string.gsub(csvtemp, "Low High Rolls", rollLowHigh)
  301.             tempstr = string.gsub(tempstr, "lowrolls", rollLowLow)
  302.             csvtemp = string.gsub(csvtemp, "Low Low Rolls", rollLowLow)
  303.             fout:write(tempstr)
  304.             tempstr1 = "Multiplier: replace / Slots: slots\r\n"
  305.             tempstr = string.gsub(tempstr1, "replace", multiplier)
  306.             tempstr = string.gsub(tempstr, "slots", maxSlots)
  307.             csvtemp = string.gsub(csvtemp, "Multiplier", multiplier)
  308.             fout:write(tempstr)
  309.             tempstr1 = "Last Bet: replace\r\n"
  310.             tempcalc = string.format("%.8f", nextbet)
  311.             tempstr = string.gsub(tempstr1, "replace", tempcalc)
  312.             csvtemp = string.gsub(csvtemp, "Last Bet", tempcalc)
  313.             fout:write(tempstr)
  314.            
  315.             tempstr1 = "Winning Chance: replace\r\n"
  316.             tempcalc = string.format("%.2f", chance)
  317.             tempstr = string.gsub(tempstr1, "replace", tempcalc)
  318.             csvtemp = string.gsub(csvtemp, "Winning Chance", tempcalc)
  319.             fout:write(tempstr)
  320.             tempstr1 = "Winning Roll: replace\r\n"
  321.             tempcalc = string.format("%.2f", lastBet.Roll)
  322.             tempstr = string.gsub(tempstr1, "replace", tempcalc)
  323.             csvtemp = string.gsub(csvtemp, "Winning Roll", tempcalc)
  324.             fout:write(tempstr)
  325.             tempstr1 = "Spent Out:  replace\r\n"
  326.             tempcalc = string.format("%.8f", roundSpent)
  327.             tempstr = string.gsub(tempstr1, "replace", tempcalc)
  328.             csvtemp = string.gsub(csvtemp, "Spent", tempcalc)
  329.             fout:write(tempstr)
  330.             tempstr1 = "Win Amount: replace\r\n"
  331.             tempcalc = string.format("%.8f", lastBet.Profit)
  332.             tempstr = string.gsub(tempstr1, "replace", tempcalc)
  333.             csvtemp = string.gsub(csvtemp, "Win Amount", tempcalc)
  334.             fout:write(tempstr)
  335.             tempstr1 = "Win Profit: replace\r\n"
  336.             tempcalc = string.format("%.8f", lastBet.Profit - roundSpent + lastBet.Amount)
  337.             tempstr = string.gsub(tempstr1, "replace", tempcalc)
  338.             csvtemp = string.gsub(csvtemp, "Win Profit", tempcalc)
  339.             fout:write(tempstr)
  340.             tempstr1 = "Balance: replace\r\n"
  341.             tempcalc = string.format("%.8f", balance)
  342.             tempstr = string.gsub(tempstr1, "replace", tempcalc)
  343.             csvtemp = string.gsub(csvtemp, "Balance", tempcalc)
  344.             fout:write(tempstr)
  345.             tempstr1 = "Run Profit: replace\r\n"
  346.             tempcalc = string.format("%.8f", balance - startingBalance)
  347.             tempstr = string.gsub(tempstr1, "replace", tempcalc)
  348.             csvtemp = string.gsub(csvtemp, "Run Profit", tempcalc)
  349.             fout:write(tempstr)
  350.    
  351.             fout:close()
  352.             os.remove(filename)
  353.             os.rename(tempfile, filename)
  354.    
  355.             fin = assert(io.open(csvfile, "r"))
  356.             content = fin:read("*a")
  357.             -- print(content)
  358.             fin:close()
  359.            
  360.             fout = assert(io.open(tempfile, "w"))
  361.             fout:write(content)
  362.             fout:write(csvtemp)
  363.             -- fout:write(oppositeOut)
  364.            
  365.             fout:close()
  366.             os.remove(csvfile)
  367.             os.rename(tempfile, csvfile)
  368.         end
  369.        
  370.         rollCount = 0 -- reset for next rolling
  371.         oppositeRolls = 0
  372.         rollSeedCount = 0 -- Keep this seed for now
  373.         rollHighHigh = 0 -- reset counters
  374.         rollHighLow = 0 -- reset counters
  375.         rollLowHigh = 0 -- reset counters
  376.         rollLowLow = 0 -- reset counters
  377.         seedResets = 0
  378.         roundSpent = 0
  379.         chance = basechance
  380.         nextbet = basebet
  381.     end
  382.    
  383.     -- Let's use the averages from previous rolls to see if the bet needs to be changed
  384.     if(!win) then
  385.         oppositeTest = lastBet.Roll
  386.         if(oppositeTest > (100 - chance) and bethigh == false) then -- Test if we were rolling high
  387.             -- print(oppositeTest)
  388.             oppositeArray[oppositeRolls] = oppositeTest
  389.             oppositeArrayCount[oppositeRolls] = rollCount
  390.             oppositeRolls += 1
  391.         end
  392.         if(oppositeTest < chance and bethigh == true) then -- Test if we were rolling low
  393.             -- print(oppositeTest)
  394.             oppositeArray[oppositeRolls] = oppositeTest
  395.             oppositeArrayCount[oppositeRolls] = rollCount
  396.             oppositeRolls += 1
  397.         end
  398.         -- Reset the seed if too long of a losing streak
  399.         rollSeedCount += 1
  400.         if(rollSeedCount > SeedResetMax) then
  401.             -- resetseed()
  402.             rollSeedCount = 0
  403.             seedResets += 1
  404.             -- nextbet = nextbet + basebet -- Increment bet
  405.             -- check to see if we are at our absolute max bet allowed
  406.         end
  407.         nextbet = nextbet * multiplier -- Increment bet
  408.     end
  409.  
  410.     -- Calculate the average, and then change high / low accordingly
  411.     if(lastBet.Roll >= 50) then
  412.         highLowAverage[averageIndex] = 1   
  413.     else
  414.         highLowAverage[averageIndex] = 0
  415.     end
  416.     averageIndex += 1
  417.     if(averageIndex >= averageMax) then
  418.         averageIndex = 0
  419.     end
  420.     if(averageCount < averageMax) then
  421.         averageCount += 1
  422.     end
  423.     average = 0.00
  424.     for i=0, averageCount do
  425.         average += highLowAverage[i]
  426.     end
  427.     average = average / averageCount
  428.     -- print (average)
  429.     if average >= 0.5 then
  430.         bethigh = true
  431.     else
  432.         bethigh = false
  433.     end
  434.     sleep(slowdown)
  435.  
  436. end
Add Comment
Please, Sign In to add comment