what do you mean bid and ask tick to fill them? do you mean you buy on the bid and sell on the ask?
Yes, just the other way around.
is there any relationship between Last and bid/ask?
I would not say relationship, but it can help considering both when backtesting your algo.
Algos are often based on the last tick, which might give you nice results in backtesting.
Especially when you run the tape "tick by tick" and your orders and stops are only or two ticks small, like the one's from the op.
But the results in live testing might be much worse.
The reason is, that your algo was triggered by the "Last" order, which is already gone at the time.
And only the next bid's or ask' will tell you, when "Your" order might get executed.
So what I do in backtesting to get IMHO more realistic results:
- Use the "Last" tick (based on my algo) only to create an order in "Placed" state
- And wait for the next "Ask" or "Bid" tick (having the same or a better price) to change the order to "Filled"
- Or change the order to "Cancelled" if my order times out.
Thats also how IB paper accounts are doing it, based on my experience.
For Example
My algo tells me to BUY at 15:30 during my backtesting.
So I've add an (simulated) order which looks like:
- Symbol: ES
- Price: 3100
- Action: Buy
- Created: 15:30:00
- Expires: 15:31:00
- State: Placed
Then i search at the tape for a tick which
- was an Ask order (because somebody needs to buy from me)
- has a price of 3100 or less (because I want to buy)
- and was after the last tick (at 15:30:00) as well as before 15:31:00
If that exists, i change my (simulated) order to "Filled" otherwise to "Cancelled"
In that way, my simulated results are hopefully more realistic (at least they are much worse

)
Hope that makes it more clear.