• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reference manually drawn trendline

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

    Reference manually drawn trendline

    If I manually draw a trendline on a chart, is there a way to reference that trendline within a strategy?

    #2
    Originally posted by dukeb View Post
    If I manually draw a trendline on a chart, is there a way to reference that trendline within a strategy?
    These guys were able to do it:

    http://www.youtube.com/watch?v=1USSIBInAnw

    Comment


      #3
      Originally posted by dukeb View Post
      If I manually draw a trendline on a chart, is there a way to reference that trendline within a strategy?

      This guy here was looping through the ChartObjects to find where manually drawn horizontal lines were placed out.

      http://www.ninjatrader.com/support/f...ad.php?t=51642

      This may or may not pick up trendlines. But it is something worth checking out.

      Comment


        #4
        Thank you, Sledge...

        I really appreciate your help. It gets me on the right path.
        Duke

        Comment


          #5
          DrawObject

          This is right out of reference

          foreach (IDrawObject draw in DrawObjects)
          {
          if (draw is ILine)
          {
          ILine drawnLine = (ILine) draw;

          Print("Line Object: " + draw.Tag + " Manually Drawn: " + draw.UserDrawn);

          }

          }
          I loaded a new chart then loaded this indicator and placed a couple of manually drawn trendlines on the chart.
          1) The lines appear to be indexed (0,1 etc)
          2) There is a large quantity of output. Is this because this is on a tic basis and not bars?
          3) What is the purpose of the red code?
          I get the same output with or without this code.
          4) Very important. I can't seem to get a price value for various points on the trendline.
          How is this done?

          Thank you...
          Duke

          Comment


            #6
            That's going to take some serious math to compute lines that aren't straight.


            Originally posted by dukeb View Post
            This is right out of reference

            foreach (IDrawObject draw in DrawObjects)
            {
            if (draw is ILine)
            {
            ILine drawnLine = (ILine) draw;

            Print("Line Object: " + draw.Tag + " Manually Drawn: " + draw.UserDrawn);

            }

            }
            I loaded a new chart then loaded this indicator and placed a couple of manually drawn trendlines on the chart.
            1) The lines appear to be indexed (0,1 etc)
            2) There is a large quantity of output. Is this because this is on a tic basis and not bars?
            3) What is the purpose of the red code?
            I get the same output with or without this code.
            4) Very important. I can't seem to get a price value for various points on the trendline.
            How is this done?

            Thank you...
            Duke

            Comment


              #7
              Thankfully it's already handled.

              I hacked up the PKPriceAlert2.

              The usage of "Value" was incorrect in the post I referenced earlier. I'm sure I compiled that on my desktop at some point, but I can't find it. Wait - that was in NT 6.5. Now I remember.

              I unknowingly upgraded this to NT7 version.

              Be sure to check out the entire Print Statement to see what is available to you at each Y.


              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()
                      {
                          
                            if (CurrentBar < 1)
                              return;
              
                      
                          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.ILine )     
                              {    
                                  ChartObjectArrayList.Add(CO);
                              }
                          }
                              
                                  
                          foreach(ChartObject CO in ChartObjectArrayList) 
                          {
                                
                              double PriceAlert = Math.Round(CO.Y,4);
                                  
                                   
                              Print(CO.ToString() + " Horizontal Line Value= " + CO.Y  +  "  PriceAlert=" + PriceAlert ); 
              
                          }            
                              
                       
                           
                      }
              
                      #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)
                      {
                          if (cachePKPriceAlert2 != null)
                              for (int idx = 0; idx < cachePKPriceAlert2.Length; idx++)
                                  if (cachePKPriceAlert2[idx].Uptrend == uptrend && cachePKPriceAlert2[idx].EqualsInput(input))
                                      return cachePKPriceAlert2[idx];
              
                          lock (checkPKPriceAlert2)
                          {
                              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;
              #if NT7
                              indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                              indicator.MaximumBarsLookBack = MaximumBarsLookBack;
              #endif
                              indicator.Input = input;
                              indicator.Uptrend = uptrend;
                              Indicators.Add(indicator);
                              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;
                              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
              Originally posted by dukeb View Post


              Thank you...
              Duke
              HTML Code:
              Name='Line' Time='8/8/2012 8:30:00 AM', StartBar='9108' StartY='1392.18' EndTime='8/8/2012 9:00:00 AM' EndBar='9138' EndY='1391.02' Horizontal Line Value= 1392.18252381616  PriceAlert=1392.1825
              Name='Line' Time='8/8/2012 8:31:00 AM', StartBar='9109' StartY='1390.85' EndTime='8/8/2012 9:00:00 AM' EndBar='9138' EndY='1392.31' Horizontal Line Value= 1390.85000933148  PriceAlert=1390.85
              Name='Line' Time='8/8/2012 8:30:00 AM', StartBar='9108' StartY='1392.18' EndTime='8/8/2012 9:00:00 AM' EndBar='9138' EndY='1391.02' Horizontal Line Value= 1392.18252381616  PriceAlert=1392.1825
              Name='Line' Time='8/8/2012 8:31:00 AM', StartBar='9109' StartY='1390.85' EndTime='8/8/2012 9:00:00 AM' EndBar='9138' EndY='1392.31' Horizontal Line Value= 1390.85000933148  PriceAlert=1390.85


              Last edited by sledge; 09-02-2012, 10:45 AM. Reason: added output of 2 drawn lines

              Comment


                #8
                I will check it out... I will let you know.
                I did see the Y as a parameter but did not relate it to value.
                Thanks again..

                Comment


                  #9
                  Ooops, that's not working like i expected.

                  I'm not seeing the value of the line at a current bar after I went 6 more bars into the future.

                  Comment


                    #10
                    Originally posted by sledge View Post
                    Ooops, that's not working like i expected.

                    I'm not seeing the value of the line at a current bar after I went 6 more bars into the future.
                    Unreal, I'm not sure why we don't have access to a guesstimation of a object on a chart at a bar.

                    Comment


                      #11
                      Originally posted by dukeb View Post
                      I will check it out... I will let you know.
                      I did see the Y as a parameter but did not relate it to value.
                      Thanks again..
                      Hey - I've worked out the math in a spreadsheet.

                      I'll work it into the sample.

                      Comment


                        #12
                        Manually Drawn Lines

                        Originally posted by sledge View Post
                        Ooops, that's not working like i expected.

                        I'm not seeing the value of the line at a current bar after I went 6 more bars into the future.
                        Yes, I noticed that too....I will keep plugging away.
                        I will keep you posted..

                        Comment


                          #13
                          Originally posted by dukeb View Post
                          Yes, I noticed that too....I will keep plugging away.
                          I will keep you posted..
                          Let me know how it works.

                          Comment


                            #14
                            You may be able to get some ideas from this indicator:
                            http://www.ninjatrader.com/support/f...d=4&linkid=472
                            Ryan MNinjaTrader Customer Service

                            Comment


                              #15
                              Thank you

                              Ryan,
                              Thank you very much. I will check this out.
                              Duke

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cocopod, Today, 05:32 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post cocopod
                              by cocopod
                               
                              Started by Leeroy_Jenkins, Today, 03:52 AM
                              2 responses
                              13 views
                              0 likes
                              Last Post Leeroy_Jenkins  
                              Started by Leope, Today, 03:15 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_ChrisSch  
                              Started by Frook1951, Today, 03:09 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post Frook1951  
                              Started by unlobotrader, Today, 02:46 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post unlobotrader  
                              Working...
                              X