MacBook Air 2013 bad wifi when internal monitor off while using external monitor
You should try to do a PRAM reset. You do it by holding command + shift + P + R on the MacBook keyboard on start-up, when it does the boot sound the second time, stop holding the keys. This should solve.  Even though I suggest you to use an ethernet cable with your MacBook lid closed. If your setup isn't near your modem try using some powerlines. Here  you have a link for some pretty good ones.

http://www.amazon.com/TP-LINK-TL-PA4010KIT-Powerline-Adapter-Starter/dp/B00AWRUICG/ref=redir_mobile_desktop?ie=UTF8&amp;dpID=31IYBNuPwFL&amp;dpPl=1&amp;keywords=powerline&amp;pi=AC_SY200_QL40&amp;qid=1436666780&amp;ref=plSrch&amp;ref_=mp_s_a_1_1&amp;sr=8-1