Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Entry at specific level

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

    #16
    Originally posted by NinjaTrader_JC View Post
    Hello arroganzmaschine,

    You would not want to change the "LineAlert" Script but you may use its logic. For example:

    Code:
    protected override void OnBarUpdate()
            {
    			foreach (NinjaTrader.Gui.Chart.IDrawObject draw in DrawObjects)
    			{
    				if (draw.UserDrawn &&
    					(draw.DrawType == NinjaTrader.Gui.Chart.DrawType.Line ))
    				{	
    					//Sets some line properties programatically
    					NinjaTrader.Gui.Chart.ILine globalLine = (NinjaTrader.Gui.Chart.ILine) draw;
    					
    					//Print out that NinjaTrader was able to get the line and the price.
    					Print("It works " +globalLine.EndY);
    				}
    			}
            }
    Do you know what I mean with the previous Post?

    Comment


      #17
      Hello arroganzmaschine,

      Yes, I believe I do know what you mean in your previous post. You want to see if the Close price has crossed above your line that you have drawn meaning that it was below the value before for a long position.

      Working from the examples that we have shared in the thread this would be an example of this.

      Code:
      if( CrossAbove(Close, globalLine.EndY, 1))
      {
      	EnterLong(1, "");  
      }
      JCNinjaTrader Customer Service

      Comment


        #18
        Originally posted by NinjaTrader_JC View Post
        Hello arroganzmaschine,

        Yes, I believe I do know what you mean in your previous post. You want to see if the Close price has crossed above your line that you have drawn meaning that it was below the value before for a long position.

        Working from the examples that we have shared in the thread this would be an example of this.

        Code:
        if( CrossAbove(Close, globalLine.EndY, 1))
        {
        	EnterLong(1, "");  
        }
        Thank you! I will try it.

        Comment


          #19
          Ok, I tried to paste the code with the line alert into an own Strategy, but when it crosses a line, nothing happens. Do you know why? Just pasted your 8 lines into the OnBarUpdate();

          Comment


            #20
            Hello arroganzmaschine,

            Not sure, can you make sure that the Strategy is enabled?

            Also, do you see any error inside of the Log tab of the Control Center Window?
            JCNinjaTrader Customer Service

            Comment


              #21
              Originally posted by NinjaTrader_JC View Post
              Hello arroganzmaschine,

              Not sure, can you make sure that the Strategy is enabled?

              Also, do you see any error inside of the Log tab of the Control Center Window?
              Strategy is enabled within the chart. I only made a new strategy and pasted your code of "OnBarUpdate()". Then I started it and inserted a horizontal line. But when it crosses the line, nothing happens.

              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.Indicator;
              using NinjaTrader.Gui.Chart;
              using NinjaTrader.Strategy;
              #endregion
              
              // This namespace holds all strategies and is required. Do not change it.
              namespace NinjaTrader.Strategy
              {
                  /// <summary>
                  /// 
                  /// </summary>
                  [Description("")]
                  public class AlertTest : Strategy
                  {
                      #region Variables
                      // Wizard generated variables
                      private bool coolness = true; // Default setting for Coolness
                      // 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>
                      protected override void Initialize()
                      {
                          CalculateOnBarClose = true;
                      }
              
                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
                          foreach (NinjaTrader.Gui.Chart.IDrawObject draw in DrawObjects)
                          {
                              if (draw.UserDrawn &&
                                  (draw.DrawType == NinjaTrader.Gui.Chart.DrawType.Line ))
                              {    
                                  //Sets some line properties programatically
                                  NinjaTrader.Gui.Chart.ILine globalLine = (NinjaTrader.Gui.Chart.ILine) draw;
                                  
                                  //Print out that NinjaTrader was able to get the line and the price.
                                  Print("It works " +globalLine.EndY);
                              }
                          }
                          
                          EnterShort(DefaultQuantity, "");
                          //EnterLong(DefaultQuantity, "");
                      
                      }
              
                      #region Properties
                      [Description("")]
                      [GridCategory("Parameters")]
                      public bool Coolness
                      {
                          get { return coolness; }
                          set { coolness = value; }
                      }
                      #endregion
                  }
              }
              Last edited by arroganzmaschine; 02-07-2014, 09:14 AM.

              Comment


                #22
                Hello arroganzmaschine,

                You have "EnterShort(DefaultQuantity, "");" in OnBarUpdate() without any conditions which means that it is going to be triggered every bar.

                You will want to place it inside of the condition where you are getting your line drawn at, so this would be inside of the "foreach" loop and inside of the "if(draw.UserDrawn && ...) and then you will want to define your Cross condition.

                Code:
                   protected override void OnBarUpdate()
                        {
                            foreach (NinjaTrader.Gui.Chart.IDrawObject draw in DrawObjects)
                            {
                                if (draw.UserDrawn &&
                                    (draw.DrawType == NinjaTrader.Gui.Chart.DrawType.Line ))
                                {    
                                    //Sets some line properties programatically
                                    NinjaTrader.Gui.Chart.ILine globalLine = (NinjaTrader.Gui.Chart.ILine) draw;
                                    
                                    //Print out that NinjaTrader was able to get the line and the price.
                                    Print("It works " +globalLine.EndY);
                					if( CrossBelow(Close, globalLine.EndY, 1))
                					{
                						EnterShort(DefaultQuantity, "");
                					}
                                }
                            }       
                        }
                JCNinjaTrader Customer Service

                Comment


                  #23
                  Originally posted by NinjaTrader_JC View Post
                  Hello arroganzmaschine,

                  You have "EnterShort(DefaultQuantity, "");" in OnBarUpdate() without any conditions which means that it is going to be triggered every bar.

                  You will want to place it inside of the condition where you are getting your line drawn at, so this would be inside of the "foreach" loop and inside of the "if(draw.UserDrawn && ...) and then you will want to define your Cross condition.

                  Code:
                     protected override void OnBarUpdate()
                          {
                              foreach (NinjaTrader.Gui.Chart.IDrawObject draw in DrawObjects)
                              {
                                  if (draw.UserDrawn &&
                                      (draw.DrawType == NinjaTrader.Gui.Chart.DrawType.Line ))
                                  {    
                                      //Sets some line properties programatically
                                      NinjaTrader.Gui.Chart.ILine globalLine = (NinjaTrader.Gui.Chart.ILine) draw;
                                      
                                      //Print out that NinjaTrader was able to get the line and the price.
                                      Print("It works " +globalLine.EndY);
                                      if( CrossBelow(Close, globalLine.EndY, 1))
                                      {
                                          EnterShort(DefaultQuantity, "");
                                      }
                                  }
                              }       
                          }
                  Thank you! Can I add an ATM strategy to the script?

                  EDIT: I imported the original LineAlert-Indicator and attached it to a simulted data feed chart. The line I draw has turned red, but there was no message that the line was crossed. What do I do wrong?
                  Last edited by arroganzmaschine; 02-07-2014, 12:26 PM.

                  Comment


                    #24
                    In addition: Here is my modified code. When I draw a line and the price crosses it, nothing happens.
                    The strategy is also "Enabled" under the strategys folder.

                    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.Indicator;
                    using NinjaTrader.Gui.Chart;
                    using NinjaTrader.Strategy;
                    #endregion
                    
                    // This namespace holds all strategies and is required. Do not change it.
                    namespace NinjaTrader.Strategy
                    {
                        /// <summary>
                        /// 
                        /// </summary>
                        [Description("")]
                        public class AlertTest : Strategy
                        {
                            #region Variables
                            // Wizard generated variables
                            private bool coolness = true; // Default setting for Coolness
                            // 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>
                            protected override void Initialize()
                            {
                                CalculateOnBarClose = true;
                            }
                    
                            /// <summary>
                            /// Called on each bar update event (incoming tick)
                            /// </summary>
                            protected override void OnBarUpdate()
                            {
                                foreach (NinjaTrader.Gui.Chart.IDrawObject draw in DrawObjects)
                                {
                                    if (draw.UserDrawn &&
                                        (draw.DrawType == NinjaTrader.Gui.Chart.DrawType.Line ))
                                    {    
                                        //Sets some line properties programatically
                                        NinjaTrader.Gui.Chart.ILine globalLine = (NinjaTrader.Gui.Chart.ILine) draw;
                                        
                                        //Print out that NinjaTrader was able to get the line and the price.
                                        Print("It works " +globalLine.EndY);
                                        
                                        if( CrossBelow(Close, globalLine.EndY, 1))
                                        {
                                            EnterShort(1, "Short Entry");
                                        } else if( CrossAbove(Close, globalLine.EndY, 1)) {
                                            EnterLong(1, "Long Entry");    
                                        }
                                    }
                                }
                            
                            }
                    
                            #region Properties
                            [Description("")]
                            [GridCategory("Parameters")]
                            public bool Coolness
                            {
                                get { return coolness; }
                                set { coolness = value; }
                            }
                            #endregion
                        }
                    }

                    Comment


                      #25
                      Hello arroganzmaschine,

                      Let make we know how the LineAlert Indicator works first. The LineAlert Indicator will send an Alert meaning that it will play a sound and put an Alert Message in the Alerts window.

                      Can you open up the Alerts window and make sure that it is being sent? The Alerts window can be opened up by going to File -> New -> Alerts.
                      JCNinjaTrader Customer Service

                      Comment


                        #26
                        Ok, thank you. But why does my attached Code not work? why doesnt it Open Ordes.

                        Comment


                          #27
                          Hello arroganzmaschine,

                          What color is the Strategy cell inside of the Strategy tab inside of the Control Center?

                          Also, can you put a Print() statement to verify values are what you expect and to see if your Entry Condition is hit? - Here is an example of how to use the Print() statement.
                          JCNinjaTrader Customer Service

                          Comment


                            #28
                            Ok, I have to try that.

                            Comment


                              #29
                              Originally posted by NinjaTrader_JC View Post
                              Hello arroganzmaschine,

                              What color is the Strategy cell inside of the Strategy tab inside of the Control Center?

                              Also, can you put a Print() statement to verify values are what you expect and to see if your Entry Condition is hit? - Here is an example of how to use the Print() statement.
                              http://www.ninjatrader.com/support/f...ead.php?t=3418

                              Ok, the below attached code works so far.

                              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.Indicator;
                              using NinjaTrader.Gui.Chart;
                              using NinjaTrader.Strategy;
                              #endregion
                              
                              // This namespace holds all strategies and is required. Do not change it.
                              namespace NinjaTrader.Strategy
                              {
                                  /// <summary>
                                  /// Einstieg bei Durchbruch von Linie
                                  /// </summary>
                                  [Description("Einstieg bei Durchbruch von Linie")]
                                  public class CrossEntry : Strategy
                                  {
                                      #region Variables
                                      // Wizard generated variables
                                      private bool activeTrading = true; // Default setting for ActiveTrading
                                      #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;
                                      }
                              
                                      /// <summary>
                                      /// Called on each bar update event (incoming tick)
                                      /// </summary>
                                      protected override void OnBarUpdate()
                                      {
                                          foreach (NinjaTrader.Gui.Chart.IDrawObject draw in DrawObjects)
                                          {
                                              if (draw.UserDrawn &&
                                                  (draw.DrawType == NinjaTrader.Gui.Chart.DrawType.HorizontalLine ))
                                              {    
                                                  //Sets some line properties programatically
                                                  NinjaTrader.Gui.Chart.ILine globalLine = (NinjaTrader.Gui.Chart.ILine) draw;
                                                  
                                                  //Print out that NinjaTrader was able to get the line and the price.
                                                  Print("It works " +globalLine.EndY);
                                                  
                                                  if(CrossBelow(Close, globalLine.EndY, 1) || CrossAbove(Close, globalLine.EndY, 1))
                                                  {
                                                          EnterLong(1, "Entry Long");
                                                  }
                                              }
                                          }
                                          //EnterLong(1, "Entry Long");
                                          //EnterShort(1, "Entry Short");
                                      }
                              
                                      #region Properties
                                      [Description("Aktives Entry-Handling")]
                                      [GridCategory("Parameters")]
                                      public bool ActiveTrading
                                      {
                                          get { return activeTrading; }
                                          set { activeTrading = value; }
                                      }
                                      #endregion
                                  }
                              }

                              BUT, how can I open positions when they currently crossed the line and not when a new bar comes and then opens? It also opens position when I just attached it to the chart. Seems like it goes backwards in the chart and looks at the line crossing.

                              Comment


                                #30
                                Another problem. I pasted the code that worked on one computer to anothers computer strategy. Nothing happens here. The strategy doesn't seem to work. On my other computer, the strategy was yellow and opened every order after it crossed the line. Here, it is green. Can you help me here? Something is not working.

                                Here is a picture of my platform. The code for the strategy is in the previous post. Nothing happens, when it's enabled.

                                Einfach Bilder oder Fotos kostenlos hochladen bei Pic-Upload. Leicht und bequem Bild oder Foto hochladen.


                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by DJ888, Today, 10:57 PM
                                0 responses
                                1 view
                                0 likes
                                Last Post DJ888
                                by DJ888
                                 
                                Started by MacDad, 02-25-2024, 11:48 PM
                                7 responses
                                158 views
                                0 likes
                                Last Post loganjarosz123  
                                Started by Belfortbucks, Today, 09:29 PM
                                0 responses
                                7 views
                                0 likes
                                Last Post Belfortbucks  
                                Started by zstheorist, Today, 07:52 PM
                                0 responses
                                7 views
                                0 likes
                                Last Post zstheorist  
                                Started by pmachiraju, 11-01-2023, 04:46 AM
                                8 responses
                                151 views
                                0 likes
                                Last Post rehmans
                                by rehmans
                                 
                                Working...
                                X