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

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 Christopher_R, Today, 12:29 AM
                          0 responses
                          9 views
                          0 likes
                          Last Post Christopher_R  
                          Started by sidlercom80, 10-28-2023, 08:49 AM
                          166 responses
                          2,235 views
                          0 likes
                          Last Post sidlercom80  
                          Started by thread, Yesterday, 11:58 PM
                          0 responses
                          3 views
                          0 likes
                          Last Post thread
                          by thread
                           
                          Started by jclose, Yesterday, 09:37 PM
                          0 responses
                          8 views
                          0 likes
                          Last Post jclose
                          by jclose
                           
                          Started by WeyldFalcon, 08-07-2020, 06:13 AM
                          10 responses
                          1,415 views
                          0 likes
                          Last Post Traderontheroad  
                          Working...
                          X