Getting started on backtesting some trading data, in particular a very basic mean reversion idea and can't get my head around how to approach this concept.
How would I go about having a running 'posy' increase by 1 once DifFromFv (the deviation from fair value) reaches -10 and subsequently 'posy' increases by 1 as DifFromFv extends by multiples of -3 (-13,-16,-19, etc.) whilst having 'posy' decrease by 1 every time DifFromFv reverts back +5 from last changed 'posy'? Simply put, I am buying once the DifFromFv reaches 10 points and averaging every 3 points, whilst taking each individual average out for 5 points profit.
E.g:
DifFromFv posy
0.00 0
-10.00 1 #initial clip (target profit -5.00)
-11.50 1
-13.00 2 #avg #1 (target profit -8.00)
-16.60 3 #avg #2 (target profit -11.00)
-12.30 3
-11.00 2 #taking profit on avg #2
-14.10 2
-8.00 1 #taking profit on avg #1
-7.00 1
-5.00 0 #taking profit on initial clip
It should be noted that the take profit for every clip is consistently set at -5,-8,-11,etc. increments regardless of where the averages are filled as seen by the target profit for avg #2 being at -11.00 rather than -11.60. This is both to reduce margin of error in real-life fills vs data fills and also I'm pretty sure should make the approach to this concept a lot easier to think about.
Thanks in advance!