Filter the net profit / loss of some positions
Filter the net profit / loss of some positions
29 Sep 2014, 14:03
Hi,
if I'm running more cBot, Is there a way to get a variable that calculates the net profit / loss of the open positions by only one of the cBot?
This variable, then I would like to use as a parameter to close all positions managed by the cBot.
Thanks.
Replies
Forex19
29 Sep 2014, 16:01
RE:
Since I have already adapted the label to other needs of the code.
is possible to obtain the same result in another way? I think for example to use a list where converge all positions of a cBot.
Spotware said:
You can use Label for such purpose.
[Parameter(DefaultValue = "cBot unique identifier")] public string Label { get; set; }When you open position, you need to use Label:
ExecuteMarketOrder(TradeType.Buy, Symbol, someVolume, Label);Then you will be able to calculate profit/loss for positions with that specific label:
var pnl = Positions.FindAll(Label).Sum(position => position.NetProfit);You can also close all positions with specific label:
foreach (var position in Positions.FindAll(Label)) { ClosePosition(position); }
@Forex19
Forex19
29 Sep 2014, 18:31
RE:
I would like to close all position with a specific label, which generate a P&L less than -10, for example.
In OnTick, is correct put:
var pnl = Positions.FindAll(Label).Sum(position => position.NetProfit);
foreach (var position in Positions.FindAll(Label))
{
if (pnl <= -10)
ClosePosition(position);
}
???
Spotware said:
Then you will be able to calculate profit/loss for positions with that specific label:
var pnl = Positions.FindAll(Label).Sum(position => position.NetProfit);You can also close all positions with specific label:
foreach (var position in Positions.FindAll(Label)) { ClosePosition(position); }
@Forex19
Spotware
29 Sep 2014, 14:46
You can use Label for such purpose.
When you open position, you need to use Label:
Then you will be able to calculate profit/loss for positions with that specific label:
You can also close all positions with specific label:
@Spotware