Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Flatten everything from my strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Flatten everything from my strategy

    Hello,

    How can I make a "flatten everything" with a strategy? For example, I have severals opened positions with another strategies and I need to close all the positions from a different stratety.

    Thanks in advance.

    #2
    Hello,

    Thank you for the post.

    You can use the addon framework commands to flatten instruments using the Account object. Please see the following page:

    https://ninjatrader.com/support/help...us/flatten.htm

    The flatten command takes a collection of instruments to flatten.

    You can also use more advanced techniques to monitor or do other actions with the account using the addon commands: https://ninjatrader.com/support/help...ount_class.htm

    Please also see the PositionAccount object if you are working with multiple strategies at one time: https://ninjatrader.com/support/help...ionaccount.htm

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by soyjesus View Post
      Hello,

      How can I make a "flatten everything" with a strategy? For example, I have severals opened positions with another strategies and I need to close all the positions from a different stratety.

      Thanks in advance.
      Perhaps this code extract, Flatten position if a "daily goal has been reached", might give you some ideas. In regards to Flatten according to Time, it seems better to use the built-in NT feature.

      This code extract works under unmanaged approach. It's pretty basic, one account and one instrument.

      Code:
      protected override void OnAccountItemUpdate(Account account, AccountItem accountItem, double value)
      		{ 
      			daypnl=Account.Get(AccountItem.RealizedProfitLoss, Currency.UsDollar)+Account.Get(AccountItem.UnrealizedProfitLoss, Currency.UsDollar);
      			
      			if ( daypnl >= Maxpro || daypnl <= -Maxlos ) 
      			{				
      				if (Position.MarketPosition == MarketPosition.Short)					
      				{	
      					if ( stoptrading==0 )
      					{
      						if ( setshort != null )					
      						{	
      							CancelOrder(setshort);				
      						}	
      						if ( setshort == null )					
      						{	
      							if ( setlong == null )				
      							{	
      								setlong = SubmitOrderUnmanaged(0, OrderAction.BuyToCover, OrderType.Limit, Position.Quantity, (Close[0]+stop*TickSize), 0, "", "EXITSHORT");
      							}
      							else 
      							{
      								ChangeOrder( setlong, Position.Quantity, (Close[0]+stop*TickSize), 0);
      							}
      							stoptrading=1;
      							SendMail (********);			
      						}		
      					}	
      				}	
      				else if (Position.MarketPosition == MarketPosition.Long )
      				{	
      					if ( stoptrading==0 )
      					{
      						if (setlong != null )					
      						{	
      							CancelOrder(setlong);				
      						}
      						if (setlong == null )					
      						{	
      							if (setshort == null )					
      							{	
      								setshort = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, Position.Quantity, (Close[0]-stop*TickSize), 0, "", "EXITLONG");
      							}
      							else
      							{
      								ChangeOrder( setshort, Position.Quantity, (Close[0]-stop*TickSize), 0);
      							}
      							stoptrading=1;
      							SendMail (*****);				
      						}	
      					}
      				}
      				else
      				{
      					stoptrading=1;
      				}
      			}
      		}
      If you find some other ways to Flatten all, this forum would appreciate highly.
      Last edited by pstrusi; 09-29-2017, 04:02 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Franck Z, Today, 09:49 AM
      0 responses
      4 views
      0 likes
      Last Post Franck Z  
      Started by pvtrader, Today, 08:02 AM
      2 responses
      7 views
      0 likes
      Last Post pvtrader  
      Started by Natoc, Today, 03:04 AM
      1 response
      17 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by Rudy2323, Today, 02:56 AM
      2 responses
      26 views
      0 likes
      Last Post Rudy2323  
      Started by tonynt, Yesterday, 02:07 PM
      1 response
      34 views
      0 likes
      Last Post NinjaTrader_Jason  
      Working...
      X