Backtest about when index A rise 100 pts and sell stock B

Hi friends,

I am a new user of AMIBroker. I wanna to do backtest about as below:

1.) if index A rise 100pts, then we short other stock in next bar

I am no idea. How can i do in backtest. I appreicate someone to know how to do. thanks

Best Regards,

Alex

You didn't define "rise" so for simplicity I just used index close price and some bar range within which that rise should take happen.

index = Foreign( "^GSPC", "C"  );

bars = 250;
index_rise = index - Ref(index, -bars) >= 100;

ShortPrice = Open;
Short = Ref(index_rise, -1);

Or

index = Foreign( "^GSPC", "C" );

bars = 250;
index_rise = index - LLV(index, bars) >= 100;

ShortPrice = Open;
Short = Ref(index_rise, -1);

Or ....

2 Likes

Thank you and I would like to know why bars=250?

@gmouse138 that is the approximate number of daily bars in a trading year. You may of course change that number to whatever look back period you are interested in.

1 Like

No, it is not number of daily bars but number of set interval bars. Can also be in between years. The OP did not say anything about range to be observed and interval.

@gmouse138, it is just some sample number of lookback bars. It is up to you what bar range you want to observe.