Any suggestions?
Before anyone asks here it is
- Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)
Dim currentMarket As String
Dim marketChanged As Boolean
Dim FSB As Double
Dim FSL As Double
Dim SSB As Double
Dim SSL As Double
Dim stake As Double
Dim cancelbet As Double
stake = 5
If Target.Columns.Count = 16 Then
If Cells(1, 1).Value <> currentMarket Then
currentMarket = Cells(1, 1).Value
marketChanged = True
Else
marketChanged = False
End If
Application.EnableEvents = False
If ba Is Nothing Then
Set ba = New BettingAssistantCom.ComClass
ba.includeNonRunners = False
'ba.keepBetType = 0
ba.refreshRate = 0.2
End If 'ba isnothing
If marketChanged = True Then
FSB = -1 'first selection back price
FSL = -1 'first selection lay price
SSB = -1 'second selection back price
SSL = -1 'second selection lay price
Range("Q5", "ZZ100").Clear
End If 'marketchanged
Dim p As Byte, fav As Byte, n As Byte
fav = 5
p = 5
Do While Cells(p, 1).Value <> ""
If Cells(p, 6).Value < Cells(fav, 6).Value Then
fav = p
End If
p = p + 1
Loop
Dim liquid As Boolean
If Cells(fav, 8).Value < ticks(Cells(fav, 6).Value, 3) Then
liquid = True
Else
liquid = False
End If
n = p - 4
If n = 2 And Cells(1, 23).Value > 5 Then
Dim bets As Variant, i As Integer
Dim firstbackbet As Integer, firstlaybet As Integer
Dim secbackbet As Integer, seclaybet As Integer
bets = ba.getBets
firstbackbet = -1
firstlaybet = -1
secbackbet = -1
seclaybet = -1
If Not IsEmpty(bets(0)) Then 'find unmatched bets
For i = 0 To UBound(bets)
If bets(i).matched = False Then 'record bet index in bets and bet odds
If bets(i).selection = Cells(5, 1).Value And bets(i).bettype = "B" Then
If FSB < 1 Then
FSB = bets(i).odds
End If
If Not bets(i).odds / (bets(i).odds - 1) < Cells(6, 6).Value Or (bets(i).odds > Cells(5, 8).Value And Cells(5, 8).Value / (Cells(5, 8).Value - 1) < Cells(6, 6).Value) Then 'cancel bet
cancelbet = ba.cancelbet(bets(i).ref)
FSB = -1
End If
firstbackbet = i
End If 'first sel back
If bets(i).selection = Cells(6, 1).Value And bets(i).bettype = "L" Then
If SSL < 1 Then
SSL = bets(seclaybet).odds
End If
If Not bets(i).odds / (bets(i).odds - 1) > Cells(5, 8).Value Or (bets(i).odds < Cells(6, 6).Value And Cells(6, 6).Value / (Cells(6, 6).Value - 1) > Cells(5, 8).Value) Then
cancelbet = ba.cancelbet(bets(i).ref)
SSL = -1
End If
seclaybet = i
End If 'second sel lay
If bets(i).selection = Cells(5, 1).Value And bets(i).bettype = "L" Then
If FSL < 1 Then
FSL = bets(firstlaybet).odds
End If
If Not bets(i).odds / (bets(i).odds - 1) > Cells(6, 8).Value Or (bets(i).odds < Cells(5, 6).Value And Cells(5, 6).Value / (Cells(5, 6).Value - 1) > Cells(6, 8).Value) Then
cancelbet = ba.cancelbet(bets(i).ref)
FSL = -1
End If
firstlaybet = i
End If 'first sel lay
If bets(i).selection = Cells(6, 1).Value And bets(i).bettype = "B" Then
If SSB < 1 Then
SSB = bets(secbackbet).odds
End If
If Not bets(i).odds / (bets(i).odds - 1) < Cells(5, 6).Value Or (bets(i).odds > Cells(6, 8).Value And Cells(6, 8).Value / (Cells(6, 8).Value - 1) < Cells(5, 6).Value) Then
cancelbet = ba.cancelbet(bets(i).ref)
SSB = -1
End If
secbackbet = i
End If ' second sel back
End If 'bet unmatched
Next i
End If 'not isempty
'place counter bet of any matched bet and exit sub
'first selection back bet matched
If FSB > 1 And firstbackbet = -1 Then 'select odds
Cells(6, 18).Value = 1.01
If FSB < Cells(6, 6).Value Then 'calculate stake
Cells(6, 19).Value = stake * Cells(6, 6).Value / FSB
Else
Cells(6, 19).Value = stake
End If 'firstbackbetodds < second sel back odds
Cells(6, 17).Value = "BACK" 'and place the bet
FSB = -1
Exit Sub
End If 'FSB matched
'first selection lay bet matched
If FSL > 1 And firstlaybet = -1 Then
Cells(6, 18).Value = 1000
If FSL < Cells(6, 8).Value Then
Cells(6, 19).Value = stake * Cells(6, 8).Value / FSL
Else
Cells(6, 19).Value = stake
End If
Cells(6, 17).Value = "LAY"
FSL = -1
Exit Sub
End If 'FSL matched
'second selection back bet matched
If SSB > 1 And secbackbet = -1 Then
Cells(5, 18).Value = 1.01
If SSB < Cells(5, 6).Value Then
Cells(5, 19).Value = stake * Cells(5, 6).Value / SSB
Else
Cells(5, 19).Value = stake
End If
Cells(5, 17).Value = "BACK"
SSB = -1
Exit Sub
End If 'SSB matched
'second selection lay bet matched
If SSL > 1 And seclaybet = -1 Then
Cells(5, 18).Value = 1000
If SSL < Cells(5, 8).Value Then
Cells(5, 19).Value = stake * Cells(5, 8).Value / SSL
Else
Cells(5, 19).Value = stake
End If
Cells(5, 17).Value = "LAY"
SSL = -1
Exit Sub
End If 'SSL matched
'offer bets into the market
If FSB = -1 And 1 / Cells(5, 8).Value + 1 / Cells(6, 6).Value < 1 Then
FSB = 0
Cells(5, 18).Value = Cells(5, 8).Value
If Cells(5, 8).Value < Cells(6, 6).Value Then
Cells(5, 19).Value = stake * Cells(6, 6).Value / Cells(5, 8).Value
Else
Cells(5, 19).Value = stake
End If
Cells(5, 17).Value = "BACK"
End If
If FSB = -1 And 1 / Cells(5, 10).Value + 1 / Cells(6, 6).Value < 1 Then
FSB = 0
Cells(5, 18).Value = Cells(5, 10).Value
If Cells(5, 10).Value < Cells(6, 6).Value Then
Cells(5, 19).Value = stake * Cells(6, 6).Value / Cells(5, 10).Value
Else
Cells(5, 19).Value = stake
End If
Cells(5, 17).Value = "BACK"
End If
If SSB = -1 And 1 / Cells(6, 8).Value + 1 / Cells(5, 6).Value < 1 Then
SSB = 0
Cells(6, 18).Value = Cells(6, 8).Value
If Cells(6, 8).Value < Cells(5, 6).Value Then
Cells(6, 19).Value = stake * Cells(5, 6).Value / Cells(6, 8).Value
Else
Cells(6, 19).Value = stake
End If
Cells(6, 17).Value = "BACK"
End If
If SSB = -1 And 1 / Cells(6, 10).Value + 1 / Cells(5, 6).Value < 1 Then
SSB = 0
Cells(6, 18).Value = Cells(6, 10).Value
If Cells(6, 10).Value < Cells(5, 6).Value Then
Cells(6, 19).Value = stake * Cells(5, 6).Value / Cells(6, 10).Value
Else
Cells(6, 19).Value = stake
End If
Cells(6, 17).Value = "BACK"
End If
If FSL = -1 And 1 / Cells(5, 6).Value + 1 / Cells(6, 8).Value > 1 Then
FSL = 0
Cells(5, 18).Value = Cells(5, 6).Value
If Cells(5, 6).Value < Cells(6, 8).Value Then
Cells(5, 19).Value = stake * Cells(6, 8).Value / Cells(5, 6).Value
Else
Cells(5, 19).Value = stake
End If
Cells(5, 17).Value = "LAY"
End If
If FSL = -1 And 1 / Cells(5, 4).Value + 1 / Cells(6, 8).Value > 1 Then
FSL = 0
Cells(5, 18).Value = Cells(5, 4).Value
If Cells(5, 4).Value < Cells(6, 8).Value Then
Cells(5, 19).Value = stake * Cells(6, 8).Value / Cells(5, 4).Value
Else
Cells(5, 19).Value = stake
End If
Cells(5, 17).Value = "LAY"
End If
If SSL = -1 And 1 / Cells(6, 6).Value + 1 / Cells(5, 8).Value > 1 Then
SSL = 0
Cells(5, 18).Value = Cells(6, 6).Value
If Cells(6, 6).Value < Cells(5, 8).Value Then
Cells(6, 19).Value = stake * Cells(5, 8).Value / Cells(6, 6).Value
Else
Cells(6, 19).Value = stake
End If
Cells(6, 17).Value = "LAY"
End If
If SSL = -1 And 1 / Cells(6, 4).Value + 1 / Cells(5, 8).Value > 1 Then
SSL = 0
Cells(5, 18).Value = Cells(6, 4).Value
If Cells(6, 4).Value < Cells(5, 8).Value Then
Cells(6, 19).Value = stake * Cells(5, 8).Value / Cells(6, 4).Value
Else
Cells(6, 19).Value = stake
End If
Cells(6, 17).Value = "LAY"
End If
End If 'n = 2, seconds until off > 5
If Cells(1, 23).Value <= 5 Then
Cells(5, 17).Value = "CLOSEC"
Cells(6, 17).Value = "CLOSEC"
End If
Application.EnableEvents = True
End If
End Sub