• 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

Disable PlaySound() if running in Strategy

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

    Disable PlaySound() if running in Strategy

    Is there a State flag I can use or something similar to avoid playing audio when an indicator is being used in a strategy? (Indicator I am developing)

    Thanks

    #2
    Hello RandyT,

    Thanks for your post.

    Out of box, an indicator does not have any knowledge if it is added to a strategy. As a workaround, you could create an AddOn with static methods/variables for a means to have the strategy and the indicator communicate and share if that indicator is added by the strategy. C# code using GetHashCode() could be used to uniquely identify a specific instance of a NinjaScript object.

    An example for creating an AddOn for shared methods can be found below.

    https://ninjatrader.com/support/foru...104#post457104

    Please let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Originally posted by RandyT View Post
      Is there a State flag I can use or something similar to avoid playing audio when an indicator is being used in a strategy? (Indicator I am developing)
      You can invent this yourself.

      Why not create your own public non-browsable boolean property in your indicator that controls whether sound is played or not?

      When adding the indicator to the strategy, the strategy programmer explicitly sets this property to make the indicator 'go silent'.

      Problem solved.

      Comment


        #4
        Thanks bltdavid,

        This is the way I have handled this. Seems a bit messy.

        Is there a way to may parameters optional when loading an indicator from a strategy? Just use the defaults? That would allow me to keep the PlaySound() false and load the indicator without passing a string of parameters every time. Not a huge deal, but generally I am just wanting default parameters for these indicators anyway.

        Comment


          #5
          Originally posted by RandyT View Post
          Thanks bltdavid,

          This is the way I have handled this. Seems a bit messy.

          Is there a way to may parameters optional when loading an indicator from a strategy? Just use the defaults? That would allow me to keep the PlaySound() false and load the indicator without passing a string of parameters every time. Not a huge deal, but generally I am just wanting default parameters for these indicators anyway.
          A public property which is non-browsable does not get added as an argument, so calling the indicator from a strategy does not change in any way. That is, you want a public property specifically coded such that it is not added to the property grid or the parameter list.

          Are you sure you know what 'non-browsable' means?

          Code:
          [Browsable(false)]
          public bool Silence { get; set; }
          creates a public property called 'Silence' which defaults to false.

          This property, although public, is not added to the parameter list of your indicator.
          Why? Read about Browsable and NinjaScriptProperty (which is new for NT8) attributes.

          In your indicator, you check the value of this property before calling PlaySound, for example, setup a wrapper function, like this,

          Code:
          private void MyPlaySound(string filnam)
          {
              if (!Silence)
                  PlaySound(filnam);
          }
          In your strategy, load your indicator like this,

          Code:
          MyIndicator ind = MyIndicator(...);
          ind.Silence = true;
          AddChartIndicator(ind);  // optional
          Make sense?

          Good luck!
          Last edited by bltdavid; 08-15-2018, 12:41 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Gerik, Today, 12:14 AM
          0 responses
          2 views
          0 likes
          Last Post Gerik
          by Gerik
           
          Started by Bionian, Yesterday, 11:47 PM
          0 responses
          2 views
          0 likes
          Last Post Bionian
          by Bionian
           
          Started by adambrul, Yesterday, 11:34 PM
          0 responses
          1 view
          0 likes
          Last Post adambrul  
          Started by benjamind10, Yesterday, 07:27 PM
          0 responses
          4 views
          0 likes
          Last Post benjamind10  
          Started by YevhenShynkarenko, Yesterday, 06:07 PM
          0 responses
          5 views
          0 likes
          Last Post YevhenShynkarenko  
          Working...
          X