EA Template Explaned?!

 
I don't understand how this template example(Osc_test) controls how many orders to opens and where close order functions( formula) should be placed ?!

https://www.mql5.com/en/articles/1514



Can you explain please?!
1. I want to open one market order at beginning of a bar, if there is a signal( BUY or SELL) for opening, no matter is there any other opened orders(BUY or SELL) in terminal. So no limitation for opening new( only market) orders.
2. If there is a signal for closing orders and few or all of orders fulfil all conditions then close all orders at same bar that satisfy closing conditions, no matter how may orders should be closed.
Very simple Example: 15 Minute Chart

0:00 Signal for Buy Order( Open one market order at Bar Open) #1
0:15 Signal for Buy Order( Open one market order at Bar Open) #2

0:30 Signal for Buy Order( Open one market order at Bar Open) #3
0:30 Signal for Closing Buy Order #1( Close only Buy Order that satisfy condition in same bar, no matter that EA opened new order at same time).
0:45 Signal for Buy Order( Open one market order at Bar Open) #4
1:00 Signal for Sell Order( Open one market order at Bar Open) #5
1:15 Signal for Sell Order( Open one market order at Bar Open) #6
1:15 Signal for Closing Buy Orders # 2 and 3( Close only Buy Orders that satisfy condition in same bar, no matter that EA opened new order at same time).
....
and so on

I don't see how to program this into EA Template, so can you explain in detail how to control new orders and closing orders in EA Template?

Also is this template will produce true results in strategy tester with no limitation for number of opening trades(well no more then 100) with above characteristics- Open and Close at beginning of a bar?
Reason: