Once the bar is closed, an algorithm handles it immediately.
if you will have bars in 1min or 30s? it will not be as immediate as it is now.
you cannot buy for average price of current bar because that period is just closed, you buy on the next bar avg price, your trade is being aggregated to this next bar.
That's why you are counting the price as next bar. You can perform simulation based on real executed price of orders ~ estimated by both methods with lag/with no lag.
When you have 30 minutes bar the engine will trigger when a bar closes, within a very short amount the engine will determine whether it needs to change the portfolio (and if to buy or sell to reflect this). This will all probably happen within 1 second after the bar closed, with the low liquidity in the BTC market I really don't think the effects are big. And if they are I don't see how the average price of the next bar is any better price indicator as a lot can happen after in the 29 minutes and 59 seconds after the decision (maybe the open of the next candle would be a little better but I really don't see it right now).
About the lag: I don't know if this data is available at all, but it is not going to help you much: when there is a 10 second lag it means the trading engine is lagging 10 seconds behind. All orders from between 10 seconds ago and now are queued and they are probably not available, so they are unknown at the time you make your decision (not 100% sure, maybe there are in the order book already).
If I got your question correctly:
Trade price = Close price for the current bar + Trading fee
Remember, this is only a simulation so the formula does not consider slippage and other real trading costs.
I don't agree on your price calculation: While the trading fee obviously needs to be payed while ordering, the alpha (EMA/MACD indicator) is only responsible for detecting the trend, you are now manipulating the data so that trends happening do not get properly detected IMO (difference is pretty small, but it's there).
This is a hard problem because the current alpha (a simple trend indicator) can't tell you anything about how long a trend will probably last (statistically) or how much the price will change. If you would have a model predicting this you can better determine if you should reposition your portfolio while taking fees into account. My bot only uses the fees to simulate the profit, it does not use them to determine what position to take.EDIT: It appears I failed to read properly.