Close all positions with profitable takeprofit
Close all positions with profitable takeprofit
09 Dec 2013, 15:18
Hi,
How can i close all the positions as soon as their sum is profitable?
Eg: 1k sell = -45
2k sell = -90
4k buy = 180
Thanks for your help!
Replies
hichem
09 Dec 2013, 17:37
RE:
sum += position.NetProfit;
should be
sum += position.NetProfit + position.Commisions + positions.Swap ;
daemon said:
something like this:
double sum; protected override void OnTick() { sum = 0; foreach (var position in Positions) { sum += position.NetProfit; } if (sum > 0) { foreach (var position in Positions) { ClosePosition(position); } } }
@hichem
Spotware
10 Jan 2014, 12:12
RE: RE:
hichem said:
sum += position.NetProfit;should be
sum += position.NetProfit + position.Commisions + positions.Swap ;daemon said:
something like this:
double sum; protected override void OnTick() { sum = 0; foreach (var position in Positions) { sum += position.NetProfit; } if (sum > 0) { foreach (var position in Positions) { ClosePosition(position); } } }
UPDATE:
The NetProfit property of a Position type variable has been updated to include closing commissions.
Until now the NetProfit property of a Position type variable included commissions one way, that is only the commissions charged upon creating an order. Now, they will include the commissions that will be charged when the position is closed as well.
So, if you had any cBots calculating net profit and subtracted the closing commissions you will need to modify the code otherwise commissions will be subtracted twice.
@Spotware
daemon
09 Dec 2013, 17:34
something like this:
@daemon