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

After each strategy restart, I can not track of previous open positions

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

    After each strategy restart, I can not track of previous open positions

    Hi
    Im fairly new to NT coding.
    My broker is Interactive broker and it exits (disconnects form NT) once in a day so my strategy get restarted. and for each day that market opens my strategy can not determine what are the previous positions.
    i added the script here.
    Any advice is appreciated.
    Thanks in advance

    P.S: Also, does any one has any idea how to solve the problem of each day exit from Interactive broker?
    Attached Files

    #2
    Hello godric,

    Thank you for the post.

    In this case, to avoid the disconnect you would need to use the IB Gateway instead of using TWS.

    You can find directions on how to configure the gateway in the connection guide here: https://ninjatrader.com/ConnectionGu...nnection-Guide

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      Thanks for your quick reply.
      I tried the Gateway also and the same problem.
      Lets just simplify the problem to this case that, there are some positions open in Ninja trader and you run new strategy,
      1-How one can determine if previous positions are short or long?
      2-How to count the size(number of shares ) that are already bought or sold in those positions.

      Thanks in advance

      Comment


        #4
        Hello godric,

        Thank you for the reply.

        This is going to depend on the start behavior that you select and also how your strategy is programmed. If your strategy is created to adopt the account position after it calculates you could refer to the Position object to find out the direction and quantity of the position it is in. If your strategy is not aware of the prior position meaning that when it enabled it did not re evalueate the same position or adopt it, you would need to use alternative means such as PositionsAccount or the addon account methods. I do see that you are using the addon account method already so that is one way to access the Positions collection. A position object has a MarketPosition enum which defines the direction and a Quantity property.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        3 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        1 view
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        6 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Working...
        X