Sorry, but I had never heard of the Sound Bar turning on and off with an Optical Connection, but it's possible with an HDMI Connection with TV ARC Enabled.
HDMI ARC is only a feature which allows Sound to be transferred to the Sound Bar, instead of going into the TV. However, HDMI-CEC allows you to control the volume of the Sound Bar and enable the Sound Bar to turn on and off with the TV. Mostly, if HDMI-ARC is enabled, HDMI-CEC will be enabled as well. Please check that your TV supports HDMI-ARC and HDMI-CEC. If your TV supports HDMI-CEC and HDMI-ARC, follow the steps below. If not, please provide us with more information on your current situation above. I'd recommend you provide your TV model as well for other members to help out easier.
1) Make sure that your TV supports HDMI-ARC and HDMI-CEC
2) Search the manual of your TV to find the HDMI port which supports HDMI-ARC
3) Connect one end of the HDMI cable to the specific port on the TV
4) Connect the other end into your Sound Bar HDMI Out
5) Enable HDMI-ARC and HDMI-CEC on your TV
7) Disable TV Speakers (if possible)
8) Turn on all your existing devices, and change your Sound Bar's input to "TV ARC"
9) Try turning on and off your TV to see if it works.
If you TV has only the option to enable HDMI-ARC, the feature HDMI-CEC should also be enabled after enabling HDMI-ARC. This settings could normally be found on your TV sound settings.