Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position.MarketPosition for account

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

    Position.MarketPosition for account

    Hi,

    I'm running a simple automated strategy (currently with the sim account), and I want to be able to close down Ninjatrader after market close each day, then restart it and the strategy the next morning before the open. Also, it does not sell on the close, so positions may be open overnight. The problem is, although the session remembers that a position was open when Ninja is restarted, my strategy uses Position.MarketPosition in its decisionmaking, and it does not have the correct state after restart. For example, if the strategy was long 100 shares yesterday at the close, the next morning the position will still list 100 shares, but MarketPosition is equal to MarketPosition.Flat, leading to incorrect trade logic, typically buying an additional 100 shares. Is there a good way around this?

    #2
    Hello,

    Thank you for the question.

    This could potentially be that the strategy is not calculating a historical trade that exactly matches the the trade which opened position. If the strategy does not allow for historical trades it would not generate the exact same trades historically meaning that it would start flat because the prior position was not matched.

    Can you provide more details on the strategy, mainly if the strategy is calculating historically and placing the exact same trade as the live trade that produced the open position?

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

    Comment


      #3
      No, it doesn't do any historical trade calculations. Isn't that risky, since the historical bars may look slightly different than the way they looked live?

      Comment


        #4
        Hello,

        Yes there is a possibility that the strategy could calculate different if there is different historical data but this would also be the only way for the strategy to resume a position. If the strategy is only working in realtime, it can not calculate historically to see that it had actually generated that position. Without that, it would be unable to associate with the order correctly.

        You can add intrabar granularity to the script to minimize differences but still could calculate differently if the difference in data is too much and creates a change in the pattern in which it had placed orders.

        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Is there any way I can get the account position rather than the strategy position? It would assume I'm only running a single strategy, but that's OK for now.

          Comment


            #6
            Hello,

            There are not any supported methods for getting the account position, the strategy will only be aware of it's own position.

            With that said there are some undocumented/unsupported methods available you can use as per this thread:

            Support for the development of custom automated trading strategies using NinjaScript.


            As they are unsupported we cannot guarantee the functionality and should be reserved only for experienced programmers.

            Please let me know if I may be of additional assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by algospoke, Yesterday, 06:40 PM
            2 responses
            22 views
            0 likes
            Last Post algospoke  
            Started by ghoul, Today, 06:02 PM
            3 responses
            14 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            45 views
            0 likes
            Last Post jeronymite  
            Started by Barry Milan, Yesterday, 10:35 PM
            7 responses
            21 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by AttiM, 02-14-2024, 05:20 PM
            10 responses
            181 views
            0 likes
            Last Post jeronymite  
            Working...
            X