mkserge
mkserge

Reputation: 103

Understanding order fills in Broker Emulator

I am trying to understand how does TradingView's PineScript place order fills during backtesting. I understand that the computation is done after the bar closes, so obviously we have to "fake" it somewhere.

Now, from the documentation:

The following logic is used to emulate order fills:

  • If the bar’s high is closer to bar’s open than the bar’s low, the broker emulator assumes that intrabar price was moving this way: open → high → low → close.
  • If the bar’s low is closer to bar’s open than the bar’s high, the broker emulator assumes that intrabar price was moving this way: open → low → high → close.
  • The broker emulator assumes that there are no gaps inside bars, meaning the full range of intrabar prices is available for order execution.

For the heck of it, I cannot wrap my head around the phrase, "if the bar’s high is closer to bar’s open than the bar’s low". Isn't that by definition always true? How can the bar's high NOT be closer to bar's open than the bar's low? The bar's low, by definition, is below (or at) the open.

Even with that the documentation does not explicitly state what is the fill price. It mentions the assumed direction of the price movement (open -> high -> low -> close), but does that mean that we take the price at close? high? What does the direction tell us about the chosen fill price?

Thank you.

S

Upvotes: 0

Views: 386

Answers (1)

Andrey D
Andrey D

Reputation: 1714

In simple words this is: if open - high < open - low then open → high → low → close

For example: the broker emulator takes price range open → high. It is walking on this price range (for p = open; p <= high; p += price_min_tick) and check if some order can be filled with p price. And so on.

Upvotes: 1

Related Questions