Average entry price?

Posted By: Cstyle

Average entry price? - 06/12/16 23:44

Within a zorro script, how do I tell what my entry price was? Likewise, if I've added to the position a couple times, how do I know the average entry price for my total position?

Thanks!
Posted By: jcl

Re: Average entry price? - 06/13/16 07:42

The average entry price is the weighted sum of entry prices divided by number of trades. You can find all trade specific variables in the manual under "trade specific variables".
Posted By: Cstyle

Re: Average entry price? - 06/13/16 22:40

I see it now. Thanks a million!
Posted By: Cstyle

Re: Average entry price? - 06/16/16 21:53

Now that I'm digging into the trade specific variables, what I may need is the average profit of all open trades. Does TradeProfit give that? How does TradeProfit behave when more than one trade is open?

Here is an example:

You go long 1 lot at 100.
You add to your position, an additional lot, at 110.

What would be the value of TradeProfit when the asset is trading at 120?
Would it be 30 (total profit)?
15 (average profit)?
10 (the profit of the most recently opened trade)?
Other?

Thanks!
Posted By: jcl

Re: Average entry price? - 06/17/16 07:49

Neither. Here's how to calculate the average profit per trade:

Code:
var AverageProfit = 0;
int Count = 0;
for(open_trades)
  if(TradeIsOpen) {
    AverageProfit += TradeProfit;
    Count++;
  }
if(Count) 
  AverageProfit /= Count;



Untested, so try it at your own risk..
© 2024 lite-C Forums