I do not understand your difficulties, why do you not simply trade the asset only while it is in the index? This is just 1 line of code.