NexusFi: Find Your Edge


Home Menu

 





Close positions and cancel all orders pending


Discussion in Traders Hideout

Updated
    1. trending_up 2,224 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 janiodesouza 
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?


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
SEC and CFTC Unlock Customer Cross-Margining for Treasur …
Treasury Notes and Bonds
Probability Collapse: Bitcoin $150k Craters from 15% to …
Prediction Markets & Event Contracts
More Than Capable: Hegseths War Warning Validates $114M …
Prediction Markets & Event Contracts
CFTC Opens First COT Report Review in 20 Years -- Asks W …
Traders Hideout
Warsh Confirmed 54-45 on PPI Day -- 97% Say He Holds in …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
21 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
Algo automated / semi-automated trading anyone?
6 thanks
2026 Fire Horse
5 thanks
  #3 (permalink)
 janiodesouza 
Francisco Beltrão PR Brazil
 
Experience: Intermediate
Platform: NinjaTrader
Trading: forex
Posts: 4 since Oct 2019
Thanks Given: 0
Thanks Received: 1


I did it using AtmStrategyClose (). Thank you!


Started this thread Reply With Quote




Last Updated on January 8, 2020


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts