Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to generate an exit only strategy

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

    How to generate an exit only strategy

    If currently I have a long position in my account (for example buy market on chart trading), how do I create an exit only strategy?

    "ExitLong()" won't work because I didn't enter a long position in this particular strategy, right?

    "EnterShort()" will be ignored too.

    The only way to exit is if I choose "sync account position" as "true" when I apply the strategy. But then the position is SellMarket without applying any of my exit strategy.

    Thanks for your time.

    #2
    Hello skooj,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    Automated NinjaScript Strategies are not designed to handle manually submitted orders.

    With that said, you could use the Unmanaged Order Approach to SubmitOrder() that would close the position but would need unsupported methods to pull the account position. Keep in mind this path would mean the strategy reported position would be incorrect compared to the account position.

    For information on the Unmanaged Order Approach please visit the following link: http://www.ninjatrader.com/support/h...d_approach.htm

    Comment


      #3
      Thank you Patrick! That's exactly what I need. So how can I pull the account position using unsupported methods? Can you share some codes or introduction?

      Originally posted by NinjaTrader_PatrickH View Post
      Hello skooj,

      Thank you for your post and welcome to the NinjaTrader Support Forum!

      Automated NinjaScript Strategies are not designed to handle manually submitted orders.

      With that said, you could use the Unmanaged Order Approach to SubmitOrder() that would close the position but would need unsupported methods to pull the account position. Keep in mind this path would mean the strategy reported position would be incorrect compared to the account position.

      For information on the Unmanaged Order Approach please visit the following link: http://www.ninjatrader.com/support/h...d_approach.htm

      Comment


        #4
        Hello skooj,

        Thank you for your response.

        You can use the following to pull from the accounts and get the positions, keep in mind this is unsupported code:
        Code:
        foreach (Account acct in Cbi.Globals.Accounts)
        {
        if (acct.Positions != null)
        {
        PositionCollection positions = acct.Positions;
        foreach (Position pos in positions)
        {
        Print(pos.Account.Name + " " + pos.Instrument + " " + pos.MarketPosition + " " + pos.Quantity + " " + pos.AvgPrice);
        }
        }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmtjoancolmenero, Yesterday, 03:58 PM
        4 responses
        24 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Brevo, Today, 01:45 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by rjbtrade1, 11-30-2023, 04:38 PM
        2 responses
        74 views
        0 likes
        Last Post DavidHP
        by DavidHP
         
        Started by suroot, 04-10-2017, 02:18 AM
        5 responses
        3,022 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by Stanfillirenfro, Today, 07:23 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X