problem with code

 
Hi, I have got some problems with introduce my conditions in reality. If any good person coul help me a little bit, I would be very gratefull.  
How to convert these conditions below to code?

For example every candle is 1H candle->

-positions can be opened from e.g. 08:00:00 to 21:59:59
                             And
-body of candle #1 and candle #2 shoul have minimum e.g. 5 pips
                            And
-if at the actual moment there is no opened a position, then it can be opened only one position, becouse if one position is opened, second position can't be opened
                           And
-if position was opened in any candle and if this position will not close with TP or SL, then this position has to be closed at the end of this candle (close price this candle)
                       And
- if the one position was opened and closed in the same candle( 1H candle), then next position can't be opened in the same candle

Thank you  for any information.







Reason: