Closing a position
Closing a position
06 Nov 2017, 08:50
HI
I have a algo where i open a long position when x conditions are met, and
short when y conditions are met but i cant close any positions, it just keeps opening new ones on top of existing positions
what i would like is to close all long positions when i short a position on that symbol
so if i short EURUSD, it should close all long positions before i do so
and if i long EURUSD it should close all short postions but currently it only adds new positions to old ones and never closes the positions
My goal is to have this running on many symbols so i cant use for position in positions, and since profit pips is variable, i cant use take profit pips either
Replies
khan_tu
06 Nov 2017, 09:28
if (rsi.Result.LastValue <= 30) { if (direction != 0) { foreach (var pos in Positions) { ClosePosition(pos); } PlaceLimitOrder(TradeType.Buy, Symbol, 10000, Symbol.Bid); // ExecuteMarketOrder(TradeType.Buy, Symbol, Quantity); // Close(TradeType.Sell); direction = 0; } } if (rsi.Result.LastValue >= 70) { if (direction != 1) { foreach (var Position in Positions) { ClosePosition(Position); } //Open(TradeType.Sell); //Close(TradeType.Buy); ExecuteMarketOrder(TradeType.Sell, Symbol, 10000); //ClosePosition(Position); direction = 1; } }
@khan_tu
PanagiotisCharalampous
06 Nov 2017, 09:12
Hi khan_tu,
Is it possible to share your cBot code with us so that we can tell you where the problem is? Do you use ClosePosition method to close your positions?
Best Regards,
Panagiotis
@PanagiotisCharalampous