Hi I'm trying to find the 1 and 3-year returns in the 'SPY' following an event--in this case, my custom indicator crossing above a reading of 30. The issue is I'm not sure how to break out individual trades that happen inside the time frame. For example, the trades shown below has a trade on 8/16/2002 and then another one on 10/18/2002. So I'd like to see the 1-year and 3-year returns for both the signal on 8/16/2002 and on 10/18/2002 trade. Here's an example of what I mean:
Ideally, I'd like to get the rate of return over the time frames mentioned. Please help!
This is the code I have so far:
bbi=Foreign("~BBI","C");
Buysignal=Cross(bbi,30);
oneyearlater=Ref(buysignal,-252);
threeyearslater=Ref(Buysignal,-756);
fiveyearslater=Ref(buysignal,-1260);
Filter=buysignal;
AddColumn(buysignal,"Buy");
AddColumn(ValueWhen(BUYSIGNAL,C),"ValueWhen");
AddColumn(ValueWhen(oneyearlater,C),"OneYearLater");
AddColumn(ValueWhen(threeyearslater,C),"ThreeYearsLater");
AddColumn(ValueWhen(fiveyearslater,C),"FiveYearsLater");
//AddColumn( ValueWhen(oneyearlater,DateTime()), "Date / Time", formatDateTime );
Buy=buysignal;
Sell=Ref(buysignal,-252);