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

Toggle Indicator Bool Value From Another Indicator

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

    Toggle Indicator Bool Value From Another Indicator

    I am trying to use a toolbar button in another indicator to toggle a Boolean value in another indicator. Here is the code and I am not getting any errors but it is not toggling the indicator Bool (ShowShorts) from true to false and vice versa.


    //new code test for indicator bool toggle
    private void btnConfirmations_Click(object sender, EventArgs e)//includes toggle function with logic below for confirmations
    {
    if (ShowConfirmations == true)
    {
    Myindicator(BarsArray[0],Color.LimeGreen,Color.Red,true,true,5,false,233). ShowShorts = true;
    ShowConfirmations = false;
    }
    else if (ShowConfirmations == false)
    {
    Myindicator(BarsArray[0],Color.LimeGreen,Color.Red,true,true,5,false,233). ShowShorts = false;
    ShowConfirmations = true;
    }}

    Any ideas? Am I not accessing the bool value correctly?

    #2
    There isn't a supported way to do this however I'll leave this open for others to assist with if someone has found a way. You may also try searching/asking here: http://ninjatrader.com/support/forum...ad.php?t=22435
    LanceNinjaTrader Customer Service

    Comment


      #3
      Originally posted by jhowinvest View Post
      I am trying to use a toolbar button in another indicator to toggle a Boolean value in another indicator. Here is the code and I am not getting any errors but it is not toggling the indicator Bool (ShowShorts) from true to false and vice versa.


      //new code test for indicator bool toggle
      private void btnConfirmations_Click(object sender, EventArgs e)//includes toggle function with logic below for confirmations
      {
      if (ShowConfirmations == true)
      {
      Myindicator(BarsArray[0],Color.LimeGreen,Color.Red,true,true,5,false,233). ShowShorts = true;
      ShowConfirmations = false;
      }
      else if (ShowConfirmations == false)
      {
      Myindicator(BarsArray[0],Color.LimeGreen,Color.Red,true,true,5,false,233). ShowShorts = false;
      ShowConfirmations = true;
      }}

      Any ideas? Am I not accessing the bool value correctly?
      1. Any errors in your log?
      2. How did you expose the bool, ShowShorts, for outside access, in the called indicator?

      Comment


        #4
        It is just listed as a private bool in the called indicator. Is that what you mean by exposing the bool? I have no errors in the log.

        private bool showShorts = true;

        Comment


          #5
          Originally posted by jhowinvest View Post
          It is just listed as a private bool in the called indicator. Is that what you mean by exposing the bool? I have no errors in the log.

          private bool showShorts = true;
          " ... no errors in the log." is a bit of a surprise. Are you sure that you have enabled your log to show errors? Given the protection level of the showShorts bool, I would expect an error about the access level.

          If you want to access a variable from outside its class, you need to properly expose the variable for such access. Here is a reference sample on how to do so. ref: http://www.ninjatrader.com/support/f...ead.php?t=4991

          Comment


            #6
            I looked through the sample bool series and the ninja boolseries class. Now that I have a bool series created and set it to true or false how do I then use that in another indicator to do something? When I try to use that bool in an if statement it doesn't allow me to use it. For example using the bear indication bool series from the sample...if I try to use it in an if statement to do something I get an error:

            if (bearIndication == true)
            {
            Do something here
            }

            The error is "operator == can't be applied to operand of type nintrader.data.boolseries and bool

            I am evidently looking at this from the wrong perspective based on what I am trying to do. I want to have one indicator change a bool value from true to false OR false to true in another indicator and I am not seeing how the boolseries will let me do that. The logic in indicator A has a bool value that when true something happens and when false nothing happens. I want to be able to set the bool value in indicator A back and forth from true to false using and action in indicator B if that makes sense.

            Comment


              #7
              You will need to access the index location of the bearIndication to get a true false value. Otherwise you would just get the entire data series.

              bearIndication[0] //for example

              LanceNinjaTrader Customer Service

              Comment


                #8
                Okay I see. I changed it to:

                bearIndication[0] == true

                and no errors now. I will keep working on it. Thanks.

                Comment


                  #9
                  Now I am getting the following error in indicator B where I am trying to toggle the boolseries in indicator A...here is the code from indicator B

                  //new code test for indicator bool toggle
                  private void btnConfirmations_Click(object sender, EventArgs e)//includes toggle function with logic below for confirmations
                  {
                  if (ShowConfirmations == true)
                  {
                  IndicatorA(BarsArray[0],Color.LimeGreen,Color.Red,true,true,5,false,233). bearIndication = true;
                  ShowConfirmations = false;
                  }
                  else if (ShowConfirmations == false)
                  {
                  IndicatorA(BarsArray[0],Color.LimeGreen,Color.Red,true,true,5,false,233). bearIndication = false;
                  ShowConfirmations = true;
                  }}

                  The error is: NinjaTrader.Indicator.IndicatorA.bearindication is inaccessible due to its protection level. If I replace ".bearIndication" with "ShowShorts" I get no errors but the "ShowShorts" true/false value is still not being changed. "ShowShorts" is a private bool from IndicatorA that controls when something happens.

                  Comment


                    #10
                    Unfortunately I won't be able to assist with button press related scripts but if you have a supported script that needed to access a value from a script it called I'd be happy to help as best I can. Otherwise I'll leave it open for the community to assist with.

                    That being said, I'm assuming this is the cause of your issue:
                    IndicatorA(BarsArray[0],Color.LimeGreen,Color.Red,true,true,5,false,233). bearIndication = false;

                    There isn't a supported way to set values for indicator A when calling it from indicator B
                    Also, if you did have accessibility this would be setting the whole series to true/false when you likely only want to set a specific index location to true/false.
                    LanceNinjaTrader Customer Service

                    Comment


                      #11
                      Okay. It sounds like what I was trying to do isn't possible and I appreciate your help.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by junkone, Today, 11:37 AM
                      1 response
                      7 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by frankthearm, Yesterday, 09:08 AM
                      11 responses
                      41 views
                      0 likes
                      Last Post frankthearm  
                      Started by quantismo, 04-17-2024, 05:13 PM
                      5 responses
                      35 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by proptrade13, Today, 11:06 AM
                      1 response
                      6 views
                      0 likes
                      Last Post NinjaTrader_Clayton  
                      Started by love2code2trade, 04-17-2024, 01:45 PM
                      4 responses
                      34 views
                      0 likes
                      Last Post love2code2trade  
                      Working...
                      X