When planes are flying in formation, TCAS will undoubtedly alert the crew. As a result, in this instance, the transponder must be turned off. The pilot must, however, rely on eyesight rather than displays and sensors which can be difficult for them to fly closely. Please correct me if I am wrong until this point? Is it therefore necessary to turn off the transponder when flying in formation? Or pilots are instructed to fly their plane by a certain speed and attitude at a particular location beforehand?
Yes, the transponder should be off/standby. From AIM 4-1-20-a-4-c
(c) When participating in a VFR formation flight that is not receiving ATC services, only the lead aircraft should operate their transponder and ADS-B Out. All other aircraft should disable transponder and ADS-B transmissions once established within the formation.
If the formation flight is receiving ATC services, pilots can expect ATC to direct all non-lead aircraft to STOP SQUAWK, and should not do so until instructed.