• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Creating a sync method

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

    Creating a sync method

    I'm trying to create a method that helps me in the sync process of NT, not only when starting a strategy but also when long disconnections occur. In order to set the right logic flow, I need to understand some details on how it runs. Here some questions:

    1. When a strategy is starting, the work logic order of main methods is:
    Initialize() OnStartUp() OnConnectionStatus() OnBarUpdate() then OnPositionUpdate( ) and others ?

    2. When a running strategy is reconnecting after a connection loss, is it :
    OnConnectionStatus() OnPositionUpdate( ) OnBarUpdate() then others ?

    3. If I select in the Strategies-tab the option: KeepRunning on ConnectionLoss, once the connection is recovered, I understand that the Strategy won't recalculate anything but only will process the new tick coming, is it not? So I assume that any previous Strategy Position will continue to be the same. But if I select in the Strategies-tab the option: Recalculate on ConnectionLoss, it will mean that once the connection is back on, then the Strategy will use the historical data to calculate the right Strategy Position, right? So, if I use within my code: if ( historical ) { returns;} then any recalculation would always be a FLAT Strategy Position, right?

    4. I select in the Strategies-tab the option: Recalculate on ConnectionLoss, once the connection is back on, what method should go first: OnBarUpdate() cause it's recalculating OR OnConnectionStatus() because of the recovered connection? This is key to me in order to create a sync method.

    5. If I set to sync at initial startup Account Positions with Immediately submit live working historical orders, but I use in the code:
    if ( historical ) { returns;}
    then my Strategy Position will be flat when the first live tick data comes, but what would it happen if my broker's account has actually an open position, will NT submit a reconciliatory order to sync positions with that first tick of live data ? or since there's not any longer historical data, not reconciliatory orders will be submitted any more?

    6. Is there any way that I was able to submit direct orders to my broker's account from any method other than OnBarUpdate(), such as protected override void OnConnectionStatus( ) in order to affect only my broker's account leaving out of effect the Strategy position?

    7. Is there any unsupported way to change the internal variables values for StrategyPosition OR Strategy Position.Quantity ?



    Thanks
    Last edited by pstrusi; 09-30-2019, 06:10 AM.

    #2
    Hello ptrusi,

    Thank you for your post.

    1 and 2: As far as order goes, most of the processing is event based, so the methods are fired when an event happens that impacts that method. So, OnConnectionStatus() most likely won't be triggered until a connection issue occurs. Initialize() OnStartUp() will go first, but after that it's dependent on what events occur. After a disconnect/reconnect event, OnConnectionStatus() fires, then the next OBU in my testing.

    3. All of this is correct.

    4. I select in the Strategies-tab the option: Recalculate on ConnectionLoss, once the connection is back on, what method should go first: OnBarUpdate() cause it's recalculating OR OnConnectionStatus() because of the recovered connection? This is key to me in order to create a sync method.

    5. In this case your account will not be in sync with your strategy and will remain out of sync.

    6. You should be able to submit an order from any event method. You could submit one directly from OnConnectionStatus if you like.

    7. There is no way, supported or unsupported, that we are aware of to change the internal values for StrategyPostion or StrategyPosition.Quantity.

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

    Comment


      #3
      Hi Kate,
      I appreciate your attention and response to my questions.

      I have only a doubt in regards to question 6. Let's suppose that within OnConnectionStatus() , I detect that my actual Strategy Position is flat, BUT the AccountPosition, somehow is not. If I submit a reconciliatory order to flatten my Account Position, won't that action create a non flat Strategy Position now?

      Once again, thank you

      Comment


        #4
        Hello pstrusi,

        Thank you for your reply.

        I believe I may have misread question six. While you can submit an order from within OnConnectionStatus(), this would still affect your strategy position. You would need to manually sync the strategy by submitting a manual order to bring your Strategy and Account positions to be the same.

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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by horace chow, Today, 04:00 PM
        3 responses
        14 views
        0 likes
        Last Post bltdavid  
        Started by PrimoItch, Today, 04:35 PM
        0 responses
        6 views
        0 likes
        Last Post PrimoItch  
        Started by Serge A, Today, 04:03 PM
        0 responses
        9 views
        0 likes
        Last Post Serge A
        by Serge A
         
        Started by JBTrader2005, Today, 03:57 PM
        0 responses
        6 views
        0 likes
        Last Post JBTrader2005  
        Started by Austiner87, Yesterday, 09:29 PM
        1 response
        19 views
        0 likes
        Last Post NinjaTrader_Kate  
        Working...
        X