How the trades are calculated in backtesting results

I am having confusion on how the backtesting profit and loss are calculated

I have a strategy where buy sell and exit long and exit short conditions are there

thus say first is

1)long at rs100

  1. exit long at 200(profit 100)

  2. short at 300

  3. long at 200 then (profit 100, but here should new position tobe taken or just cover the short position?)

5)exit long at 100(if new position is taken at (4) long here i have loss of 100/-OR I remain out of trade from 4 to 5 if just short position is covered)

6)short at 400

In short what rule is followed for backtesting 1. taking new position at every buy and sell and just covering positions at exit long and short

  1. At each buy sell and exit long short, only old positions are covered.

As per rule one I have to take 2 trades at every buy and sell signal
I hope I made my question clear

the above conditions based on prices is not possible to code automated with tradescript you can use price alert indicator

I have not given the strategy above
Its the result of say of my strategy giving buy and sell signals at above prices
My question is regarding execution of buy and sell signals
say first buy then sell now at this sell shoud i just sq off or create new sell position also.
How the backtesting profit and loss calculated ?