The Problem with all these methods, they need time for preparation, sometimes I get the first ambush during summer year 1. If I focus all my dwarfes on building these sort of fancy traps they starve to death etc. Most the time I start with 2 Axedwarfes and some leather armor but unless I train some of the first imigrants I get killed.
I start with a MECHANIC. He makes mechanisms.
I start with a MASON. He makes me some blocks.
I start with a MINER. He carves the fortress (producing stone for the MECHANIC and MASON), and channels out (1 z) where the drawbridge will go.
I set one of the 7 to architect, and designate a drawbridge over the 1 z channel and pick blocks as the construction material.
After the bridge gets built, I build a lever (in my manager's office inside the fortress), and link it to the drawbridge (ALWAYS a drawbridge--- so you can block out flying attackers).
The miner gets assigned the task of building up ramps 1 z level down from the covered/bridged channel (with the miner access from OUTSIDE the protected area). Then miner cleans up the left over ramps.
This is all done in year 1, unless I have a large aquifier between me and my stone.
You cannot be ambushed in year 1. You can be ambushed on day 1, year 2, but year 1 is always safe, even if you are at war with all other civs.
As long as you have stone, you have mechanisms. As long as you have mechanisms, you have traps and drawbridges. Enjoy.
It might seem boring at first, but pausing every few seconds and checking the combat logs can give you a good picture of what's happening in combat, and may or may not give you an indication of what's going wrong. Goblins in copper and leather beating a larger number of dwarves in iron and steel means something's up... assuming that your first ambush didn't consist of 8 Axe Lords. And even then, maybe!
Lashers. You can get an ambush squad full of lashers, easy. I have it happened to me often enough in 31.x. Against lashers, the only defense is to HIDE behind your drawbridge, since lashers = light sabers.