Problem fixing my lot size and closing position, I'd appreciate the help.

Hi guys, 
So I'm a resident doctor who's gotten hooked on trading, 2years so far and dare I say it's profitable. 
So cus of my schedule I decided to learn how to code my own EA. 

Here goes.. 
My plans quite simple, basically 5 and 10 MA cross-over. 
I've successfully defined all my parameters and how it should go. 
But the problem I keep getting errors in is opening and closing buy and sell orders and lot sizes. 
What I want is simply to buy when 5 crosses above 10,then close when 5 crosses below 10 and open a sell order immediately, just 1 order at a time. 
And for the lot sizes, I want it to automatically calculate my lot size to always take one fifth of my free margin so I wouldn't get stuck on a fixed lot size as my balance grows. 

I'd really appreciate whomever can guide me through this process.. Thanks in anticipation, all ideas are welcome. 

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code.
     How To Ask Questions The Smart Way. 2004
          Be precise and informative about your problem

We can't see your broken code.

Fix your broken code.

With the information you've provided — we can only guess. And you haven't provided any useful information for that.