It has a lot to do with build order also. Some quick gameplay recommendations:
1) Don't build nano turrets (caretakers) so early. It's better to get mobile constructors instead because firstly, they are faster to build because you have buildpower from both com and factory (factory cant help build nano turret), and secondly, because you can expand to take more mexes once you start stalling.
2) LLT (Light Laser Tower or Lotus) is 90 metal, and probably the best unit in the game for its cost. One or two can cover your base, and that is really the most defense you need for a while. Again, it's better to invest in mobile units that can help you take territory.
3) Be sure to keep a couple raiders always roaming about looking for cracks in the defense, and mexes and contructors to kill. They are really cheap, and almost always worth the scouting knowledge and psychological pressure they put on your opponent, even if they don't kill anything.
Don't forget, a lot of the game comes down to numbers. The one who has more resources and spends more resources will have the advantage, and resources come from territory!