Average Price for positions
Average Price for positions
07 Sep 2018, 06:44
the Position window in "aggregated view" shows Average pips, price and P/L
is there a way to get this information via the Indicator API ?
Replies
swingfish
07 Sep 2018, 10:20
thanks for the reply, for some reason cTrader 3.0 and 3.01 do not have the Positions.Average call
i use this now to calculate the average price (but as i said before, its not very accurate)
the goal is to plot a average line on the chart based on entries/volume .. like a breakeven-line so to speak
// breakeven line ie = 0; foreach (var position in Positions) { if (position.SymbolCode == Symbol.Code) { ie++; ev = position.Volume; tv += ev; if (position.TradeType == TradeType.Sell) ev = ev * -1; e = e + position.EntryPrice * ev; v = v + ev; if (position.EntryPrice >= epmx) { epmx = position.EntryPrice; } if (position.EntryPrice <= epmn) { epmn = position.EntryPrice; } } } p = e / v; if (ie > 0) { ChartObjects.DrawLine("brline", index - 5, p, index + 10, p, Colors.LimeGreen); } else { ChartObjects.RemoveObject("brline"); }
@swingfish
PanagiotisCharalampous
07 Sep 2018, 10:26
Hi swingfish,
"thanks for the reply, for some reason cTrader 3.0 and 3.01 do not have the Positions.Average call ".
This is not part of cTrader but of .Net. As i said you need to use System.Linq library.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
07 Sep 2018, 09:50
Hi swingfish,
You can easily calculate this information. For example
Note that you need to add a reference to System.Linq to your indicator
Best Regards,
Panagiotis
@PanagiotisCharalampous