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

Alert buzzer

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

    Alert buzzer

    Hello,

    I created an alert in OBU but the Alert keep on buzzing every 10 seconds. I just want the buzz to be heard once when it meet the condition of the if statement. Right now its buzzing constantly even if foundIndex do not equal index3.

    Code:
    
    { 
    
        double highPrice = Int32.MinValue;
    
        for (int barIndex = ChartBars.FromIndex; barIndex <= ChartBars.ToIndex; barIndex++)
           {
        if (Bars.GetHigh(barIndex) > highPrice)
        {
    
         highPrice = Bars.GetHigh(barIndex);
         index3 = barIndex;
    
    
    
    
    
        }
           }
    
    
        if (foundIndex == index3);
    
    [LEFT][COLOR=#808080][FONT=Consolas]Alert([/FONT][/COLOR][/LEFT][LEFT][COLOR=#800000][FONT=Consolas]"myAlert"[/FONT][/COLOR][/LEFT][LEFT][COLOR=#808080][FONT=Consolas],[/FONT][/COLOR][/LEFT][LEFT][COLOR=#FFFFFF][FONT=Consolas] [/FONT][/COLOR][/LEFT][LEFT][COLOR=#808080][FONT=Consolas]Priority.High,[/FONT][/COLOR][/LEFT][LEFT][COLOR=#FFFFFF][FONT=Consolas] [/FONT][/COLOR][/LEFT][LEFT][COLOR=#800000][FONT=Consolas]"Reached threshold"[/FONT][/COLOR][/LEFT][LEFT][COLOR=#808080][FONT=Consolas],[/FONT][/COLOR][/LEFT][LEFT][COLOR=#FFFFFF][FONT=Consolas] [/FONT][/COLOR][/LEFT][LEFT][COLOR=#808080][FONT=Consolas]NinjaTrader.Core.Globals.InstallDir+[/FONT][/COLOR][/LEFT][LEFT][COLOR=#800000][FONT=Consolas]@"\sounds\Alert1.wav"[/FONT][/COLOR][/LEFT][LEFT][COLOR=#808080][FONT=Consolas],[/FONT][/COLOR][/LEFT][LEFT][COLOR=#FFFFFF][FONT=Consolas] [/FONT][/COLOR][/LEFT][LEFT][COLOR=#FF6600][FONT=Consolas]10[/FONT][/COLOR][/LEFT][LEFT][COLOR=#808080][FONT=Consolas],[/FONT][/COLOR][/LEFT][LEFT][COLOR=#FFFFFF][FONT=Consolas] [/FONT][/COLOR][/LEFT][LEFT][COLOR=#808080][FONT=Consolas]Brushes.Black,[/FONT][/COLOR][/LEFT][LEFT][COLOR=#FFFFFF][FONT=Consolas] [/FONT][/COLOR][/LEFT][LEFT][COLOR=#808080][FONT=Consolas]Brushes.Yellow);[/FONT][/COLOR][/LEFT][LEFT][COLOR=#FFFFFF][FONT=Consolas] [/FONT][/COLOR][/LEFT]
         
    
         }
    Any idea why?
    Thanks

    #2
    Hello frankduc,

    You have a rearm seconds set to 10, if this condition continues to become true it would happen every 10 seconds.

    I don't see how you are confirming that the condition is true/not true. Can you provide a specific example which shows how you were checking that?

    You also did not include the variables here for me to see the types. If either index3 or foundindex are a double then checking == will not always work.

    I could suggest adding Prints into your logic to print the variables to see why this may be happening. Once you do this if you are still having trouble, please provide a sample that includes the print along with the output you had seen.

    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      index3 and foundIndex are both int
      the Print() show the barIndex for foundIndex and index3. If index3 the high of the chart is at bar 300 and foundIndex reach bar 300, because foundIndex is also a barIndex than condition is met to buzz.
      You mean that if both reach 300 at the same time it will buzz and than as long as they reach 300 it will buzz every 10 secs. But if it pass at 350 the condition are not met, will still buzz?

      TY

      Comment


        #4
        Hello frankduc

        If the condition is true and you call the alert syntax that will cause an alert. The rearm seconds only causes this alert to happen once every 10 seconds if it is called more frequently than 10 seconds. Based on the result you are seeing, it sounds like the alert syntax is being called frequently but your re arm seconds of 10 is only allowing it every 10 seconds. You could set a rearm with a smaller amount of seconds to check how frequently this is happening, or you could use a print.

        One item I can now see is that you have invalid syntax:
        Code:
          if (foundIndex == index3);
        You used a semicolon at the end of the if statement, that makes this do nothing.

        Because you have not used the curly braces you have set yourself up for failure in being able to check if this condition becomes true or not. You should always use a body with your if statement so you can debug it later:

        Code:
        if (foundIndex == index3)
        {
        Alert(...);
        Print("Condition became true");
        }
        If you had put a semi colon at the end but used a body { }, it would be easy to see your condition was not working because it is just being called all the time, after removing the semi colon you should see less prints because the condition is actually being used.





        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          You we're right i should of seen that by myself.

          Thanks

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by PaulMohn, Today, 03:49 AM
          0 responses
          3 views
          0 likes
          Last Post PaulMohn  
          Started by inanazsocial, Today, 01:15 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by rocketman7, Today, 02:12 AM
          0 responses
          10 views
          0 likes
          Last Post rocketman7  
          Started by dustydbayer, Today, 01:59 AM
          0 responses
          2 views
          0 likes
          Last Post dustydbayer  
          Started by trilliantrader, 04-18-2024, 08:16 AM
          5 responses
          23 views
          0 likes
          Last Post trilliantrader  
          Working...
          X