How to code delay/avoid entry of IPO stock?

I try to code a stock trading system that delays entry signal 1-year at least after IPO using “BarIndex() >= 250” filter included in the buy signal as following code.

Buy = Cross(C, Ref(HHV(H, 200), -1)) AND BarIndex() >= 250;
Sell = Cross(Ref(LLV(L, 20), -1));

There is no buy signal appear within 1-year after IPO when I plot this into chart but it still does not work in backtesting.

Can anyone suggest me how to apply or code this to work in backtesting? Thank you.

@madonion Check to see if you have turned on "Pad and Align". I think that will change your "BarIndex" number from the symbol you are testing upon to your reference symbol's barindex.


Secondly your Sell line is improperly coded. Didn't you get a syntax error, as you have nothing to "cross", you need another argument in the formula.

So here for example is an Explore result with Pad and Align OFF, and you see Googl began trading in August 2004 and has the BarIndex to match.

Now with Pad and Align turned ON and my reference symbol being the $SPX with many more years of data than GOOGL (and with a setting of 10,000 bars)


You see a Buy signal after only a few bars because your filter of 250 on the Bar Index has been surpassed.


Problem solved!. Thank you very much for the answer and your kindness. :blush: