NexusFi: Find Your Edge


Home Menu

 





Close positions and cancel all orders pending


Discussion in Traders Hideout

Updated
    1. trending_up 2,336 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?
Trump Media to sell instant access to market-moving soci …
Traders Hideout
Netherlands & Germany Surge as World Cup Field Narro …
Prediction Markets & Event Contracts
Would a node-based workflow for automated trading be useful?
Traders Hideout
No book, only a stair: journaling fills where price move …
Cryptocurrency
Fed Hike Odds at 57% After Warsh: England Surges 12.9%, …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Want your NinjaTrader indicator created, free?
5 thanks
Afternoon-close session
1 thanks
Franks Trading Journey
1 thanks
Denied 20K payouts: Alpha Futures
1 thanks
FootPrintV2 Chart for NT8
1 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