• 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

Account Selector issue

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

    Account Selector issue

    Hi,

    I don't know if this is a bug or something else but I am having difficulty in isolating positions so they are only displaying if the specific account is selected in ' accountSelector.SelectedAccount' field.

    Take for example the AddOn Framework example. If i update the OnPositionUpdate method with the following code,

    Code:
            // This method is fired as a position changes
            private void OnPositionUpdate(object sender, PositionEventArgs e)
            {
                try
                {
                    Dispatcher.InvokeAsync(() =>
                    {
                        if (e.Position.Instrument != Instrument)
                            return;
    
                        outputBox.Text = string.Format("Time: {1}{0}Selected Acc: {2}",
                            Environment.NewLine,
                            DateTime.Now,
                            accountSelector.SelectedAccount.Name);
                    });
                }
    
                catch (Exception error)
                {
                    Dispatcher.InvokeAsync(() =>
                    {
                        // It is important to protect NinjaTrader from any unhandled exceptions that may arise from your code
                        outputBox.Text = "AddOnFramework - OnPositionUpdate Exception: " + error.ToString();
                    });
                }
            }
    When I compile and open the AddOn along with a SuperDOM both selected to Sim101, when I select another account on the AddOn and open a trade through the SuperDOM on the Sim101 account, the OnPositionUpdate still fires even though selected account is different.

    Please can someone assist, thanks.

    The video link explains hopefully what is happening.:http://recordit.co/vCKDFjQS5k

    #2
    Hello michaeldim, and thank you for your report.

    Since Add-Ons can have their own account selectors (see http://ninjatrader.com/support/helpG...ntselector.htm), the cost to this freedom is that they are not tied down to the SuperDOM's account selector.

    To work around this limitation, and retrieve an open SuperDOM's selector, please review the content my colleague Jesse has put together at this forums post, and please let us know if there are any further questions we could answer.

    http://ninjatrader.com/support/forum...44&postcount=7
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Jessica,

      Thanks for your reply.

      To be honest I was using SuperDOM as an example and my expectation being that whether the trade was opened from the DOM, Basic Entry, Order Ticket, etc that the AddOn would only subscribe to positions related to the account selected within it.

      It certainly works when the AddOn is initially opened, however as soon as I change the account within the AddOn do other account positions leak through.

      My understanding of the this snippet in the initialize method led to me to believe that we are only subscribe to events relevant to the selected account within the AddOn.

      Code:
         accountSelector.SelectionChanged += (o, args) =>
                  {
                      if (accountSelector.SelectedAccount != null)
                      {
                          // Unsubscribe to any prior account subscriptions
                          accountSelector.SelectedAccount.PositionUpdate -= OnPositionUpdate;
      
                          // Subscribe to new account subscriptions
                          accountSelector.SelectedAccount.PositionUpdate += OnPositionUpdate;
                      }
                  };
              }
      Thanks

      Comment


        #4
        Hello,

        Thank you for the reply.

        I believe what you are seeing is that the account is not being un-subscibed in this case.

        For example if I have two accounts, and the first selected in the addon is Sim101. I can places trades on Sim101 and see those trades. Now if I select Sim102 in the addon, I can still place trades on SIm101 and see the subscription. Is this the same as what you are experiencing?

        I will need to research this further to see if any change is needed to the unsubscription syntax or if this is something happening internally. When I have more details I will reply back here.

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

        Comment


          #5
          Jesse, yes this is what I'm experiencing, the account is not unsubscribing when it is changed. Thanks.

          Comment


            #6
            Hello,

            I wanted to reply back on this item.

            It appears there is actually no problem here, the sample just does not contain the additional logic needed for actually un subscribing. I have suggested that we update the help guide samples to also include the changes in the attached script.

            The existing unsubscription is simply making sure that there are not duplicate handlers for the same event, but does not reference the previous account object. You would need to store the selected account as a variable, and if the account changes to some other account than what is stored, remove the handler from the stored variable and reset it.

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

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by dadarara, Today, 12:18 PM
            0 responses
            1 view
            0 likes
            Last Post dadarara  
            Started by joemiller, Today, 07:33 AM
            0 responses
            7 views
            0 likes
            Last Post joemiller  
            Started by isnercrypto, Today, 06:42 AM
            0 responses
            4 views
            0 likes
            Last Post isnercrypto  
            Started by Coursocied67, Today, 04:02 AM
            0 responses
            5 views
            0 likes
            Last Post Coursocied67  
            Started by TheGameOfProbabilities, 07-18-2019, 06:56 AM
            7 responses
            37 views
            0 likes
            Last Post DaveS
            by DaveS
             
            Working...
            X