1

I try to test one strategy in R which is to buy at xth number of bars after a bull engulfing signal. As you can see I have number of Bars after Bull Eng which is the last column.

Now I want to calculate a dynamic return based on the xth Bar from column testrange.High, with x 's value indicated by the value of the last column.

For example, I want to anchor the Open price from bar #1 which is 200.000, then compare the High price from 3rd column (200.19 200.17 199.49 199.55 199.73 200.04) which is to run from 1 to 6 bars as indicated in the last column to the anchor ( the 200.000) to get the returns for the 6 bars, then start over again at the next 1 position which is 19:44:00 for the same process (a new anchor of 199.97 and run 7 bars from High for return calculation) and return all the returns as a list or a vector with their number of bars.

Any help is greatly appreciated. Thanks in advance.

                           testrange.Open testrange.High BarAfterBULLEng
2015-01-06 17:59:00        200.000        200.190               1
2015-01-06 18:14:00        200.140        200.170               2
2015-01-06 18:29:00        199.430        199.490               3
2015-01-06 18:44:00        199.280        199.550               4
2015-01-06 18:59:00        199.150        199.730               5
2015-01-06 19:14:00        199.680        200.040               6
2015-01-06 19:44:00        199.970        200.500               1
2015-01-06 19:59:00        200.490        200.985               2
2015-01-06 20:14:00        200.500        200.820               3
2015-01-06 20:29:00        200.710        201.340               4
2015-01-06 20:44:00        201.250        201.300               5
2015-01-06 20:59:00        200.555        201.000               6
2015-01-06 21:01:00        199.960        200.870               7
Rstudent
  • 41
  • 2
  • Thank you Loic TheAztec for formatting my question, it looks a lot better now. – Rstudent May 16 '16 at 20:06
  • Can you please add code for your example and desired output for the sample. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Bulat May 16 '16 at 23:06
  • thanks Bulat, I am out at a conference for the rest of this week and will follow up next week. – Rstudent May 18 '16 at 22:51

0 Answers0