Moderator: 2020vision
by osknows » Tue Jan 18, 2011 3:22 pm
by GaryRussell » Tue Jan 18, 2011 3:28 pm
osknows wrote:If your happy for me to do so I can have a look at this later this week and optimize both the read & write routine?
by mak » Tue Jan 18, 2011 3:28 pm
by Shaun » Tue Jan 18, 2011 3:35 pm
by Shaun » Tue Jan 18, 2011 5:02 pm
Option Explicit
Private ifWin() As Currency
Private ifLose() As Currency
Private greenarray() As Variant
Private selecIndex As New Collection
Private plRange As Range, pl As Variant, levelPLRange As Range
Private currentMarket As String
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count = 16 Then
Application.EnableEvents = False
calcGreenUp
Application.EnableEvents = True
End If
End Sub
Private Sub calcGreenUp()
Dim r As Integer, i As Integer
Dim selecName As String
Dim stake As Currency, odds As Currency, win As Currency, lose As Currency, diff As Currency, betType As String
Dim idx As Integer
Dim myBetsRange As Range
r = 2
ReDim ifWin(100)
ReDim ifLose(100)
ReDim greenarray(1 To 51, 1 To 3)
Set myBetsRange = Worksheets("Market 1_MyBets").Cells
If currentMarket <> Cells(1, 1) Then initMarket
pl = plRange
currentMarket = Cells(1, 1)
Do
' calculate win and lose positions
If myBetsRange.Cells(r, 5).Value = "F" Then
selecName = myBetsRange.Cells(r, 2).Value
idx = getIndex(selecName)
If idx <> -1 Then
stake = myBetsRange.Cells(r, 3).Value
odds = myBetsRange.Cells(r, 4).Value
If myBetsRange.Cells(r, 6).Value = "B" Then
ifWin(idx) = ifWin(idx) + (stake * (odds - 1))
ifLose(idx) = ifLose(idx) - stake
Else
ifWin(idx) = ifWin(idx) - (stake * (odds - 1))
ifLose(idx) = ifLose(idx) + stake
End If
End If
End If
r = r + 1
Loop Until myBetsRange.Cells(r, 1).Value = ""
' calculate green up stakes
For r = 5 To 55
getIfWinLose Cells(r, 1).Value, win, lose
If win = lose Then
betType = ""
stake = 0
odds = 0
End If
If win > lose Then
betType = "LAY"
diff = win - lose
odds = Cells(r, 8).Value
If odds <> 0 Then
stake = diff / odds
Else
stake = 0
End If
End If
If win < lose Then
betType = "BACK"
diff = lose - win
odds = Cells(r, 6).Value
If odds <> 0 Then
stake = diff / odds
Else
stake = 0
End If
End If
If stake < 0.01 Then
stake = 0
odds = 0
betType = ""
End If
greenarray(r - 4, 1) = betType
greenarray(r - 4, 2) = stake
greenarray(r - 4, 3) = odds
' Cells(r, 62).Value = betType
' Cells(r, 63).Value = stake
' Cells(r, 64).Value = odds
calculateFuturePL r - 4, betType, stake, odds
Next
Range("BJ5:bl55") = greenarray()
levelPLRange = pl
End Sub
Private Sub calculateFuturePL(r As Integer, betType As String, stake As Currency, odds As Currency)
Dim i As Integer
For i = 1 To UBound(pl)
If betType = "BACK" Then
If i = r Then
pl(i, 1) = pl(i, 1) + (stake * (odds - 1))
Else
pl(i, 1) = pl(i, 1) - stake
End If
Else
If i = r Then
pl(i, 1) = pl(i, 1) - (stake * (odds - 1))
Else
pl(i, 1) = pl(i, 1) + stake
End If
End If
Next
End Sub
Private Sub initMarket()
Dim r As Integer
Set selecIndex = New Collection
r = 5
Do
r = r + 1
Loop Until Cells(r, 1) = ""
Set plRange = Range(Cells(5, 24), Cells(r - 1, 24))
Set levelPLRange = Range(Cells(5, 65), Cells(100, 65))
levelPLRange = ""
Set levelPLRange = Range(Cells(5, 65), Cells(r - 1, 65))
End Sub
Private Function getIndex(selecName As String) As Integer
Dim idx As Integer
Dim r As Integer
Dim found As Boolean
On Error GoTo index_not_found
idx = selecIndex(selecName)
getIndex = idx
Exit Function
index_not_found:
On Error GoTo 0
r = 4
found = False
Do
r = r + 1
If Cells(r, 1).Value = selecName Then
selecIndex.Add r - 5, selecName
found = True
End If
Loop Until found Or Cells(r, 1).Value = ""
If found Then getIndex = r - 5 Else getIndex = -1
End Function
Private Sub getIfWinLose(selecName As String, ByRef win As Currency, ByRef lose As Currency)
Dim idx As Integer
On Error GoTo index_not_found
idx = selecIndex(selecName)
win = ifWin(idx)
lose = ifLose(idx)
Exit Sub
index_not_found:
On Error GoTo 0
win = 0
lose = 0
End Sub
by osknows » Tue Jan 18, 2011 11:05 pm
Option Explicit
Dim marketChanging As Boolean, currentMarket As String
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Dim BA_Array() As Variant, increment As Long, c As Object, firstaddress As String
If Target.Columns.Count = 16 Then
With ThisWorkbook.Sheets(Target.Worksheet.Name)
BA_Array = .Range("A1:BZ55").Value 'read whole block A1:BZ55 Once ONLY (can make as large or small as required)
'.Cells(2, 59) = BA_Array(2,59)
'.Range("Q2").Value = BA_Array(2,17)
'Cells(2, 5) = BA_Array(2,5)
'Cells(2, 6) = BA_Array(2,6)
'[A1] = BA_Array(1,1)
'etc
If BA_Array(2, 59) <= 120 Then
BA_Array(2, 17) = 0.4
Else
BA_Array(2, 17) = 1
End If
If BA_Array(2, 5) = "In Play" And BA_Array(2, 6) = "" Then
'do nothing (this is most frequent scenario so stop further IF statements)
ElseIf BA_Array(2, 5) = "In Play" And BA_Array(2, 6) = "Closed" Then
If Not marketChanging Then
marketChanging = True
currentMarket = BA_Array(1, 1)
.Range("Q2").Value = 1
Else
If BA_Array(1, 1) <> currentMarket Then marketChanging = False
End If
ElseIf BA_Array(2, 5) = "In Play" And BA_Array(2, 6) = "Suspended" Then
If Not marketChanging Then
marketChanging = True
currentMarket = BA_Array(1, 1)
.Range("Q2").Value = -1
Else
If BA_Array(1, 1) <> currentMarket Then marketChanging = False
End If
ElseIf BA_Array(2, 5) = "Not In Play" And BA_Array(2, 6) = "Closed" Then
If Not marketChanging Then
marketChanging = True
currentMarket = BA_Array(1, 1)
.Range("Q2").Value = -1
Else
If BA_Array(1, 1) <> currentMarket Then marketChanging = False
End If
End If
'''''Garys timer inPlay
'' http://www.gruss-software.co.uk/phpBB2/viewtopic.php?t=2404&highlight=cells
If BA_Array(2, 5) <> "In Play" And BA_Array(2, 6) <> "Suspended" Then
.Cells(1, 27) = ""
.Cells(1, 28) = ""
ElseIf BA_Array(2, 5) = "In Play" Then
If BA_Array(1, 27) = "" Then
.Cells(1, 27) = BA_Array(2, 3)
BA_Array(1, 27) = BA_Array(2, 3)
End If
If BA_Array(1, 27) <> "" Then .Cells(1, 28) = DateDiff("s", BA_Array(1, 27), BA_Array(2, 3))
End If
'this is quickest method for searching range
With .Range("T5:T55")
Set c = .Find("CANCELLED", LookIn:=xlValues)
If Not c Is Nothing Then
firstaddress = c.Address
Do
c.Value = ""
Set c = .FindNext(c)
If Not c Is Nothing Then
If c.Address = firstaddress Then c = Nothing
End If
Loop While Not c Is Nothing
End If
End With
End With
End If
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
End Sub
by Shaun » Wed Jan 19, 2011 3:00 am
Set myBetsRange = Worksheets("Market 1_MyBets").Cells
'change to
Set myBetsRange = Worksheets("MyBets").Cells
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count = 16 Then
Application.EnableEvents = False
calcGreenUp
Application.EnableEvents = True
End If
End Sub
by mak » Wed Jan 19, 2011 10:49 am
by osknows » Wed Jan 19, 2011 1:34 pm
If BA_Array(2, 59) <= 120 Then
.Range("Q2").Value = 0.4
Else
.Range("Q2").Value = 1
End If
by mak » Wed Jan 19, 2011 4:26 pm
by osknows » Fri Jan 21, 2011 6:23 pm
The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.
Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.
Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.
He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.
We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.