Francisco Beltrão PR Brazil
Experience: Intermediate
Platform: NinjaTrader
Trading: forex
Posts: 4 since Oct 2019
Thanks Given: 0
Thanks Received: 1
|
Hello,
In my expert when there is a signal I place an order to market, and it launches some pending stop orders with a certain distance in the direction of the signal.
For closing orders and positions I use financial goal profit or loss.
This is the concept I am developing.
Let's get to the facts:
I created a CloseAllPositions method to close positions when the goal is reached up or down.
To cancel orders that are eventually pending when the goal is reached I use CancelAllOrders.
I run CloseAllPositions on OnMarketData.
However, there is always an error in OnMarketData: "Strategy 'Rsi': Error on calling 'OnMarketData' method on bar 1327: Collection was modified; enumeration operation may not execute.".
Below the CloseAllPositions code.
private void CloseAllPositions() {
foreach (Position position in this.AccountObj.Positions) {
this.PrintLog("tem posicao aqui");
if(position.MarketPosition == MarketPosition.Long) {
ExitLong();
}
if(position.MarketPosition == MarketPosition.Short) {
ExitShort();
}
}
}
Please, any contributions?
|