Look at this thread
How to start with MetaTrader and forex
To say shortly, the coders are coding the systems on close bar. Almost always. There are some few exceptions related to open bar scalpers and so on.
What is coding on close bar?
It is the same with real manual trading: the signal is valid if you see it on previous(or close) bar.
Numeration is started with bar number 0 (current open bar). In this case previous bar is bar #1 and so on.
It is no any programming problem to check the condition of previous 5 bars's close.
Check this thread (first post) for more information
How to start with MetaTrader and forex