Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to retrieve the value of the 'QuantityUpDown' and the state of the checkbox?

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

    How to retrieve the value of the 'QuantityUpDown' and the state of the checkbox?

    Hello
    I am currently creating my own addon, inspired by an example I found on the NinjaTrader forum: https://forum.ninjatrader.com/forum/...considerations.
    The specific example I am using is called 'ChartTraderCustomButtonsExample_NT8,' which I downloaded from this link: https://forum.ninjatrader.com/filedata/fetch?id=909605.

    In my strategy, I have tried to retrieve the value of the 'QuantityUpDown' and the state of the checkbox, but unfortunately, I am getting the following error message: 'OnBarUpdate method on bar 0: Object reference not set to an instance of an object.'
    As a result, the strategy remains disabled and does not function correctly.
    I have attached the addon and the strategy.
    How can I resolve this issue?

    Thank you in advance for the time you spend helping us


    Attached Files
    Last edited by aekzof; 07-20-2023, 05:55 AM.

    #2
    Hello aekzof,

    Thanks for your post.

    The error is advising that something you are accessing has not been created at the time you are accessing it. There is no specific thing I can advise as to the source of the error.

    To determine what the source of the error is you will need to debug your strategy. This is typically done with print statements added to your code to send a print output to the New>Ninjascript Output window. As you do not know where the error is, you would add a print statement every few lines of code and then observe the output window when you apply the strategy. The last print statement value shown in the output window would indicate the error occurs after that print statement, you can then add further print statements to zero in on the offending code.

    Here is a link to our tips on debugging: https://ninjatrader.com/support/help...script_cod.htm

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    You could view this help guide page for information and sample code about accessing QuantityUpDown in a custom NinjaScript: https://ninjatrader.com/support/help...tityupdown.htm

    Here is a link to a forum thread containing an example script that my colleague Chelsea shared demonstrating the use of QuantityUpDown: https://forum.ninjatrader.com/forum/...830#post759830
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hello
      I work directly within the indicator without using a strategy. I have added a condition to check if the QuantityUpDown is null. Then,
      I added 'ChartControl.Dispatcher.InvokeAsync((() =>' and everything is functioning without any issues.
      However, I am not sure if this is the solution!

      Code:
         protected override void OnBarUpdate()
      //     Quantity_Selector = new NinjaTrader.Gui.Tools.QuantityUpDown();
              {
      
                  if (Quantity_Selector != null)
                  {
      
                      ChartControl.Dispatcher.InvokeAsync((() =>
                      {
                          Print("Quantity_Selector NOT null ");
                          Print("Strategy Quantity_Selector : " + Quantity_Selector.Value);
                      }));
                  }
                  else
                  {
                      Print(CurrentBar + " "+ Time[0]);
                      Print("Quantity_Selector = null ");
      
                  }
      
          }​

      Comment


        #4
        Hello aekzof,

        Thanks for your notes.

        Yes, if you do not see errors occurring and everything is functioning without any issues then this would be a possible solution.

        Please let us know if we may assist further on this matter.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Hello
          To make it work, I had two errors that were corrected by this script.
          Thank you for your help.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by DeskTroll, Today, 12:09 PM
          3 responses
          22 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by Pabulon, 12-02-2024, 03:42 PM
          14 responses
          90 views
          0 likes
          Last Post Pabulon
          by Pabulon
           
          Started by tfa2806trader, Today, 12:04 PM
          10 responses
          25 views
          0 likes
          Last Post tfa2806trader  
          Started by trdninstyle, 11-26-2024, 12:23 PM
          62 responses
          186 views
          0 likes
          Last Post trdninstyle  
          Started by lorien, 08-08-2021, 07:33 AM
          12 responses
          721 views
          0 likes
          Last Post AndyM871  
          Working...
          X