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

Alerts on COBC=false

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

    Alerts on COBC=false

    Hi Support,

    How to prevent the code from firing alerts on COBC=false when the value is touched?It works good on COBC = true.

    Thanks

    #2
    Hello cachevery,

    Thank you for your post.

    If you want to use CalculateOnBarClose = false you could use FirstTickOfBar to ensure the alerts only fire once per bar:
    Code:
    if(FirstTickOfBar)
    {
    // Your alert.
    }
    You can find a reference sample on this item at the following link: http://www.ninjatrader.com/support/f...ad.php?t=19387

    Please let me know if you have any questions.

    Comment


      #3
      Originally posted by NinjaTrader_PatrickH View Post
      Hello cachevery,

      Thank you for your post.

      If you want to use CalculateOnBarClose = false you could use FirstTickOfBar to ensure the alerts only fire once per bar:
      Code:
      if(FirstTickOfBar)
      {
      // Your alert.
      }
      You can find a reference sample on this item at the following link: http://www.ninjatrader.com/support/f...ad.php?t=19387

      Please let me know if you have any questions.

      Hi Patrick,the code uses OnBarUpdate method

      Comment


        #4
        I want the alerts to behave the same way,either it`s COBC= true or false.Is there a way to do that?

        Comment


          #5
          Hello cachevery,

          Thank you for your response.

          Are you trying to have the alert go off when running CalculateOnBarClose = false or true? Do you want the alert to go off intra-bar or on the close of the bar?

          Comment


            #6
            Originally posted by cachevery View Post
            Hi Support,

            How to prevent the code from firing alerts on COBC=false when the value is touched?It works good on COBC = true.

            Thanks
            What I suggest to do is the following

            (1) Historical bars -> no alerts
            (2) COBC = true -> trigger alert when the condition has been met for the current bar
            (3) COBC = false -> with the first tick of each bar check whether the condition has been met for the prior bar

            For example:

            Code:
            [COLOR=Blue]if [/COLOR](soundAlert && !Historical && IsConnected()) 
            [COLOR=Green]// only trigger alerts for real-time bars when connected)[/COLOR]
            { 
                  [COLOR=Blue]if[/COLOR](CalculateOnBarClose)
                  {      
                      [COLOR=Blue] if[/COLOR](condition[0])
                      [COLOR=Green] // put your sound alert here[/COLOR]
                  }
                  [COLOR=Blue]else if[/COLOR](FirstTickOfBar && condition[1])
                  {
                      [COLOR=Green]// put your sound alert here[/COLOR]
                  }
            }

            Comment


              #7
              Originally posted by NinjaTrader_PatrickH View Post
              Hello cachevery,

              Thank you for your response.

              Are you trying to have the alert go off when running CalculateOnBarClose = false or true? Do you want the alert to go off intra-bar or on the close of the bar?
              As i said i want both COBC =tru/false to behave equally.But when i set COBC = false itt`s firing alrets every second.I wnan the alers to go off intra-bar and on the bar close,depending on what i need.

              Comment


                #8
                Originally posted by Harry View Post
                What I suggest to do is the following

                (1) Historical bars -> no alerts
                (2) COBC = true -> trigger alert when the condition has been met for the current bar
                (3) COBC = false -> with the first tick of each bar check whether the condition has been met for the prior bar

                For example:

                Code:
                [COLOR=Blue]if [/COLOR](soundAlert && !Historical && IsConnected()) 
                [COLOR=Green]// only trigger alerts for real-time bars when connected)[/COLOR]
                { 
                      [COLOR=Blue]if[/COLOR](CalculateOnBarClose)
                      {      
                          [COLOR=Blue] if[/COLOR](condition[0])
                          [COLOR=Green] // put your sound alert here[/COLOR]
                      }
                      [COLOR=Blue]else if[/COLOR](FirstTickOfBar && condition[1])
                      {
                          [COLOR=Green]// put your sound alert here[/COLOR]
                      }
                }

                Hi Harry,where do i put this snipet within the code body?

                Comment


                  #9
                  Originally posted by cachevery View Post
                  Hi Harry,where do i put this snipet within the code body?

                  No,it doesn`t fly.I get different kind of errors when i try to implement this snippet

                  Comment


                    #10
                    Hello cachevery,

                    Thank you for your response.

                    When would you want the alert to trigger on CalculateOnBarClose = true? When would you want to see the alert trigger on CalculateOnBarClose = false? This may be as simple as a variable for re-arm seconds.

                    Comment


                      #11
                      Originally posted by NinjaTrader_PatrickH View Post
                      Hello cachevery,

                      Thank you for your response.

                      When would you want the alert to trigger on CalculateOnBarClose = true? When would you want to see the alert trigger on CalculateOnBarClose = false? This may be as simple as a variable for re-arm seconds.
                      I don`t understand you question,Patrick.What do you mean by ''When''?

                      Whenever i want,i guess.

                      Comment


                        #12
                        Hello cachevery,

                        Thank you for your note.

                        So you do not want to use FirstTickOfBar when using CalculateOnBarClose?
                        Code:
                                protected override void Initialize()
                                {
                                    CalculateOnBarClose = false;
                                }
                        
                                protected override void OnBarUpdate()
                                {
                        			if(FirstTickOfBar)
                        			{
                        				// Your alert goes here.
                        			}
                                }

                        Comment


                          #13
                          Originally posted by NinjaTrader_PatrickH View Post
                          Hello cachevery,

                          Thank you for your note.

                          So you do not want to use FirstTickOfBar when using CalculateOnBarClose?
                          Code:
                                  protected override void Initialize()
                                  {
                                      CalculateOnBarClose = false;
                                  }
                          
                                  protected override void OnBarUpdate()
                                  {
                          			if(FirstTickOfBar)
                          			{
                          				// Your alert goes here.
                          			}
                                  }
                          Where do i paste it in the code?

                          Comment


                            #14
                            Here is the notification snippet:

                            string subject = "";
                            if( currentlyOverSold )
                            {
                            subject = " " + Instrument.FullName + " at " + Math.Round( Close[0], 4 ).ToString( russian );
                            }
                            if( currentlyOverBrought )
                            {
                            subject = " " + Instrument.FullName + " at " + Math.Round( Close[0], 4 ).ToString( russian );
                            }

                            if( soundAlert != "" )
                            {
                            PlaySound( soundAlert );
                            }
                            if( emailAddress != "" )
                            {
                            string body = subject + Environment.NewLine + Environment.NewLine + "Message generated at " + Time[0];
                            SendMail( fromEmailAddress, emailAddress, subject, body );
                            }
                            }

                            Comment


                              #15
                              Hello cachevery,

                              Thank you for your response.

                              It would be the following:
                              Code:
                              if(FirstTickOfBar)
                              {
                              if( soundAlert != "" )
                              {
                              PlaySound( soundAlert );
                              }
                              if( emailAddress != "" )
                              {
                              string body = subject + Environment.NewLine + Environment.NewLine + "Message generated at " + Time[0];
                              SendMail( fromEmailAddress, emailAddress, subject, body );
                              }
                              }
                              }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, Yesterday, 06:40 PM
                              2 responses
                              23 views
                              0 likes
                              Last Post algospoke  
                              Started by ghoul, Today, 06:02 PM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              45 views
                              0 likes
                              Last Post jeronymite  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              7 responses
                              21 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              10 responses
                              181 views
                              0 likes
                              Last Post jeronymite  
                              Working...
                              X