NexusFi: Find Your Edge


Home Menu

 





Close positions and cancel all orders pending


Discussion in Traders Hideout

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




 
Search this Thread

Close positions and cancel all orders pending

  #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?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
What broker to use for trading palladium futures
Commodities
Better Renko Gaps
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
How to apply profiles
Traders Hideout
 
  #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


© 2024 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 - Privacy Policy - Downloads - Top
no new posts