Code is read at the end of each candle on whatever timeframe you are running the code at. So 5 min TF, the code is read every 5 mins at the end of the candle / bar.
The Open or Close trade is then executed at the open of the next candle / bar (a few milliseconds after the close of the previous candle / bar).
Only way you can execute a trade (open or close) during a bar, is to set a Pending Order to execute when, for example, a price level is met that satisfies the Pending Order.
https://www.prorealcode.com/documentation/stop-pending/
The nearest you can get to what you want – without using Pending Orders – is to run your code on multi-timeframe.
Multi-TF means, for example, using a 5 min TF and when conditions are met within a 5 min bar then the trade could be executed on, for example, a 1 second or 5 second candle / bar.
https://www.prorealcode.com/topic/multi-timeframe-mtf-indicators-for-prorealtime/
3 users thanked author for this post.