Hi,
I am having a bit of a problem for the problem below.
This is a quantitative strategy for trading and i am unable to calculate the profit/loss for it.
The strategy goes something like this:
at the end of day 4 i look at the volume(234,770 ). I check whether it is larger than the average volume of the 3 previous days (1,2,3). that is the average of 275,670 , 464,374 ,362,799 .In this case it turns out to be less. So i give a sell signal at the open price on day 5.
I do same for day 6(where i check volume for day 5 versus the average for day 4,3,2). I assume that in case of consecutive sell or buy calls i HOLD the previous buy/sell call. So in this case i will hold my position from day 4,5,6,7,8 and sell all of them on day 9 when the call CHANGES TO BUY. this is true the other way too ( day 12 , where i sell all positions from day 11,10,9). I want find a formula which can help me calculate my profit/loss everytime there is a change in call (that is from buy to sell or vice versa). So basically i intend to find my total gain/loss from consecutive buy or call signals.

Let me give you an example of what i mean
On day 9 when my signal changes to "buy"
i calculate my profit in the following way:

(day 4 open price - day 9 open price)+( day 5 open price - day 9 open price)+(day 6 open price - day 9 open price)+(day 7 open price - day 9 open price)+ (day 8 open price - day 9 open price)
this in the above case comes to (2915-2802)+(2855-2802)+(2835-2802)+(2840-2802)+(2820-2802) = 254.35
In this case because it changing from a sell to buy , i subtract day 9's open price from the day 4,5,6,7,8.
In case of a change from a buy to sell signal i will subtract day 4,5,6,7,8's open prices FROM day 9's price to calculate my profit/loss

Please let me know if this clear.


Please help and message if there are any doubts.

Thanks in advance

day Open Price Volume Action Profit/loss
15 2,900.0 205,788 sell
14 2935 239,240 buy
13 2940 346,525 sell
12 2937 185,466 sell
11 2925 286,809 buy
10 2821 444,991 buy
9 2802.15 286,311 buy
8 2820.1 347,279 sell
7 2840 194,468 sell
6 2835 158,955 sell
5 2855 242,048 sell
4 2915 234,770 sell
3 2825 275,670 buy
2 2872 464,374 buy
1 2766 362,799 buy