Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Imhotep), 567 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
[Test] mode: Simulate both market *and* limit orders #486244
07/05/22 13:59
07/05/22 13:59
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
This much is obvious:

1) To simulate market orders, you need bid and ask. Your order fills at an unfavorable price.

2) To simulate limit orders, you need tick data. Your order may fill at a favorable price... or it won't fill at all.

But how do you realistically simulate both simultaneously? It sounds like you need both bid-ask and tick data, so there would be multiple datasets loaded per asset, correct?

Example scenario: I patiently open a limit order at 4pm. It's now 4:29pm and the order did not fill yet. I become impatient because the market closes at 4:30pm and convert the order into a market order.

Re: [Test] mode: Simulate both market *and* limit orders [Re: AndrewAMD] #486245
07/05/22 14:59
07/05/22 14:59
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
The .t1 and .t2 formats support ask and bid. You need normally only a single dataset. Set Spread = marketVal() at any tick for a realistic simulation.

Re: [Test] mode: Simulate both market *and* limit orders [Re: AndrewAMD] #486247
07/05/22 15:44
07/05/22 15:44
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Sorry, I was unclear. Yes, *.t1 and *.t2 support bid and ask, but what if I want to account for trade ticks on top of that?

This way, trade ticks are specifically used for simulating limit order fills and bid/ask ticks are specifically used for simulating market order fills.

Re: [Test] mode: Simulate both market *and* limit orders [Re: AndrewAMD] #486251
07/06/22 06:36
07/06/22 06:36
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
In that case you use indeed a second dataset, get the trade ticks with dataset functions, and simulate order fill by script. But why do you need trade ticks at all? Order filling is caused by ask and bid, not by trade ticks.

Re: [Test] mode: Simulate both market *and* limit orders [Re: jcl] #486252
07/06/22 12:51
07/06/22 12:51
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Originally Posted by jcl
But why do you need trade ticks at all? Order filling is caused by ask and bid, not by trade ticks.
Are you sure? Bid and ask price are market prices and are therefore relevant to market orders. But sometimes, when a trader has a buy limit order around bid price, another trader will sell at market, filling the limit order to the buyer's advantage. It is difficult to realistically simulate these kinds of fills without trade ticks.

This is also why IB offers Midprice, Pegged-to-Midpoint, Pegged-to-Primary, etc. orders, because there are people on the opposite end of the trade who will fill these orders.

I have a client that wants to trade better-than-market prices by placing limit orders somewhere between bid and ask.

Re: [Test] mode: Simulate both market *and* limit orders [Re: AndrewAMD] #486255
07/06/22 14:27
07/06/22 14:27
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
When a trader places a market order, it is filled from the top of the order book. A limit order is filled when an order book entry matches the limit. In both cases the trades are filled at an ask or bid price from the book. In my opinion, ask and bid are sufficient for limit order simulation.

Re: [Test] mode: Simulate both market *and* limit orders [Re: jcl] #486257
07/06/22 14:46
07/06/22 14:46
Joined: Aug 2021
Posts: 101
M
MegaTanker Offline
Member
MegaTanker  Offline
Member
M

Joined: Aug 2021
Posts: 101
Originally Posted by jcl
A limit order is filled when an order book entry matches the limit.


They're also filled when your limit order is on the top of the order book and someone places a market order, thereby taking your order from the book. These market orders never make it to the order book, no?

I think using ask/bid data is close enough for simulation but this data usually doesn't have size attached to it (but from some sources it might) whereas trades data tends to have the trade size attached, therefore you can accurately simulate how much of your order would be filled.

Re: [Test] mode: Simulate both market *and* limit orders [Re: AndrewAMD] #486258
07/06/22 14:47
07/06/22 14:47
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Question: How does Zorro simulate this order? When does it fill, and at what price?

Buy order, one lot, Entry = -1000.0 (i.e., entry limit is 1000.0). (This is to simulate a limit buy order at 1000.0.)

Scenario A) Bid = 999.0, Ask = 1001.0
Scenario B) Bid = 1000.0, Ask = 1002.0
Scenario C) Bid = 1000.1, Ask = 1002.1
Scenario D) Bid = 998.0, Ask = 1000.0
Scenario E) Bid = 997.9, Ask = 999.9

Re: [Test] mode: Simulate both market *and* limit orders [Re: AndrewAMD] #486259
07/06/22 15:09
07/06/22 15:09
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Megatanker: Yes they do. Not the market order, but the other side of the trade was in the order book.

Andrew: D at 1000

Re: [Test] mode: Simulate both market *and* limit orders [Re: AndrewAMD] #486260
07/06/22 15:18
07/06/22 15:18
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
When I think about it, there is a situation where a trade does indeed not appear in the order book: When the book is completely empty and a market buy and sell order appear at the same time. But I think this is a very unlikely scenario.

Page 1 of 2 1 2

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1