Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Flatten everything from my strategy

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

  • pstrusi
    replied
    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.

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    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.

    Leave a comment:


  • soyjesus
    started a topic Flatten everything from my strategy

    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.

Latest Posts

Collapse

Topics Statistics Last Post
Started by AaronKoRn, Today, 03:05 PM
1 response
9 views
0 likes
Last Post NinjaTrader_Emily  
Started by zacharydw00, Today, 02:21 PM
2 responses
15 views
0 likes
Last Post zacharydw00  
Started by Harvard, Today, 12:01 PM
2 responses
14 views
0 likes
Last Post Harvard
by Harvard
 
Started by DanDaMan, Today, 12:40 PM
5 responses
15 views
0 likes
Last Post NinjaTrader_Zachary  
Started by bob999, 02-16-2021, 10:00 AM
3 responses
29 views
0 likes
Last Post NinjaTrader_Kate  
Working...
X