Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

sync account position

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

    #16
    @Josh, @Bertrand,

    attached a modified SampleMaCrossOver2 Strategy.
    The strategy's only function is to open a long position on date 8march2010 at 9.30.

    I added some more Print statements for easier debugging.

    Here my findings:
    1. From the Print statements it results that the strategy position is 1. This is how it should be.
    2. Also, when placing the strategy on a chart the blue Buy 1 arrow on 8march is present. Hence the strategy knows its position.
    3. The Control Center Strategy grid does NOT display the correct strategy position. Here only "-" is shown.
    4. NT Print gives: **NT** Syncing account... , Account position="",Strategy position="".

    My interpretation:

    I am inclined to think there is a bug in NinjaTrader: The Position Column should reflect the strategy position, and it does not do this.
    Probably by mistake you have taken the position value returned from Strategy.Account.Positions.FindByInstrument or similar and not the Strategy.Position value to fill the Strategy row Position Column value.

    Later for synch'ing you refer again to the Strategy row Position Column value which is already wrong...


    Please check again and try with the sample strategy I supplied.
    Please get back and report if you can confirm the bug.


    2. Point:
    I see discrepancies between the field value "historical" and the property "Historical". "Historical" stays true all the time, which is wrong, while "historical" reflects the correct situation.
    "historical" is however a NT internal variable and not publicly available.

    regards

    Andreas
    Attached Files

    Comment


      #17
      Thanks for posting and clarifying Andreas, will look into.

      Comment


        #18
        Andreas, is your strategy started with 'Immediately Submit' on? If I do this on ES March 1min (setting ExitOnClose = false, thus having a long open which needed synching) I get exactly this output -

        Code:
         
        **NT** Enabling NinjaScript strategy 'SampleMACrossOver2/284855f08848486ea606956a0f994def' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=True EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
        OnStartUp: Flat 0
        Strategy Position:Flat 0
        Account Position==null
        OnBarUpdate: Historical(True) 3/5/2010 7:51:00 AM
        OnBarUpdate: historical(True) 3/5/2010 7:51:00 AM
        3/8/2010 9:31:00 AM: EnterLongLimit()
        Strategy Position:Long 1
        Account Position==null
        **NT** Syncing account position on starting strategy 'SampleMACrossOver2/284855f08848486ea606956a0f994def'. Account position='' Strategy position='1L ES 03-10' 
        OnBarUpdate: Historical(False) 3/10/2010 10:35:00 AM
        OnBarUpdate: historical(False) 3/10/2010 10:35:00 AM
        NT detects it needs to sync after cycling through historical OnBarUpdate() part, thus it buys 1 Long contract for me before OnBarUpdate() processes the first realtime bar.

        Comment


          #19
          Fine, with 'Immediately Submit' = true it seems to works !!

          Thank you.

          (I will get back in case...)

          Comment


            #20
            Great, thanks for reporting back.

            Comment


              #21
              Ok, still digging deeper into it...

              in advance thank you for your time!!

              So I use SampleMACrossOver2 (ES 03-10 1 minute)and I do the following:
              A. Simple Enable/disable cycle.

              1. Enable Strategy
              2. Disable Strategy
              3. Enable Strategy

              all this is working fine and yields expected results.

              Then I do:
              B. disonnect/reconnect cycle

              1. Enable Strategy and wait until 1L and stop set
              2. Disconnect Account
              3. Recconect Account
              4. Enable Strategy

              The strategy seems to be running, but OnBarUpdate is never called real-time!!! (See the Print statements)

              Here something strange happens:
              The strategy's OnBarUpdate function is called only for the Historical == true portion.
              OnBarUpdate is not updated while current marketdata is coming in (session template 24/5)

              A few seconds later I get an error message:
              **NT** Unable to cancel out unmapped live orders... Strategy was not started.


              What does this mean? Why is this internal error triggered?

              regards
              Andreas
              Attached Files

              Comment


                #22
                Andreas, thanks for the follow up - do you get the same error if you there's no stop placed by the strategy? Trying to reproduce this here currently...

                I tried the same 2 processes for example with the default SampleMACrossOver script from us and it worked as expected in both your A & B scenarios.

                Thanks for the feedback.

                Comment


                  #23
                  I checked so many things with and without stop that I don't remember.

                  But your sampleMACrossover scripts are very simplistic, as they do not even contain a stop order. Almost every real-life strategy contains a stop-order.

                  You have my code, so you can just comment the relative line(s) to try out. I will coss check again over the w/e but today I am too tired for a constructive comment.

                  I did test using a connection to my IB account (simulated). (prefer testing on this and not the internal simulated data feed.

                  regards
                  andreas

                  Comment


                    #24
                    Andreas, I understand - thanks for your support and testing. I'll continue checking into this issue and update this thread then.

                    Comment


                      #25
                      Andreas, gotten to the core of this - the last issue you reported in was a bug related to the 'Cancel Exit orders if strategy is disabled' setting - causing orders getting stuck in 'PendingCancel' - this will be fixed with in beta 11.

                      Thanks for your support and for taking the time to report in.

                      Comment


                        #26
                        @Bertrand,

                        I tried the b11 with the SampeMACrossOver2 strategy ,

                        and to me the problem seems NOT resolved.

                        cycling through enable/disable is fine

                        cycling through disconnect/connect will cause the error
                        "Unable to cancel out unmapped live orders. Strategy not started...."

                        This is exactly as the incorrect behaviour in b10,
                        I tested this using a simulation account with IB using an ES 06-10 contract 1 min dataseries.


                        regards
                        Andreas

                        Comment


                          #27
                          Andreas, just tried on my B11 with ZenFire and ES 06-10 -

                          1. Use attached strategy and run with 'immediately submit' and 'cancel exit orders if disabled'

                          2. Strategy is hardcoded to be enabeld and synched.

                          3. As you start it up, it successfully sync acc to strat position and place stop and exit order bracket.

                          4. Disconnect Zen

                          5. NT will disable strat and cancel exit orders.

                          6. Reconnect Zen

                          7. Click on enabled in Strategies tab > it's reenabled and exit bracket orders again are placed to protect still synched position.

                          At which step do you run into issues with the attached cs?

                          Thanks for your patience and support.
                          Attached Files

                          Comment


                            #28
                            Hello Bertrand,

                            please use the super simple strategy I attached in post#21 (SampleMACrossOver2.cs)



                            (I will explain later the limitations of your new strategy supplied..)


                            The SampleMACrossOver2.cs strategy will do only one thing:

                            it will Enter long at 8 march 2010 9.30 W.Europe Standard Time and place a stop of 1.7%.

                            For the ES 06-10 this means that until now this long position is active and the stop has not been hit.

                            Using NTb11 , and
                            ExitOnClose=false;
                            SyncAccountPosition = true;

                            Please check the following:

                            1. after starting the strategy strategy_position=1 and account_position=1. You should see a stop loss order and your position under the orders/position tab.


                            2. Disable the strategy:
                            Now your strategy is disabled. But you should still see order and the position.


                            3. re-enable the strategy: up and running again.

                            4. Now disconnect the account connection. Allthough disconnected, your position should still be at the brokers account and your stop loss should still be at the exchange.
                            When using IB you can see this easily, and the IB TWS will show the stop loss order and the position.
                            I don't know Zenfire, but you should have some application other than NinjaTrader that will show your brokerage account positions and orders. If you have doubts, please continue testing using an IB account. A simulation IB account is fine (and if you are desperate I can give you my IB simulated login credentials)


                            5. reconnect to the account.

                            6. re-enable the strategy. The strategy will not start again and will return the error : "UNABLE TO CANCEL UNMAPPED LIVE ORDERS...".

                            Your bugfix has not yet worked and the result is the same as in b10.

                            7. I can reproduce the problem with the IB simulated account and also with the built in Sim101 account (Simulated data feed).

                            in step 6, the task of the NinjaTrader application is to map again the stop order on the exchange/broker to the stop order of the strategy. You can do so because you know the order token! But this mapping does not work! Please check agaib with the SampleMACrossOver2.cs supplied in an earlier post of this thread.

                            Best regards

                            Andreas


                            P.S. Your new SMACrossStopTargetSync.cs does not give me an actual postion on ES 06-10, it is just flat currently and it is also flat using Simulated data feed. Therefore it is not suited for testing as the problem described comes up only if you disconnect the account for a strategy that is NOT flat.

                            Generally I do not advice to use a dynamic strategy, e.g. a strategy that does actual entries/exits based on market data for testing the above problem. You will only become more confused because each time you repeat testing the market data has changed and therefore also the strategy position might have changed. A nightmare for testing...


                            Regards
                            andreas

                            p.p.s.
                            I have more thoughts on this problem, but I am afraid to give you too much input and then you give up investigating further.
                            Please tell me if it is fine to expose more ideas...
                            Thank you
                            Last edited by zweistein; 03-21-2010, 06:06 AM.

                            Comment


                              #29
                              zweistein,

                              Followed your steps exactly. Step 6 works on my end here as well. Your sample strategy recovered the order. Can you please confirm that you are on TWS 900.6?

                              Maybe a fresh install of NinjaTrader 7B11 would help?
                              Josh P.NinjaTrader Customer Service

                              Comment


                                #30
                                @Josh,

                                step 6 will produce the error "UNABLE TO CANCEL UNMAPPED LIVE ORDERS...".


                                I checked with 2 different accounts. Sim101 (simulation) and IB tws 900.6.
                                In both cases the error comes up.

                                the error will show only if the strategy has a position and is not flat the moment you disconnect the account.

                                I will attach again a test strategy, basically the same as before, but just to make sure we compare apples to apples...

                                regards

                                andreas

                                p.s. using a clean b11 install, nothing has changed. This is the print output produced by the strategy after a account disconnect/recconnect cylce:

                                **NT** Syncing account position on starting strategy 'FixedPosAndStop/9100bb2b09fa48279d79dab4fbe6e9b2'. Account position='' Strategy position='1L ES 06-10'
                                Close[0]=1163.5
                                OnBarUpdate: Historical(False) 3/23/2010 6:04:00 PM
                                Close[0]=1163.5
                                Close[0]=1163.5
                                Close[0]=1163.5
                                OnBarUpdate.SetStopLoss(1143.47475)
                                Close[0]=1163.5
                                Close[0]=1163.5
                                Close[0]=1163.5
                                Close[0]=1163.5
                                Close[0]=1163.5
                                **NT** Disabling NinjaScript strategy 'FixedPosAndStop/9100bb2b09fa48279d79dab4fbe6e9b2'
                                **NT** Enabling NinjaScript strategy 'FixedPosAndStop/9100bb2b09fa48279d79dab4fbe6e9b2' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=True EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=False MaxRestarts=4 in 5 minutes
                                **NT** Unable to cancel out unmapped live orders. Strategy 'FixedPosAndStop/9100bb2b09fa48279d79dab4fbe6e9b2' was not started.
                                Attached Files
                                Last edited by zweistein; 03-23-2010, 11:11 AM. Reason: more info

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                628 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                359 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                105 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                562 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                568 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X