Close all Postitions

Please post any questions regarding the program here.

Moderator: 2020vision

Close all Postitions

Postby willow59 » Fri Apr 02, 2021 10:27 am

Looking for help - I currently lay in excel using LAY-TL3-SPC , My question is, how can i close all positions 10 seconds after the market goes in-play automatically.
willow59
 
Posts: 4
Joined: Sat Mar 30, 2019 5:39 am

Re: Close all Postitions

Postby MollyMoo » Sat Apr 03, 2021 12:04 pm

Try this:
Code: Select all
'Place these 3 lines in a Module
Public StartTime As Double
Public RaceHasStarted As Boolean
Public Greened As Boolean
'Routine which runs when a new race is loaded from Quick Pick List
Private Sub Worksheet_Change(ByVal Target As Range)
    Greened = False
    RaceHasStarted = False
End Sub
'Routine which runs when sheet calculates
'Or place code in Worksheet_Change subroutine if running every time odds change
'Code assumes Gruss is connected to Cell A1
Private Sub Worksheet_Calculate()
    Dim lastRow As Integer, i As Integer
    'Replace "SheetConnectedToGruss" with the name of your worksheet connected to Gruss
    With ThisWorkbook.Sheets("SheetConnectedToGruss")
    If Not RaceHasStarted And .Range("E2") = "In Play" Then
        RaceHasStarted = True
        StartTime = Timer
    End If
    If RaceHasStarted And Not Greened And Timer - StartTime >= 10 Then
        lastRow = .Cells(.Rows.Count, 1).End(xlUp).row
        For i = 5 To lastRow
            If .Range("Q" & i) <> vbNullString Then .Range("Q" & i) = "CLOSEC"
        Next i
        Greened = True
    End If
End Sub

MollyMoo
 
Posts: 90
Joined: Mon Sep 11, 2017 9:31 am
Location: UK

Re: Close all Postitions

Postby MollyMoo » Sat Apr 03, 2021 12:21 pm

Forgot the End With!

MollyMoo wrote:Try this:
Code: Select all
'Place these 3 lines in a Module
Public StartTime As Double
Public RaceHasStarted As Boolean
Public Greened As Boolean
'Routine which runs when a new race is loaded from Quick Pick List
Private Sub Worksheet_Change(ByVal Target As Range)
    Greened = False
    RaceHasStarted = False
End Sub
'Routine which runs when sheet calculates
'Or place code in Worksheet_Change subroutine if running every time odds change
'Code assumes Gruss is connected to Cell A1
Private Sub Worksheet_Calculate()
    Dim lastRow As Integer, i As Integer
    'Replace "SheetConnectedToGruss" with the name of your worksheet connected to Gruss
    With ThisWorkbook.Sheets("SheetConnectedToGruss")
    If Not RaceHasStarted And .Range("E2") = "In Play" Then
        RaceHasStarted = True
        StartTime = Timer
    End If
    If RaceHasStarted And Not Greened And Timer - StartTime >= 10 Then
        lastRow = .Cells(.Rows.Count, 1).End(xlUp).row
        For i = 5 To lastRow
            If .Range("Q" & i) <> vbNullString Then .Range("Q" & i) = "CLOSEC"
        Next i
        Greened = True
    End If
    End With
End Sub

MollyMoo
 
Posts: 90
Joined: Mon Sep 11, 2017 9:31 am
Location: UK

Re: Close all Postitions

Postby vanbuuts » Tue Apr 13, 2021 6:49 pm

I'm interested in similar code but this doesn't seem to do anything?

I've embedded into my worksheet module but it didn't trigger anything at 10 seconds?

How does it determine that the race has been in play 10 seconds as I guess that is the crucial part
vanbuuts
 
Posts: 321
Joined: Thu Oct 16, 2014 8:55 pm

Re: Close all Postitions

Postby MollyMoo » Tue Apr 20, 2021 10:48 pm

Did you place the main part of the code in the Private Sub Worksheet_Change routine of the worksheet that's connected to Gruss?

The routine checks for when a race goes in play (Cell E2 = "In Play"). When it does it places the current time into the variable StartTime. Each time the worksheet calculates the routine checks whether the current time minus StartTime is >= 10, i.e. 10 seconds have elapsed since going in play. If it has, all positions are closed (CLOSEC trigger).
MollyMoo
 
Posts: 90
Joined: Mon Sep 11, 2017 9:31 am
Location: UK

Re: Close all Postitions

Postby MollyMoo » Tue Apr 20, 2021 11:20 pm

Also, ensure your Worksheet_Calculate routine starts with Application.EnableEvents = False and ends with Application.EnableEvents = True:

Code: Select all
Private Sub Worksheet_Calculate()
    Application.EnableEvents = False
    Dim lastRow As Integer, i As Integer
    'Replace "SheetConnectedToGruss" with the name of your worksheet connected to Gruss
    With ThisWorkbook.Sheets("SheetConnectedToGruss")
    If Not RaceHasStarted And .Range("E2") = "In Play" Then
        RaceHasStarted = True
        StartTime = Timer
    End If
    If RaceHasStarted And Not Greened And Timer - StartTime >= 10 Then
        lastRow = .Cells(.Rows.Count, 1).End(xlUp).row
        For i = 5 To lastRow
            If .Range("Q" & i) <> vbNullString Then .Range("Q" & i) = "CLOSEC"
        Next i
        Greened = True
    End If
    End With
    Application.EnableEvents = True
End Sub
MollyMoo
 
Posts: 90
Joined: Mon Sep 11, 2017 9:31 am
Location: UK


Return to Help

Who is online

Users browsing this forum: Google [Bot] and 30 guests

Sports betting software from Gruss Software


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.