Make a winding, 3-tile-wide entrance ramp across maybe three or four z-levels. Place at least two drawbridges with two-tile-long channels (no ramps!) and a large-as-possible airlock-like in between them. The Airlock ought to be long, and it's no problem if it goes spiralling across several z-levels. It shouldn't be wider than 3 tiles, though. Place chained war animals at the walls, relatively close to the interior end of the tunnel. Place a number of traps within the airlock, cage traps at the outer end, stonefall or weapon traps at the interior one. For both traps and war animals: the more, the merrier.
For additional safety, place the trade depot right at the interior end of the tunnel, so anything that gets past the war animals (and the traps, if you place any) has to fight through the merchants first. Make sure the whole tunnel is wagon-accessible, and properly smoothed and perhaps engraved to impress the traders.
I'm pretty happy with this design. Traders and their wagons go through, dwarves can go out, goblins and kobolds and wild animals are either catched or killed straight away...
All that's missing (but you're free to include it) is an auto-closing mechanism for the airlock via pressure plates, so anything that survives the traps causes the fortress to seal itself. And a flushing system to clean the airlock once anything is isolated inside.