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

closing positions for other strategies

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

    closing positions for other strategies

    Dear friends.
    I try to create strategy which can monitor positions from other instruments or opened manually. But I have a trouble with closing position. As I understand I can influence only at my strategy. If manually opened positions is Short with 5 lots, and my strategy opens Long position with 5 lots, I will not close first position.
    I have attached my strategy.
    Attached Files

    #2
    I have attached screens from my terminal.
    Attached Files

    Comment


      #3
      Hello daglas,
      If you open a position for 5 short manually and your strategy opens a position for 5 long, then overall your account position will be flat however your strategy position will be 5 long.

      You can use the below unsupported code to check on the overall account position.
      Code:
      foreach (Position p in Account.Positions)
      {
      	if (p.Instrument.FullName == Instrument.FullName)
              {
      		//do stuff
              }
      }
      I will leave the thread open for any forum member who can further assist you in this regard.
      JoydeepNinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Joydeep View Post
        Hello daglas,
        If you open a position for 5 short manually and your strategy opens a position for 5 long, then overall your account position will be flat however your strategy position will be 5 long.

        You can use the below unsupported code to check on the overall account position.
        Code:
        foreach (Position p in Account.Positions)
        {
            if (p.Instrument.FullName == Instrument.FullName)
                {
                //do stuff
                }
        }
        I will leave the thread open for any forum member who can further assist you in this regard.
        Many thanks for your help.
        I have check this code, it has access only for position which are visible on Positions Tab. I can't get data about from my strategy with this code. I think I should you getpnl method in code of my strategy and compare it with positions available on Position tab.
        Also I have get some strange message about overfill orders.
        Attached Files

        Comment


          #5
          Hello daglas,
          Position.Quantity should give you the current position held by your strategy.



          An overfill is categorized as when an order returns a "Filled" or "PartFilled" state after the order was already marked for cancellation. The cancel request could have been induced by an explicit CancelOrder() call, from more implicit cancellations like those that occur when another order sharing the same OCO ID is filled, or from things like order expirations.
          JoydeepNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by GLFX005, Today, 03:23 AM
          0 responses
          1 view
          0 likes
          Last Post GLFX005
          by GLFX005
           
          Started by XXtrader, Yesterday, 11:30 PM
          2 responses
          11 views
          0 likes
          Last Post XXtrader  
          Started by Waxavi, Today, 02:10 AM
          0 responses
          6 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by TradeForge, Today, 02:09 AM
          0 responses
          12 views
          0 likes
          Last Post TradeForge  
          Started by Waxavi, Today, 02:00 AM
          0 responses
          2 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Working...
          X