Hello Prorealtimers!
When exactly does a buy occur after a buy condition is satisfied in a code? Say for example, in a 1 minute timeframe, at candle n buying condition is satisfied, does the buy order go to market as soon as the condition is satisfied, i.e. in the middle of bar n? or does it occur at the open of bar n+1?
does the buy order go to market as soon as the condition is satisfied? … yes if it is a Buy Limit or Buy Stop Order (and therefore at a predefined price level set at the end of the previous bar).
In the middle of bar? … intrabar only as above.
Buy orders get filled at the open of the next bar after the bar where ‘condition are met’.
Code is read at the end of each bar.
GraHal
All decisions are made at the candle close and orders placed at the next candle open. If that includes setting a buy/sell limit/stop order then that is when it is sent to the market. They last one candle only and so will need to be sent again at the close of that candle if you want the order to stay on the market for longer than one candle.
Ok imagine these 2 scenarios:
Assume: x < y < z and u which could be higher or lower than z.
Now let’s assume I have this in my code:
Buy when close crosses over y
Scenario1: Bar n opens at x and closes at z
Scenario2: Bar n opens at x, goes up to z and then comes down and closes at x
Now let’s assume bar n+1 opens at price u.
Would the buy order be triggered and at what price?
Scenario 1 is the sole where close has crossed over x, so the buy order at market will be executed immediately when bar n closes, just before bar n+1 opens (once called NEXTBAROPEN).
Scenario 2 has no condition true, since the crossing is evaluated at the closure and it did not happen at that very time. You could trigger it just changing the condition to high crosses over x, instead of close crosses over x, but still it would be triggered at the same time, not while the crossing occurs.