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

One Alert per bar

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

    One Alert per bar

    I am using the Wizard. My strategy is a cross of the zeroline and want to have it give one Alert per bar. Right now it gives alerts for everytime the price moves. I am not a programmer, so any help would be great. I added emails to the alert and yes I am getting alot of emails......lol
    Attached Files

    #2
    Hello,

    Thanks for the forum post!

    The best way to change this to once per bar is to change the indicator to only calculate once per bar instead of on each tick. To do this right click on the chart and go to strategies. Then change the setting for Calculate On Bar Close to true. This will cause the code to run only once per bar which will be what your looking for on your alert.

    Let me know if I can be of further assistance.

    Comment


      #3
      Originally posted by Viper3 View Post
      I am using the Wizard. My strategy is a cross of the zeroline and want to have it give one Alert per bar. Right now it gives alerts for everytime the price moves. I am not a programmer, so any help would be great. I added emails to the alert and yes I am getting alot of emails......lol
      How is your alert being triggered?
      Can you post the line which triggers the alert ?

      Comment


        #4
        I can post the step by step of the strategy if you like or email it.

        Comment


          #5
          Originally posted by Viper3 View Post
          I can post the step by step of the strategy if you like or email it.
          OK. Just post the entire text to the forum. Or the step by step if you wish.

          Comment


            #6
            {
            #region Variables
            // Wizard generated variables
            privateint myInput0 = 1; // Default setting for MyInput0
            // User defined variables (add any user defined variables below)
            #endregion
            ///<summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            ///</summary>
            protectedoverridevoid Initialize()
            {
            Add(WoodiesCCI(
            2, 5, 50, 34, 25, 14, 60, 100, 2));
            Add(WoodiesCCI(
            2, 5, 50, 34, 25, 14, 60, 100, 2));
            CalculateOnBarClose =
            true;
            }
            ///<summary>
            /// Called on each bar update event (incoming tick)
            ///</summary>
            protectedoverridevoid OnBarUpdate()
            {
            // Condition set 1
            if (CrossAbove(WoodiesCCI(2, 5, 50, 34, 25, 14, 60, 100, 2), 0, 1))
            {
            DrawArrowUp(
            "My up arrow" + CurrentBar, false, 0, Low[0], Color.Lime);
            PlaySound(
            @"C:\Program Files\NinjaTrader 7\sounds\Alert1.wav");
            SendMail(
            "[email protected]", "[email protected]", "Alert Trade 9 minute chart", "Go long set stop at 30 T1 @20");
            }

            Comment


              #7
              So I need to put it under Variables. can you help me write that part. I did this but it need to be written right.

              region Variables


              // Wizard generated variables


              private int myInput0 = 1; // Default setting for MyInput0


              // User defined variables (add any user defined variables below)


              #endregion


              /// <summary>


              /// This method is used to configure the strategy and is called once before any strategy method is called.


              /// boot alreadyAlertThis = false;


              /// OnBarUpdate()


              /// {


              /// if (FirstTickOfBar)


              /// {alreadyAlertThisBar=false;}


              /// if(alert conditions == true&& alreadyAlertThisBar == false)


              /// {


              /// Alert(.....)


              /// alreadyAlertThisBar = true;


              /// }


              /// }


              ///

              Comment


                #8
                See what happens with this. You cannot do it in the wizard, You are going to have to unlock the code.

                Code:
                private bool boolAlertSounded = false; [COLOR="blue"]// declare and intialize the bool flag
                [/COLOR]
                protected override void OnBarUpdate()
                {
                if (FirstTickOfBar) boolAlertSounded = false; [COLOR="Blue"]//reset the bool flag at the start of the bar[/COLOR]
                // Condition set 1
                if (CrossAbove(WoodiesCCI(2, 5, 50, 34, 25, 14, 60, 100, 2), 0, 1))
                {
                DrawArrowUp(
                "My up arrow" + CurrentBar, false, 0, Low[0], Color.Lime);
                if (!boolAlertSounded) PlaySound(
                @"C:\Program Files\NinjaTrader 7\sounds\Alert1.wav"); [COLOR="blue"]// only if bool flag is false, play sound[/COLOR]
                SendMail(
                "[email protected]", "[email protected]", "Alert Trade 9 minute chart", "Go long set stop at 30 T1 @20");
                boolAlertSounded = true; [COLOR="blue"]// set the bool flag to stop sound play[/COLOR]
                }

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by algospoke, Today, 06:40 PM
                0 responses
                9 views
                0 likes
                Last Post algospoke  
                Started by maybeimnotrader, Today, 05:46 PM
                0 responses
                7 views
                0 likes
                Last Post maybeimnotrader  
                Started by quantismo, Today, 05:13 PM
                0 responses
                7 views
                0 likes
                Last Post quantismo  
                Started by AttiM, 02-14-2024, 05:20 PM
                8 responses
                168 views
                0 likes
                Last Post jeronymite  
                Started by cre8able, Today, 04:22 PM
                0 responses
                9 views
                0 likes
                Last Post cre8able  
                Working...
                X