actual direction (not opening)
actual direction (not opening)
18 Jun 2018, 12:53
i use the following code to count positions and its sizes
it works fine until is reverse a trade. so iassume it uses the opening direction instead of the actual one.
anyone knows how to change that so it counts the actual positions and not the opening direction?
long VolumeBuy = symbolPositions.Where(x => x.TradeType == TradeType.Buy).Sum(x => -x.Volume); long VolumeSell = symbolPositions.Where(x => x.TradeType == TradeType.Sell).Sum(x => x.Volume);
Replies
swingfish
18 Jun 2018, 22:06
thanks alot .. but using just "positions" will count all positions, i need to filter them by Symbol
so i used
var symbolPositions = Positions.Where(t => t.SymbolCode == Symbol.Code);
to populate "symbolPositions"
@swingfish
swingfish
18 Jun 2018, 22:18
never mind, i figured it out ;)
long VolumeBuy = Positions.Where(x => x.TradeType == TradeType.Buy && x.SymbolCode == Symbol.Code).Sum(x => x.Volume); long VolumeSell = Positions.Where(x => x.TradeType == TradeType.Sell && x.SymbolCode == Symbol.Code).Sum(x => -x.Volume); Print("Buy: " + VolumeBuy); Print("Sell: " + VolumeSell);
that works .. thanks for the help
@swingfish
PanagiotisCharalampous
18 Jun 2018, 15:24
Hi swingfish,
I tried it but I did not notice any problem. Positions are considered properly even if direction is reserved. Here is the code I used
Best Regards,
Panagiotis
@PanagiotisCharalampous