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 Indicator

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

    Alert Indicator

    Hi I am stillusing ninja 6.5 as my data is compatible with ninja 6.5 only
    Please help me with the following alert Indicator

    I am not getting alert signals Arrow as well as the sound

    I don't have Break ceiling and Break Floor sound files so I replaced codes with Alert1 and Alert2 sound files which I have in my sounds folders ,inspite of that I am not getting sound alert .
    HTML Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    using System.Collections;
    using System.Collections.Generic;
    #endregion
    
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        [Description("Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen.")]
        public class PKPriceAlert2 : Indicator
        {
            #region Variables
            // Wizard generated variables
                
    		    private DateTime				startTime;
    		    private bool uptrend = true;
    		private string 	breakFloor	= "BreakFloor.wav"; 	// Price Breaking Down thru horizontal line alert wav file
    		private string 	breakCeiling	= "BreakCeiling.wav"; 	// Price Breaking Up thru horizontal line alert wav file		
    		
    		
            // User defined variables (add any user defined variables below)
            #endregion
    
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
                CalculateOnBarClose	= true;
                Overlay				= true;
                this.startTime			= DateTime.Now;
    			
    			 
    			
    			 
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                
    			try {
    				
    				if (CurrentBar < 1)
    					return;
    				
    			    if (startTime.Ticks > Time[0].Ticks ) 
    					return;
    					
    				//Print("ChartObjectCount= " + this.ChartControl.ChartObjects.Count + " " + Time[0]);
    			    
    				List<ChartObject> ChartObjectArrayList = new List<ChartObject>();
    			    foreach(ChartObject CO in this.ChartControl.ChartObjects) {
    					//Print("ChartObjectType: " + CO.GetType().Name );
    				   	if ( CO is NinjaTrader.Gui.Chart.ChartHorizontalLine) 	{	
    						//Print("Horizontal Line Value= " + CO.Value);
    				   		ChartObjectArrayList.Add(CO);
    					}
    				}
    				
    				//Print("HorizontalLineCount= " + ChartObjectArrayList.Count );
    					
    			    foreach(ChartObject CO in ChartObjectArrayList) {
    				  
    					double PriceAlert = Math.Round(CO.Value,4);
    					
    					 
    					//Print("Horizontal Line Value= " + CO.Value);
    					
    					if ( (this.uptrend == false) &&
    						 (Close[0] < Close[1])   && 
    						 (Close[0] < PriceAlert) &&
    						 (Close[1] > PriceAlert)    ) {
    							 
    							Print("********************PriceAlert DOWN. AlertPrice=" + PriceAlert + " \t Close[0]=" + Close[0] + " \t Close[1]=" + Close[1] + " \t Time[0]=" + Time[0] );
    							//DrawArrowDown("MyArrowDOWN" + CurrentBar , 0,  High[0] + .05 , Color.Blue);	
    							Alert(this.GetType().Name + Instrument.FullName,Priority.High,"Price Alert. Ticker=" + Instrument.FullName + "  Price=" + PriceAlert , breakFloor , 60, Color.Blue,Color.White);
    				            	
    							
    					}
    					
    					if ( (this.uptrend == true) &&
    						 (Close[0] > Close[1])   && 
    						 (Close[0] > PriceAlert) &&
    						 (Close[1] < PriceAlert)    ) {
    						 	
    							Print("********************PriceAlert   UP. AlertPrice=" + PriceAlert + " \t Close[0]=" + Close[0] + " \t Close[1]=" + Close[1] + " \t Time[0]=" + Time[0] );	
    						 	//DrawArrowUp("MyArrowUP" + CurrentBar , 0,  Low[0] - .05 , Color.Blue);	
    							Alert(this.GetType().Name + Instrument.FullName,Priority.High,"Price Alert. Ticker=" + Instrument.FullName + "  Price=" + PriceAlert , breakCeiling , 60, Color.Blue,Color.White);
    							 
    					}
    												
    						
    					 
    				}
     
    				 
    			}
    			catch( Exception e) {
    				Print("EXCEPTION Instrument=" + Instrument +  e.ToString() );
    				 
    				Print(e.Message);
    				 
    				Alert(this.GetType().Name + Instrument.FullName,Priority.High,"Instrument=" + Instrument + "   **************EXCEPTION" + e.ToString(),"C:\\Program Files\\NinjaTrader 6.5\\sounds\\test.wav", 60, Color.Red,Color.White);
    				
    				
    			}			
    				
    		 
    			 
            }
    
            #region Properties
    
            [Description("")]
            [Category("Parameters")]
            public bool Uptrend
            {
                get { return uptrend; }
                set { uptrend = value; }
    		}	
    			[Description("Price Breaking Down thru horizontal line alert wav file")]
            [Category("Alert")]
            public string BreakFloor
            {
                get { return breakFloor; }
                set { breakFloor = value; }
            }	
    		
    		[Description("Price Breaking Down thru horizontal line alert wav file")]
            [Category("Alert")]
            public string BreakCeiling
            {
                get { return breakCeiling; }
                set { breakCeiling = value; }
            }
            #endregion
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
        public partial class Indicator : IndicatorBase
        {
            private PKPriceAlert2[] cachePKPriceAlert2 = null;
    
            private static PKPriceAlert2 checkPKPriceAlert2 = new PKPriceAlert2();
    
            /// <summary>
            /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen.
            /// </summary>
            /// <returns></returns>
            public PKPriceAlert2 PKPriceAlert2(bool uptrend)
            {
                return PKPriceAlert2(Input, uptrend);
            }
    
            /// <summary>
            /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen.
            /// </summary>
            /// <returns></returns>
            public PKPriceAlert2 PKPriceAlert2(Data.IDataSeries input, bool uptrend)
            {
                checkPKPriceAlert2.Uptrend = uptrend;
                uptrend = checkPKPriceAlert2.Uptrend;
    
                if (cachePKPriceAlert2 != null)
                    for (int idx = 0; idx < cachePKPriceAlert2.Length; idx++)
                        if (cachePKPriceAlert2[idx].Uptrend == uptrend && cachePKPriceAlert2[idx].EqualsInput(input))
                            return cachePKPriceAlert2[idx];
    
                PKPriceAlert2 indicator = new PKPriceAlert2();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
                indicator.Input = input;
                indicator.Uptrend = uptrend;
                indicator.SetUp();
    
                PKPriceAlert2[] tmp = new PKPriceAlert2[cachePKPriceAlert2 == null ? 1 : cachePKPriceAlert2.Length + 1];
                if (cachePKPriceAlert2 != null)
                    cachePKPriceAlert2.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cachePKPriceAlert2 = tmp;
                Indicators.Add(indicator);
    
                return indicator;
            }
    
        }
    }
    
    // This namespace holds all market analyzer column definitions and is required. Do not change it.
    namespace NinjaTrader.MarketAnalyzer
    {
        public partial class Column : ColumnBase
        {
            /// <summary>
            /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen.
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.PKPriceAlert2 PKPriceAlert2(bool uptrend)
            {
                return _indicator.PKPriceAlert2(Input, uptrend);
            }
    
            /// <summary>
            /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen.
            /// </summary>
            /// <returns></returns>
            public Indicator.PKPriceAlert2 PKPriceAlert2(Data.IDataSeries input, bool uptrend)
            {
                return _indicator.PKPriceAlert2(input, uptrend);
            }
    
        }
    }
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        public partial class Strategy : StrategyBase
        {
            /// <summary>
            /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen.
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.PKPriceAlert2 PKPriceAlert2(bool uptrend)
            {
                return _indicator.PKPriceAlert2(Input, uptrend);
            }
    
            /// <summary>
            /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen.
            /// </summary>
            /// <returns></returns>
            public Indicator.PKPriceAlert2 PKPriceAlert2(Data.IDataSeries input, bool uptrend)
            {
                if (InInitialize && input == null)
                    throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
    
                return _indicator.PKPriceAlert2(input, uptrend);
            }
    
        }
    }
    #endregion

    #2
    I did a quick sample in my NT 6.5 of just an indicator that calculate on bar close = true and does the sample alert in the help file.

    It plays a sound rather harshly, and then it looks like no more bars are generated,and I don't see any alert.

    So - I'm getting sound for Alert1.wav.

    You are probably seeing your Print statements in the output window?

    Can you change your alert statement to the exact thing in the NT 6.5 help file and start from there?

    I'll download your code later and try it out.

    Originally posted by SLASH View Post
    Hi I am stillusing ninja 6.5 as my data is compatible with ninja 6.5 only
    Please help me with the following alert Indicator

    I am not getting alert signals Arrow as well as the sound

    I don't have Break ceiling and Break Floor sound files so I replaced codes with Alert1 and Alert2 sound files which I have in my sounds folders ,inspite of that I am not getting sound alert .
    HTML Code:
    
    

    Comment


      #3
      This statement looks to be always TRUE

      if (startTime.Ticks > Time[0].Ticks ) return;

      Comment


        #4
        cool

        Code:
        
        #region Using declarations
        using System;
        using System.ComponentModel;
        using System.Diagnostics;
        using System.Drawing;
        using System.Drawing.Drawing2D;
        using System.Xml.Serialization;
        using NinjaTrader.Cbi;
        using NinjaTrader.Data;
        using NinjaTrader.Gui.Chart;
        using System.Collections;
        using System.Collections.Generic;
        #endregion
        
        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator
        {
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            [Description("Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen.")]
            public class PKPriceAlert2 : Indicator
            {
                #region Variables
                // Wizard generated variables
                    
                    private DateTime                startTime;
                    private bool uptrend = false;
                private string     breakFloor    = "Alert1.wav";     // Price Breaking Down thru horizontal line alert wav file
                private string     breakCeiling    = "Alert1.wav";     // Price Breaking Up thru horizontal line alert wav file        
                
                
                // User defined variables (add any user defined variables below)
                #endregion
        
                /// <summary>
                /// This method is used to configure the indicator and is called once before any bar data is loaded.
                /// </summary>
                protected override void Initialize()
                {
                    CalculateOnBarClose    = true;
                    Overlay                = true;
                    this.startTime            = DateTime.Now;
                    
                     
                    
                     
                }
        
                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                protected override void OnBarUpdate()
                {
                    
                    try {
              if (CurrentBar < 1)
                            return;
                        //Print ( "Is " + startTime.Ticks+ "<" +Time[0].Ticks +" ?" );
                        
                        if (startTime.Ticks < Time[0].Ticks ) 
                            return;
        
                        List<ChartObject> ChartObjectArrayList = new List<ChartObject>();
                        foreach(ChartObject CO in this.ChartControl.ChartObjects) {
                               if ( CO is NinjaTrader.Gui.Chart.ChartHorizontalLine)     {    
                                    ChartObjectArrayList.Add(CO);
                            }
                        }
                        
                            
                        foreach(ChartObject CO in ChartObjectArrayList) {
                          
                            double PriceAlert = Math.Round(CO.Value,4);
                            
                             
                            //Print("Horizontal Line Value= " + CO.Value +  "PriceAlert=" + PriceAlert );
                            
        
                            if 
                                 (Close[0] < Close[1])   && 
                                 (Close[0] < PriceAlert) &&
                                 (Close[1] > PriceAlert)    ) {
                                     
                                    Print("********************PriceAlert DOWN. AlertPrice=" + PriceAlert + " \t Close[0]=" + Close[0] + " \t Close[1]=" + Close[1] + " \t Time[0]=" + Time[0] );
                                    //DrawArrowDown("MyArrowDOWN" + CurrentBar , 0,  High[0] + .05 , Color.Blue);    
                                    Alert(this.GetType().Name + Instrument.FullName,Priority.High,"Price Alert. Ticker=" + Instrument.FullName + "  Price=" + PriceAlert , breakFloor , 60, Color.Blue,Color.White);
                                        
                                    
                            }
                            
                            if ( //(this.uptrend == true) &&
                                 (Close[0] > Close[1])   && 
                                 (Close[0] > PriceAlert) &&
                                 (Close[1] < PriceAlert)    ) {
                                     
                                    Print("********************PriceAlert   UP. AlertPrice=" + PriceAlert + " \t Close[0]=" + Close[0] + " \t Close[1]=" + Close[1] + " \t Time[0]=" + Time[0] );    
                                     //DrawArrowUp("MyArrowUP" + CurrentBar , 0,  Low[0] - .05 , Color.Blue);    
                                    Alert(this.GetType().Name + Instrument.FullName,Priority.High,"Price Alert. Ticker=" + Instrument.FullName + "  Price=" + PriceAlert , breakCeiling , 60, Color.Blue,Color.White);
                                     
                            }
                                                        
                                
                             
                        }
         
                         
                    }
                    catch( Exception e) {
                        Print("EXCEPTION Instrument=" + Instrument +  e.ToString() );
                         
                        Print(e.Message);
                         
                        Alert(this.GetType().Name + Instrument.FullName,Priority.High,"Instrument=" + Instrument + "   **************EXCEPTION" + e.ToString(),"C:\\Program Files\\NinjaTrader 6.5\\sounds\\test.wav", 60, Color.Red,Color.White);
                        
                        
                    }            
                        
                 
                     
                }
        
                #region Properties
        
                [Description("")]
                [Category("Parameters")]
                public bool Uptrend
                {
                    get { return uptrend; }
                    set { uptrend = value; }
                }    
                    [Description("Price Breaking Down thru horizontal line alert wav file")]
                [Category("Alert")]
                public string BreakFloor
                {
                    get { return breakFloor; }
                    set { breakFloor = value; }
                }    
                
                [Description("Price Breaking Down thru horizontal line alert wav file")]
                [Category("Alert")]
                public string BreakCeiling
                {
                    get { return breakCeiling; }
                    set { breakCeiling = value; }
                }
                #endregion
            }
        }
        
        #region NinjaScript generated code. Neither change nor remove.
        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator
        {
            public partial class Indicator : IndicatorBase
            {
                private PKPriceAlert2[] cachePKPriceAlert2 = null;
        
                private static PKPriceAlert2 checkPKPriceAlert2 = new PKPriceAlert2();
        
                /// <summary>
                /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen.
                /// </summary>
                /// <returns></returns>
                public PKPriceAlert2 PKPriceAlert2(bool uptrend)
                {
                    return PKPriceAlert2(Input, uptrend);
                }
        
                /// <summary>
                /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen.
                /// </summary>
                /// <returns></returns>
                public PKPriceAlert2 PKPriceAlert2(Data.IDataSeries input, bool uptrend)
                {
                    checkPKPriceAlert2.Uptrend = uptrend;
                    uptrend = checkPKPriceAlert2.Uptrend;
        
                    if (cachePKPriceAlert2 != null)
                        for (int idx = 0; idx < cachePKPriceAlert2.Length; idx++)
                            if (cachePKPriceAlert2[idx].Uptrend == uptrend && cachePKPriceAlert2[idx].EqualsInput(input))
                                return cachePKPriceAlert2[idx];
        
                    PKPriceAlert2 indicator = new PKPriceAlert2();
                    indicator.BarsRequired = BarsRequired;
                    indicator.CalculateOnBarClose = CalculateOnBarClose;
                    indicator.Input = input;
                    indicator.Uptrend = uptrend;
                    indicator.SetUp();
        
                    PKPriceAlert2[] tmp = new PKPriceAlert2[cachePKPriceAlert2 == null ? 1 : cachePKPriceAlert2.Length + 1];
                    if (cachePKPriceAlert2 != null)
                        cachePKPriceAlert2.CopyTo(tmp, 0);
                    tmp[tmp.Length - 1] = indicator;
                    cachePKPriceAlert2 = tmp;
                    Indicators.Add(indicator);
        
                    return indicator;
                }
        
            }
        }
        
        // This namespace holds all market analyzer column definitions and is required. Do not change it.
        namespace NinjaTrader.MarketAnalyzer
        {
            public partial class Column : ColumnBase
            {
                /// <summary>
                /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen.
                /// </summary>
                /// <returns></returns>
                [Gui.Design.WizardCondition("Indicator")]
                public Indicator.PKPriceAlert2 PKPriceAlert2(bool uptrend)
                {
                    return _indicator.PKPriceAlert2(Input, uptrend);
                }
        
                /// <summary>
                /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen.
                /// </summary>
                /// <returns></returns>
                public Indicator.PKPriceAlert2 PKPriceAlert2(Data.IDataSeries input, bool uptrend)
                {
                    return _indicator.PKPriceAlert2(input, uptrend);
                }
        
            }
        }
        
        // This namespace holds all strategies and is required. Do not change it.
        namespace NinjaTrader.Strategy
        {
            public partial class Strategy : StrategyBase
            {
                /// <summary>
                /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen.
                /// </summary>
                /// <returns></returns>
                [Gui.Design.WizardCondition("Indicator")]
                public Indicator.PKPriceAlert2 PKPriceAlert2(bool uptrend)
                {
                    return _indicator.PKPriceAlert2(Input, uptrend);
                }
        
                /// <summary>
                /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen.
                /// </summary>
                /// <returns></returns>
                public Indicator.PKPriceAlert2 PKPriceAlert2(Data.IDataSeries input, bool uptrend)
                {
                    if (InInitialize && input == null)
                        throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
        
                    return _indicator.PKPriceAlert2(input, uptrend);
                }
        
            }
        }
        #endregion

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bmartz, 03-12-2024, 06:12 AM
        3 responses
        26 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by Aviram Y, Today, 05:29 AM
        2 responses
        8 views
        0 likes
        Last Post Aviram Y  
        Started by gentlebenthebear, Today, 01:30 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by cls71, Today, 04:45 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by TradeForge, Today, 02:09 AM
        1 response
        23 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X