Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function MarketMake(time, starttime, stoptime)
- 'Our code still submits orders constantly, but realistically,
- 'we only want it to submit orders when we have no open orders in the book.
- 'Our pending orders are displayed with comma’s separating the fields,
- 'and semicolons separating each order: [Order1;Order2;Order3].
- 'We can use the semicolon to count the number of orders in the book:
- '1)if there’s nothing in this box, we know there’s no orders;
- '2)if there’s more than 1 semicolon in this box, we know there’s more than 2 orders.
- 'Once again we alter our trading code,
- 'so that orders are only submitted when no orders are in the book,
- 'and we also add code to cancel our existing orders whenever there’s only 1 order remaining.
- 'Our resulting program
- '1)submits two orders when we have no orders;
- '2)it cancels all orders if we only have 1 order;
- '3)it does nothing, otherwise.
- 'This means we always have 2 orders in the book (a bid and an ask).
- 'Initialize the API
- Dim API As RIT2.API
- Set API = New RIT2.API
- Dim Status As Boolean
- 'Run the algorithm during certain case time
- If time < starttime And time > stoptime Then
- 'Check if any orders in the book. If you have no orders, put in a bracket.
- If Range("J6") > 4999 Then
- Dim n As Integer
- n = Range("J6") \ 5000
- Dim index As Integer
- index = 1
- Do While index <= n
- Status = API.AddOrder(Range("STK_1"), Range("defaultsize"), Range("midmarket") - Range("defaultspread"), API.SELL, API.MKT)
- index = index + 1
- Loop
- End If
- If Range("J6") < -4999 Then
- Dim n1 As Integer
- n1 = Range("J6") \ 5000
- Dim index1 As Integer
- index1 = 1
- Do While index1 <= n1
- Status = API.AddOrder(Range("STK_1"), Range("defaultsize"), Range("midmarket") - Range("defaultspread"), API.BUY, API.MKT)
- index1 = index1 + 1
- Loop
- End If
- If Range("openorders") = "" Then
- 'The following loop submits the Buy section of bracket
- Status = False
- Do While Status = False
- Status = API.AddOrder(Range("STK_1"), Range("defaultsize"), Range("midmarket") - Range("defaultspread"), API.BUY, API.LMT)
- Status = API.AddOrder(Range("STK_1"), Range("defaultsize"), Range("midmarket") - Range("defaultspread"), API.BUY, API.LMT)
- Loop
- 'The following loop submits the Sell section of bracket
- Status = False
- Do While Status = False
- Status = API.AddOrder(Range("STK_1"), Range("defaultsize"), Range("midmarket") + Range("defaultspread"), API.SELL, API.LMT)
- Status = API.AddOrder(Range("STK_1"), Range("defaultsize"), Range("midmarket") + Range("defaultspread"), API.SELL, API.LMT)
- Loop
- '1 second pause
- Sleep (1500)
- Else
- 'Cancel all orders
- API.CancelOrderExpr ("price>0")
- API.CancelQueuedOrder ("price>0")
- API.ClearQueuedOrders
- 'ElseIf Range("J6") > 4999 And Range("H24") < 5000 Then
- 'Status = API.AddOrder(Range("STK_1"), 5000, Range("H8") + Range("D15"), API.SELL, API.LMT)
- 'ElseIf Range("J6") < -4999 And Range("H24") < 5000 Then
- 'Status = API.AddOrder(Range("STK_1"), 5000, Range("H8") - Range("D15"), API.BUY, API.LMT)
- 'Sleep (50)
- 'Checks the openorders to see if there's more than one order in the book
- '(semicolon indicates multiple orders, no semicolon indicates only 1 order)
- End If
- End If
- MarketMake = Range("PL")
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement