NexusFi: Find Your Edge


Home Menu

 





Close positions and cancel all orders pending


Discussion in Traders Hideout

Updated
    1. trending_up 2,273 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?
May 26 Deadline Dies at 7.5% as US Strikes Iran During C …
Prediction Markets & Event Contracts
Iran Airspace Contract Surges to 33.5% as Project Freedo …
Prediction Markets & Event Contracts
Warsh Rate Hike at 40%, Iran June 15 Expires Tonight at …
Prediction Markets & Event Contracts
US Prop Firms Race Inside the CFTC Perimeter -- Tradeify …
Funded Trading Evaluation Firms
$12M Ceasefire Contract Goes Disputed as Bandar Abbas St …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
8 thanks
Darmok and Jalad at Tanagra
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