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

Strategy restarted after price connection lost, leaving existing position unclosable

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

    Strategy restarted after price connection lost, leaving existing position unclosable

    My NT log reports
    "NinjaTrader Continuum (Live): Primary connection=Connection lost, Price feed=Connection lost"
    after my strategy had established a long position. This interruption disabled, and then reenabled, my strategy, which would normally have closed the position at a price that was realized later in the session (after the interruption) but the position was never closed.

    My questions are:
    1. Was this failure to submit an appropriate sell order due to the fact that my strategy's start behavior is set to WaitUntilFlat?
    2. If so, then which start behavior option would best allow the strategy to continue functioning as if the interruption had not occurred?
    3. If I change the start behavior option, do I need to remove the following lines (at the start of code section OnBarUpdate) that are intended to ensure processing of only realtime events?
    if (State == State.Historical)
    return;
    if (BarsInProgress != 0)
    return;
    if (CurrentBars[0] < 1)
    return;



    #2
    Hello Red_70,

    Thank you for your post.

    Yes, this would occur if you were either using Wait Until Flat or Immediately Submit. Both of these start behavior options would not check the account position at the time the strategy is restarted and simply start submitting orders as they assume your account is in the position the strategy is (i.e. Flat, since you're not submitting anything historically). When the strategy restarted it simply started submitting orders as if the account position was in fact flat.

    You can avoid this by using Wait Until Flat, Synchronize Account or Immediately Submit, Synchronize Account as the strategy start behavior. This would see the open position and submit a synchronization order to bring the position back to flat before further orders are submitted in real time. This would not require you to remove the lines that cause processing of only real time events.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate,

      Thanks for your reply.

      According to the NT8 support guide, "Wait Until Flat, Synchronize Account" and "Immediately Submit, Synchronize Account" both submit market orders to reconcile the account position to the strategy position. Ideally, I'd like to avoid the submission of market orders to close existing positions, relying instead on my strategy's logic to check for the existence of a position, via
      if (Position.MarketPosition == MarketPosition.Long) {...}
      before submitting a limit order to close.

      Could I use the "Adopt Account Position" start behavior to achieve this goal? According to the NT8 support guide, "Adopt account position will only be available if the developer of a strategy has programmed the strategy to be aware of the real-world position." Does the above test for the existence of a long position satisfy this requirement? If not, how can I implement "Adopt Account Position"?

      Comment


        #4
        Hello Red_70,

        Thank you for your reply.

        You could do that as well, yes. Here's a simple example script that will exit an existing long position on the account when the strategy is enabled. You could modify this to submit protective orders for the position instead if you like.

        Please let us know if we may be of further assistance to you.
        Attached Files
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by AaronKoRn, Yesterday, 09:49 PM
        0 responses
        11 views
        0 likes
        Last Post AaronKoRn  
        Started by carnitron, Yesterday, 08:42 PM
        0 responses
        10 views
        0 likes
        Last Post carnitron  
        Started by strategist007, Yesterday, 07:51 PM
        0 responses
        11 views
        0 likes
        Last Post strategist007  
        Started by StockTrader88, 03-06-2021, 08:58 AM
        44 responses
        3,981 views
        3 likes
        Last Post jhudas88  
        Started by rbeckmann05, Yesterday, 06:48 PM
        0 responses
        9 views
        0 likes
        Last Post rbeckmann05  
        Working...
        X