Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Audible alert when simple condition trigerred

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

    Audible alert when simple condition trigerred

    I have a custom indictor that draws a circle on a bar when a condition is met.

    Now I would like to add an audible alert when the condition is met.

    When the condition is satisfied:

    DrawText("tag01"+CurrentBar, true, "l", 0, ((High[0] + Low[0])/2), 0, Color.DarkGreen, new Font("Wingdings", 40), StringAlignment.Center, Color.DarkGreen, Color.DarkGreen, 0);

    Works perfectly.

    To play the alert can I just add?
    PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\Alert1.wav");

    I have confirmed the wav file exists in that location.

    so the code wld be:

    condition code......

    DrawText("tag01"+CurrentBar, true, "l", 0, ((High[0] + Low[0])/2), 0, Color.DarkGreen, new Font("Wingdings", 40), StringAlignment.Center, Color.DarkGreen, Color.DarkGreen, 0);

    PlaySound(
    @"C:\Program Files (x86)\NinjaTrader 7\sounds\Alert1.wav");

    is that all I need to add?



    #2
    it wld seem not as I have audible alerts firing all the time. Not sure what they are triggered by.

    I only want the sound to be triggered when the condition is met.

    NB: That was after I added the
    PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\Alert1.wav");

    line to the code
    Last edited by skiguy; 08-02-2016, 12:16 AM.

    Comment


      #3
      Hello skiguy,

      Thanks for your posts.

      You will want to tie the two actions together with the condition, so your structure would look like:

      if (your conditions are true)
      {
      // do action 1 - draw text on chart
      DrawText("tag01"+CurrentBar, true, "l", 0, ((High[0] + Low[0])/2), 0, Color.DarkGreen, new Font("Wingdings", 40), StringAlignment.Center, Color.DarkGreen, Color.DarkGreen, 0);
      // do action 2 - play sound file
      PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\Alert1.wav");
      }

      The use of the {} contain all of the actions to be performed if the condition is true. This could be one action or several actions as long as they are within the braces {}
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Thanks Paul. I made that change and will test. Compiled without errors.

        I used {} as you provided but I was wondering if it needs to specifically be {} or would () also work.

        Comment


          #5
          Hello skiguy,

          Thanks for your post.

          In the context of an "if" statement, it may be helpful to think of the "()" as defining the extent of the question and the "{}" as containing all of the actions to perform if the result of the question is true. You would not be able to use "()" is place of "{}" and vice-versa.

          References:

          http://ninjatrader.com/support/helpG...sic_syntax.htm

          http://li153-236.members.linode.com/...harp/index.php
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Thanks for the further clarification and additional info. Very helpful.


            Originally posted by NinjaTrader_Paul View Post
            Hello skiguy,

            Thanks for your post.

            In the context of an "if" statement, it may be helpful to think of the "()" as defining the extent of the question and the "{}" as containing all of the actions to perform if the result of the question is true. You would not be able to use "()" is place of "{}" and vice-versa.

            References:

            http://ninjatrader.com/support/helpG...sic_syntax.htm

            http://li153-236.members.linode.com/...harp/index.php

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by demarcog, Today, 05:40 PM
            3 responses
            18 views
            0 likes
            Last Post NinjaTrader_EricB  
            Started by cincai, Today, 08:16 PM
            0 responses
            4 views
            0 likes
            Last Post cincai
            by cincai
             
            Started by cincai, Today, 08:04 PM
            0 responses
            1 view
            0 likes
            Last Post cincai
            by cincai
             
            Started by demarcog, Today, 06:23 PM
            0 responses
            4 views
            0 likes
            Last Post demarcog  
            Started by canliyayin, Today, 05:56 PM
            0 responses
            4 views
            0 likes
            Last Post canliyayin  
            Working...
            X