Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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:



    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, 05:02 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by andrewtrades, Today, 04:57 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      6 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      7 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X