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

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://li153-236.members.linode.com/...harp/index.php

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by GLFX005, Today, 03:23 AM
            0 responses
            0 views
            0 likes
            Last Post GLFX005
            by GLFX005
             
            Started by XXtrader, Yesterday, 11:30 PM
            2 responses
            11 views
            0 likes
            Last Post XXtrader  
            Started by Waxavi, Today, 02:10 AM
            0 responses
            6 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by TradeForge, Today, 02:09 AM
            0 responses
            11 views
            0 likes
            Last Post TradeForge  
            Started by Waxavi, Today, 02:00 AM
            0 responses
            2 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Working...
            X