Can I connect 24V direct to optocoupler?
No. As indicated by the symbol, the opto-transmitter is an infrared LED with a typical forward voltage, Vf, of 1.4 V. Like any LED in a similar situation a series resistor is required to limit the current. In your case you probably want 10 mA through the LED so \$ R = \frac V I = \frac {22.6} {10m} = 2k2 \$.
A few tips:

Draw your schematics so that higher voltages are at the top of the page and current flows from top to bottom. i.e. Invert your opto-isolator.
Generally signal flow should be from left to right. i.e. LED (the input) on the left, output transistor on the right.
GND symbols should point down to ground.

If you are interested, Rules and guidelines for drawing good schematics is well worth a read.