Considering Switching To MetaTrader, Have A Question About MQL - please help!


Hey everyone, 
I've been searching high and low for a broker that will let me execute my strategy with automated trading and I keep running into the same issues. I was hoping to save myself some time by explaining a little of what I'm trying to do and the issue I'm encountering, and hopefully someone can chime in and tell me whether or not I'd run into similar problems here. I would really appreciate it!

First, the strategy:
-It's your basic swing trading strategy, but
-When the price falls below your average price I start 'pyramiding' in
-If the price starts to rise above your average price it starts to sell off the low cost shares one at a time

The problem:
-The 'average price' function never works right. Usually the way it works is by assuming all shares in the position have the same 'average price', or it defaults to fifo or something like that. Once things get complicated because I've bought and sold shares a few times without closing the entire position the 'average price' function becomes almost useless and then my profit targets are off.
-Functions for things like your 'total cost of positions' usually have similar issues. I understand the reason why this is so common (this type of position tracking needs a database and usually brokers handle their lot relief/tax stuff through another company) but I'm still going to check all the popular brokers and see if any of them can give me accurate real time information. 

So, my question:

I'm assuming there is a similar way to retrieve 'average price' with MQL, but I'm wondering does it have the same issue? Once you sell shares using low cost relief method, is the function inaccurate?

Thank you for your time. 

What do you mean by the "average price" that you say is so difficult to calculate? Are you talking about the Net Open price of a basket of orders or open positions, or are you talking about the Median price of a bar? What exactly are you talking about?