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 maybeimnotrader, Yesterday, 05:46 PM
        4 responses
        23 views
        0 likes
        Last Post maybeimnotrader  
        Started by frankthearm, Today, 09:08 AM
        6 responses
        25 views
        0 likes
        Last Post frankthearm  
        Started by adeelshahzad, Today, 03:54 AM
        5 responses
        33 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by stafe, 04-15-2024, 08:34 PM
        7 responses
        32 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by merzo, 06-25-2023, 02:19 AM
        10 responses
        824 views
        1 like
        Last Post NinjaTrader_ChristopherJ  
        Working...
        X