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

Changing variables within an Indicator from another indicator with Buttons

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

    Changing variables within an Indicator from another indicator with Buttons

    I need some guidance. I need to create a script that has 3 plots that are public and they plot either a 1 or 0. But I need to create another indicator that has 3 chart buttons that sets these variables. The first indicator needs to get those values from the second indicator depending on the button clicks. Because of using Markers Plus I cannot create a single indicator because I receive 'Error on calling 'OnStateChange' method: Object reference not set to an instance of an object. when I combine both processes into 1 indicator. The Markers Plus copy indicator run just fine if the indicator has just the 3 public plots. But when I add the button to change the values is when I get the error. I am not sure how to proceed

    #2
    Hello thepcmd,

    A hosted indicator can set a value to a public variable. If bar information is used, Update() will need to be called before the return. The Browsable(false) attribute may also be used so the property does not appear in the UI, and XmlIgnore() so the property is not saved with the workspace or template.




    The value for the plot would only be set in real-time. A plot is intended to have values for every bar on the chart. Perhaps a plot is not the best object to hold the values?

    Is the hosted indicator intended to be used with multiple host indicators? (Can you further clarify why the buttons and the plots could not be set from a single indicator?)

    You have mentioned there is an error due to a null object. What is the null object causing the error?
    Use prints on every other line to see which print is the last print to appear. The line below it may be causing the error.
    Below is a link to a forum post that demonstrates using prints to understand behavior.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I have created an indicator with 3 plots. I need them to either be 1 or 0. I have tried to troubleshoot the issue by just creating the indicator without any buttons. If I set the value from Close[1} > Close[0] = 1 and vis-versa then the 'Markers Plus Copy' indicator works as expected If I add the buttons to the indicator to change values from 0 to 1 based on the button click. The 'Markers Plus Copy' indictor is added to the chart I select the indicator that I created as the input series. When it is added like that - that is when I get error messages in the NT8 log file. I get 2 errors - the first is on the indicator I created as Error on calling 'OnStateChange' method: Object reference not set to an instance of an object. The 'Markers Plus Copy' indicator error is - Error on calling 'SetState' method: Object reference not set to an instance of an object. I have based the buttons portion of the script on NT8 'SampleAddButton' aa_ApexFilters.cs > i have attached my indicator for reference. aa_ApexFilter.cs This is the version of the indicator that works correcty without the buttons. I am trying to create this 1 indicator so I can use it for a filter on 3 other indicators so I can click 1 button and set the value instead of making the changes to 3 others. Any help or alternatives would be appreciated. Thanks
      Last edited by thepcmd; 11-08-2020, 08:07 PM.

      Comment


        #4
        Hello thepcmd,

        One thing I forgot to mention is that if you are attempting to set a series value from a non-data-driven method, such as a button click, this must use TriggerCustomEvent.

        Below is a link to the help guide.


        In the button click event, print "button clicked", then print the value of the plot to ensure it is set. Once set, that value will be readable by a host script on the next bar update.


        With the null object, you will need to use prints and debug the script to identify which line is causing an error.

        Try Print("1"); then a line of logic, then Print("2"), as shown in the forum post that I have linked you.

        I am happy to assist with analyzing the output from the debugging prints.


        Just a heads up, I can walk you the process and assist with analyzing the output, I but I cannot debug your code on your behalf.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Chelsea

          Are there any examples that use a button click when using TriggerCustomEvent?

          Thanks

          Steve

          Comment


            #6
            Hello Steve,

            Attached is an example I have that is not posted on the forums.
            Attached Files
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thank you for the example. I have done most of my programming by following other examples. I don't know .NET well enough to make this work out.

              Comment


                #8
                Chelsea I have this example on my platform. I have not download in last several months if it has been updated. The example I have is Long Orders only. I have created a version to includes short orders as well. I actually had it working trading secondary symbol to short as well. Some how in creating the secondary on the long side something went crazy. Now when i apply my indicator the indicator without clicking the buttons starts sending Long and Short Orders (it does recognize my code to select primary or secondary) but once applied to the chart IT JUST START SENDING ORDERS IN BOTH DIRECTIONS even though the buttons are not yet clicked to be enabled and IT SEND ORDER endlessly, it never stops. Have to use task manager to close ninja trader and restart (since the indicator was just added and the workspace not saved I just have to re open) Thanks for any ideas

                Comment


                  #9
                  Hello DTSSTS,

                  Do you have order methods being called in OnBarUpdate() or are these in the button click handler method?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    I did add

                    if(CurrentBar< 1){
                    return;
                    }

                    in the OnBarUdate() area, which was there when I had the secondary short working properly

                    overnight I did change the conditions and the instant both directional trades stopped. The Secondary Instrument tradeing worked as expected, the when I test the primary I still had the same issues with instant trading regardless of button click status.

                    So I created a new indicator and removed the secondary trading conditions, the primary still instantly traded. I then removed the

                    if(CurrentBar< 1){
                    return;
                    }

                    from the OnBarUpdate()

                    BUT I STILL HAVE THE INSTANT TRADING REGARDLESS of click status of button

                    Comment


                      #11
                      update, IN THE NEW INDICATOR FOR THE SECONDARY INSTRUMENT TRADING

                      KEEPING (which I think i added for the secondary to work properly)

                      if(CurrentBar< 1){
                      return;
                      }

                      from the OnBarUpdate()

                      the indicator does NOT instantly trade without the buttons click.

                      IN this indicator everything works as expected

                      Comment


                        #12
                        Hello DTSSTS,

                        Remove the order methods from OnBarUpdate, move the order methods to the button click handler.

                        See the example in post #6 in the regions labelled Use Case #1 immediately submitting a market order.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          when i removed the

                          if(CurrentBar< 1){
                          return;
                          }

                          i still had instant trades, (I do have the example and I know that is not included), I think since the secondary is working as expected and the primary not the only difference I have in the code there is a section of code with 3 indicators in a group to trade if any of those are true, so I have blocked that group and I am not getting INSTANT trading, so I am trying to isolate if it is the any statement or one of those indicators

                          Thanks for the help

                          Comment


                            #14
                            i believe I have both working now. My group of indicators with IF ANY I believe I was missing my outside () around the group. adding those has eliminated the instant trade. Testing now for if will Trade or NOT

                            Comment


                              #15
                              Chelsea B Interesting development today when I load my indicator OR the default Example indicator on the Futures instruments. Which I rolled over this morning. The indicator Loads MES 12-21 and MNQ 12-21 instead of the new expiration that the chart has loaded MES 03-22 and MNQ 03-22. Also there is no way to change it.

                              thanks

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rdtdale, Today, 01:02 PM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by alifarahani, Today, 09:40 AM
                              3 responses
                              16 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by RookieTrader, Today, 09:37 AM
                              4 responses
                              19 views
                              0 likes
                              Last Post RookieTrader  
                              Started by PaulMohn, Today, 12:36 PM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by love2code2trade, 04-17-2024, 01:45 PM
                              4 responses
                              41 views
                              0 likes
                              Last Post love2code2trade  
                              Working...
                              X