You would need a for each switch
is switch on
pick where oid = switch.oid
Animation speed of the sprites is not 0, so that can lead to further problems.
Your code seems to be not very straight-forward. Why not use something like this?:
This way you dont check the switch every tick, to setup the switchends to the correct frame. If you face the problem that newly created switchends will not have the animation frame according to the switch, you could easily do a "on created"-event and then set it according to the switch boolean or add a function, that does a "for each switch"...