ALL strategies are executed when a candle closes, just while the new one is about to open. Real time does not exist.
You are allowed to use multiple time frames so that you can use a lower TF to “simulate” as much as possible real time. Strategies will still be executed when a candle closes, but, as they are on a lower TF it’s a bit closer to real time.
You can code your strategy using MTF, with a 4h TF to evaluate conditions, then entering on the lower TF (say 1 minute):
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
TIMEFRAME(4 hour,default)
// Conditions to enter long positions
indicator1 = MACD[12,26,9](close)
c1 = (indicator1 >= 5)
IF c1 THEN
BUY 10 CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
indicator2 = MACD[12,26,9](close)
c2 = (indicator2 <= -1)
IF c2 THEN
SELL AT MARKET
ENDIF
TIMEFRAME(default)
if you launch it from a 1-minute chart, you’ll be able to evaluate your conditions every single minute on your 4-hour TF and enter/exit accordingly.
But your conditions will NOT be confirmed by the closure of a 4-hour candle, since you requested real time.
If you want your conditions to be confirmed at closing time, then you need to replace line 3 with:
TIMEFRAME(4 hour,updateonclose)
but, in this case, using the MTF support is useless, unless you use the lowest TF to trail your SL or do something else.
There are different consequences involved in using or NOT using the keyword UPDATEONCLOSE, mainly the fact that you can enter multiple times on the same conditions if your trade exits within a few candles thus entering when your conditions are no longer valid. You’d better study the available videos an the many code snippets on the forum, to go deeper into MTF.