Treat each indicator buy signal as its own trade

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:
image

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);

I managed to solve this, although I would love some constructive criticism. I ended up reading the user manual h/t Tomasz and I read about setbacktestmode( backtestRegularRaw2Multi). That allowed me to break out each individual trade. Then I was reading other threads and found @fxshrat 's solution to another issue that said just use the applystop function and set the number of bars to however many you need.
So h/t to both of you, and everyone on this forum that is very helpful to those of us that aren't as powerful programmers.
Thanks again,
Tony R

1 Like

The "Multi" mode is exactly for that purpose and yes reading manual helps :slight_smile:

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.