Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

alert on Highest High in 7 bars

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

    alert on Highest High in 7 bars

    when i try this code, it seems to print at every bar instead of the highest bar range in 7
    not sure why
    Code:
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        /// <summary>
        /// Enter the description of your strategy here
        /// </summary>
        [Description("Enter the description of your strategy here")]
        public class HH7Alert : Strategy
        {
            #region Variables
            // Wizard generated variables
              private int period1 = 7; // Default setting for Period
                private int barcounter = 0;
                
            // User defined variables (add any user defined variables below)
            private WinTrace myWinTrace ;
            #endregion
    
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
                CalculateOnBarClose = true;
                
                    myWinTrace = new WinTrace ("MyWINID", "My trace window");
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            /// 
            
            
            protected override void OnBarUpdate()
            {
                   // Do not calculate if we don't have enough bars 
                if (CurrentBar < period1) return;
                 if (FirstTickOfBar)
                    barcounter++;
                // Get a sum of prices over the specified period 
                double sum = 0; 
                
                int hh7bar = 0;
        
                // loop for HH7
                for (int barsAgo = 0; barsAgo < period1; barsAgo++) 
                { 
                    if ( Range()[barsAgo] >= Range()[0] )
                    {
                        hh7bar = barsAgo;
                    }
                }
                
    
                
                // HH7  plotting
                if (hh7bar==0)
                {
                    //DrawDot("HH7"+barcounter.ToString(), true, 0, Low[0] - (4*TickSize), Color.DarkRed);
                    //BackColor = nr7color;
                    //send alert to me
                    
                    
                    
                    Print("HH7" + Instrument.FullName,        "HH7" + hh7bar.ToString());
                }
                
                
            }
    
     
        }

    #2
    Hi rakeshSharma, welcome to our support forums! Not sure I follow - are you looking for the highest high over the last 7 bars or the highest bar range over the last 7 bars? For both it may be easier to work directly with the MAX method - http://www.ninjatrader-support.com/H...aximumMAX.html

    Comment


      #3
      i am trying to check if the current bar range > max range in last 7 bars. if so, i want to print it.

      Comment


        #4
        If you want the max range you should just use MAX(Range, 7)[0].

        if (Range()[0] >= MAX(Range, 7)[0])

        Note that MAX(Range, 7)[0] is inclusive of Range()[0]. If you actually want the 7 prior bars you need to change it to MAX(Range, 7)[1].
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          hmmm. i modified the code but the print is not alerting that i have hh7. pl let me know if i am doing something wrong.
          Code:
           protected override void OnBarUpdate()
                  {
                         // Do not calculate if we don't have enough bars 
                      if (CurrentBar < period1) return;
                       
                      myWinTrace.Debug.Send("outside checking" );
                      
                      // HH7  plotting
                      if (Range()[0] >= MAX(Range(), 7)[1])
                      {
                          
                          myWinTrace.Debug.Send("inside checking" );
                      
                          //DrawDot("HH7"+barcounter.ToString(), true, 0, Low[0] - (4*TickSize), Color.DarkRed);
                          //BackColor = nr7color;
                          //send alert to me
                          
                          //myWinTrace.Debug.Send ("HH7" + Instrument.FullName +        "HH7"  +  "max range so far " +  MAX(Range(), 7)[1] + "current range " +Range()[0]  );
                          Print("HH7" + Instrument.FullName +        "HH7"  +  "max range so far " +  MAX(Range(), 7)[1] + "current range " +Range()[0]  );
                      }
                      
                      
                  }

          Comment


            #6
            Check your Control Center for errors. Do you see any?
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              no errors in my control panel

              Comment


                #8
                What behavior are you seeing currently then? What are your print outputs printing?
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  i am running my strategy on NQ -06-09 with IB on 1 minute bars. i can definitely see HH7 bars flying regularly. but there is nothing on my output window. definitely strange and thats why i am stuck.

                  Comment


                    #10
                    Print these components individually:
                    if (Range()[0] >= MAX(Range(), 7)[1])

                    So you can evaluate the if-statement.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      i was using the strategy on control center. i had added the strategy and hit the start button to run it. when i made changes to the strategy. i compiled and stopeed and restarted the stratgegy. it did not take effect unless i delete the strategy from the strategies tab and readded them.

                      Comment


                        #12
                        That is correct. You need to load a new instance of the strategy.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          if i close NT and restart it, would it automatically get the newer code that was compiled or do i have to remove and add again?

                          Comment


                            #14
                            If you close NT it will already be removed so you would be loading a new version anyways.
                            Josh P.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by argusthome, 03-08-2026, 10:06 AM
                            0 responses
                            77 views
                            0 likes
                            Last Post argusthome  
                            Started by NabilKhattabi, 03-06-2026, 11:18 AM
                            0 responses
                            45 views
                            0 likes
                            Last Post NabilKhattabi  
                            Started by Deep42, 03-06-2026, 12:28 AM
                            0 responses
                            27 views
                            0 likes
                            Last Post Deep42
                            by Deep42
                             
                            Started by TheRealMorford, 03-05-2026, 06:15 PM
                            0 responses
                            32 views
                            0 likes
                            Last Post TheRealMorford  
                            Started by Mindset, 02-28-2026, 06:16 AM
                            0 responses
                            63 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Working...
                            X