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

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.

    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 DJ888, 04-16-2024, 06:09 PM
            6 responses
            18 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            1 view
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            6 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            10 views
            0 likes
            Last Post bltdavid  
            Started by alifarahani, Today, 09:40 AM
            6 responses
            41 views
            0 likes
            Last Post alifarahani  
            Working...
            X