• 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

sound alert not working on TSI

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

    sound alert not working on TSI

    I;m trying to make TSI alert anytime it crosses above or below zero.
    I think I have the code mostly correct for the alert except I'm not using the right piece that says its TSI since TSI isn't defined anywhere at least by name.
    I tried fastAbsEma[0] and fastEma[0] but neither works.
    Thanks
    Attached Files

    #2
    Hello simpletrades,

    Thanks for your post.

    The plot's value is what you would want to use, so Value[0] to Value[1].

    Your code shows:

    if (fastAbsEma[0] >0 && fastAbsEma[1] <=0)
    if (fastAbsEma[0] <0 && fastAbsEma[1] >=0)
    if (alertBool)PlaySound(@"C:\mysounds\horse_1.wav");

    The two "if" statements should be put together as you want an alert if either condition occurs. For an "either" type condition you would use the "Or" operator || to say one condition or the other to fire the alert sound.

    Recommend:

    if (Value[0] >0 && Value[1] <=0 || Value[0] <0 && Value[1] >=0)
    if (alertBool)PlaySound(@"C:\mysounds\horse_1.wav");
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      that gave me an error--see attached
      Attached Files

      Comment


        #4
        Originally posted by NinjaTrader_Paul View Post
        Hello simpletrades,

        Thanks for your post.

        The plot's value is what you would want to use, so Value[0] to Value[1].

        Your code shows:

        if (fastAbsEma[0] >0 && fastAbsEma[1] <=0)
        if (fastAbsEma[0] <0 && fastAbsEma[1] >=0)
        if (alertBool)PlaySound(@"C:\mysounds\horse_1.wav");

        The two "if" statements should be put together as you want an alert if either condition occurs. For an "either" type condition you would use the "Or" operator || to say one condition or the other to fire the alert sound.

        Recommend:

        if (Value[0] >0 && Value[1] <=0 || Value[0] <0 && Value[1] >=0)
        if (alertBool)PlaySound(@"C:\mysounds\horse_1.wav");
        or possibly this:

        if ((Value[0] >0 && Value[1] <=0 || Value[0] <0 && Value[1] >=0)&& (alertBool)) PlaySound(@"C:\mysounds\horse_1.wav");
        RJay
        NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

        Comment


          #5
          Hello simpletrades,

          Thanks for your reply.

          Please review your code for syntax errors.

          You have 0* || *Value and it should be 0 || Value
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            You were correcting the 2nd one. I'll see if it helps. thanks.
            I just realized, my code says in Variables private bool alertBool=true; but I have the indicator updating intrabar. How will I keep the alert from going on and off if it crosses back and forth intrabar?
            Last edited by simpletrades; 03-13-2017, 09:29 AM.

            Comment


              #7
              Hello simpletrades,

              Thanks for your post.

              Please remove/delete line 75. replace with: if (Value[0] >0 && Value[1] <=0 || Value[0] <0 && Value[1] >=0)
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                I fixed it based on the prior correction suggested and it works but now since the indicator itself updates intrabar like I wanted it to, the alert goes on and off as it crosses back and forth too.
                How do I fix it?
                All my other indicators with alerts are dots and arrows that only come on at bar close so I have no example to copy from.

                Comment


                  #9
                  Hello simpletrades,

                  Thanks for your post.

                  If you want the indicator to only alert once, you can do this two ways, one is to use CalculateOnBarClose = true however, this will not provide intrabar alerts.

                  If you wish to maintain intrabar alert capability then you will need to run with CalculateOnBarClose = false which means your code is run on each incoming tick. Depending on the bar you may have 1000's of ticks and as you have observed as price changes so will the conditions and as you have coded so you will get the alert when the condition is true.

                  If you want the alert sound to fire once per bar but at an intrabar time, you can recode to test to see if it is the same bar you have already played the sound on. For example:

                  if (Value[0] >0 && Value[1] <=0 || Value[0] <0 && Value[1] >=0 && savedBar != CurrentBar)
                  {
                  if (alertBool)
                  {
                  savedBar = CurrentBar; // save the current bar number
                  PlaySound(....);
                  }
                  }

                  In the region variable you would need to declare private int savedBar;


                  Alternatively, using the code suggested by member Rjay:

                  if ((Value[0] >0 && Value[1] <=0 || Value[0] <0 && Value[1] >=0)&& (alertBool) && savedBar != CurrentBar)
                  {
                  savedBar = CurrentBar; // save the current bar number
                  PlaySound(@"C:\mysounds\horse_1.wav");
                  }

                  You will still need to declare the private int savedBar


                  Alternatively, if you prefer we can also refer you to 3rd party coder who can create what you need
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    My goal is to have TSI values update intrabar but only to sound an alert depending on the relationship at the close. will what you suggest do that?

                    Comment


                      #11
                      Hello simpletrades,

                      Thanks for your reply.

                      If all you want is to see the TSI update intrabar, then run the TSI indicator with CalculateOnBarClose = false and run your indicator with CalculateOnBarClose = true which then provides what you are seeking.
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        How is that possible since it sounds like you're saying to run it both ways at once or are you saying run both TSI versions at once? That kind of makes sense. Thanks

                        Comment


                          #13
                          Hello simpletrades,

                          Thanks for your reply.

                          Yes, you can add several instances of the same indicator and run each one different from the other. For example you can add 10 SMAs where each SMA is a different period and may be set at a different color. Each time you "add" an indicator you are adding a fresh copy of it that you can modify through the user interface to run as you wish.

                          In your case I was advising to use the TSI indicator so you can observe the per tick plot and run your alert indicator with CalculateOnBarClose = true;
                          Paul H.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by pjsmith, Today, 12:50 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post pjsmith
                          by pjsmith
                           
                          Started by quinton77, Yesterday, 09:59 PM
                          1 response
                          5 views
                          0 likes
                          Last Post NinjaTrader_EricB  
                          Started by akuntysh, Today, 12:02 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post akuntysh  
                          Started by Revan, Yesterday, 11:53 PM
                          0 responses
                          8 views
                          0 likes
                          Last Post Revan
                          by Revan
                           
                          Started by allangl, Yesterday, 10:50 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post allangl
                          by allangl
                           
                          Working...
                          X