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

Reading a horizontal line "Y" value

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

    Reading a horizontal line "Y" value

    How do code getting the "Y" value from a horizontal line that I manually draw on a chart and I rename the tag to "test"?

    #2
    Hello Drummer,
    Please use this code to get the Y value.

    Code:
    foreach(IDrawObject o in DrawObjects)
    {
    	if (o.UserDrawn)
    	{
    		if (o.DrawType == DrawType.HorizontalLine)
    		{
    			IHorizontalLine hLine = (IHorizontalLine)o;
    			Print(hLine.Y);
    						
    		}
    	}
    }
    Unfortunately you cannot rename the tag name programmatically but you can change the same manually from the Horizontal line properties dialog (double click on the horizontal line, in the data tab, change the tag name).

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thank you. The code works great and prints the "Y" value for all horizontal lines on my chart. However, I want the Y value for only the horizontal line that I have manually tagged as "test" using the properties dialog box.

      Comment


        #4
        Hello Drummer,
        You can further filter the same as
        Code:
        If (hLine.Tag == “test”)
        {
        	//do something
        }
        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Thanks that did it. For further help to others I discovered the StartsWith method works well too.
          ex.
          if (o.DrawType == DrawType.HorizontalLine && o.Tag.StartsWith("test"))

          then you can process for "test1" "test2" etc

          Comment


            #6
            Hello Drummer,
            Glad it works fine.

            Please let me know if I can assist you any further.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Useful code

              Nice - but tell me... is it possible to get the bar time for the start of the line as well?

              Comment


                #8
                Hello Mindset,
                Thanks for writing in and I am happy to assist you.

                A Horizontal Line do not have a X axis. To get the X axis use a ILine.

                Please let me know if I can assist you any further.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  Doh

                  Sorry I realised my mistake too late. I meant if it's a vertical line?

                  Comment


                    #10
                    Hello Mindset,
                    Please use the BarsAgo or Time property for the Vertical line

                    Code:
                    IVerticalLine vLine = (IVerticalLine)o;
                    Print(vLine.BarsAgo);
                    Print(vLine.Time);
                    Please let me know if I can assist you any further.
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      Iray

                      Hi Joydeep, I am having a similar problem with Iray and would be grateful for some help. When I use horizontal line it works ok but Iray doesn't work (I have commented out the horizontal line code). I have attached the error message when compiling. I can't find anything in the manual examples about it.

                      Thanks in advance
                      DJ

                      PHP Code:

                          
                      public class djdeltastrategy Strategy
                          
                      {
                              
                      #region Variables
                              // Wizard generated variables
                              
                      private int myInput0 1// Default setting for MyInput0
                              
                      private double             lineTargetDR1A =0;
                              private 
                      bool            showtargetoneDR1A      true;
                              private 
                      double          targetoneDR1A                0;
                              
                              
                      #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()
                              {
                                  
                              
                      //    IHorizontalLine    alertLineDR1A    = null;
                              //    IDrawObject        drawAlertLineDR1A    = DrawObjects["DR1A"];
                              //    if (drawAlertLineDR1A != null && drawAlertLineDR1A.DrawType == DrawType.HorizontalLine)
                              //    alertLineDR1A = (drawAlertLineDR1A as IHorizontalLine);

                              //    lineTargetDR1A = showtargetoneDR1A ? Instrument.MasterInstrument.Round2TickSize(alertLineDR1A.Y) : targetoneDR1A;            
                              //    DrawText("tag22", false,"D1", -2,lineTargetDR1A-3*TickSize, 0,Color.White,new Font("Arial", 8, FontStyle.Bold),StringAlignment.Center, Color.Lime, Color.Green, 5);                
                              //    alertLineDR1A.Pen.Color = Color.Red;
                              //    alertLineDR1A.Pen.Width = 5;
                              //    alertLineDR1A.Pen.DashStyle = DashStyle.Dot;
                                  
                                  
                                  
                                  
                      IRay    alertLineDR1A    null;
                                  
                      IDrawObject        drawAlertLineDR1A    DrawObjects["DR1A"];
                                  if (
                      drawAlertLineDR1A != null && drawAlertLineDR1A.DrawType == DrawType.Ray)
                                  
                      alertLineDR1A = (drawAlertLineDR1A as IRay);

                                  
                      lineTargetDR1A showtargetoneDR1A Instrument.MasterInstrument.Round2TickSize(alertLineDR1A.Y) : targetoneDR1A;            
                                  
                      DrawText("tag22"false,"D1", -2,lineTargetDR1A-3*TickSize0,Color.White,new Font("Arial"8FontStyle.Bold),StringAlignment.CenterColor.LimeColor.Green5);                
                                  
                      alertLineDR1A.Pen.Color Color.Red;
                                  
                      alertLineDR1A.Pen.Width 5;
                                  
                      alertLineDR1A.Pen.DashStyle DashStyle.Dot;
                                  
                                  
                                  
                                  
                                  
                                  
                              }

                              
                      #region Properties
                              
                      [Description("")]
                              [
                      GridCategory("Parameters")]
                              public 
                      int MyInput0
                              
                      {
                                  
                      get { return myInput0; }
                                  
                      set myInput0 Math.Max(1value); }
                              }
                              
                      #endregion
                          
                      }

                      Attached Files

                      Comment


                        #12
                        Iray

                        Joydeep, please let me add some more detail to this. I've attached another chart where you can see magenta dotted lines at the bottom. What I'm actually trying to do here is draw a line from one point that goes to the right and doesn't stop. I don't want it to draw a horizontal line.

                        A line doesn't work using F2 doesn't work because it stops as the chart time moves.

                        The extended line using F4 would be the best but that doesn't work because it seems to draw like a horizontal line having a left and a right. I only want the line to go right from where I start it.

                        The ray was the only thing that let me go right but now I realize that probably isn't the right thing either because I want to access the Y value which means I have to keep it dead straight when drawing it.

                        Alternatively I could manually draw a line using F2 then once it's redraw automatically so it goes to the far right. In any case it looks like I need to access two lots of Y values start and finish whereas the horizontal line is only one Y value.


                        Any ideas on this one?
                        Thanks
                        DJ
                        Attached Files
                        Last edited by djkiwi; 03-16-2012, 03:09 PM.

                        Comment


                          #13
                          Hello DJ,
                          Thanks for writing in and I am happy to assist you.

                          An IRay do not have a Y value. its either Anchor1Y or Anchor2Y

                          So please modify the code as per

                          Code:
                          lineTargetDR1A = showtargetoneDR1A ? Instrument.MasterInstrument.Round2TickSize(alertLineDR1A.[B][COLOR="Green"]Anchor1Y[/COLOR][/B]) : targetoneDR1A;

                          Please let me know if I can assist you any further.
                          JoydeepNinjaTrader Customer Service

                          Comment


                            #14
                            IRAY Anchor

                            Thanks Joydeep, that worked perfectly. The only problem now is I'm trying to get the Y value out as follows
                            DrawTextFixed("uptick",(lineTargetDR1A.Anchor1Y).T oString("N0"), trPosition,Color.White,textFontMed, Color.White, Color.Green, 10);
                            :

                            Could you please advise the correct syntax for this one?

                            Thanks
                            DJ

                            Comment


                              #15
                              Hello djkiwi,
                              Please try the below snippet.

                              Code:
                              DrawTextFixed("uptick", lineTargetDR1A.Anchor1Y.ToString("N0"), trPosition,Color.White, textFontMed, Color.White, Color.Green, 10);
                              Please let me know if I can assist you any further.
                              JoydeepNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by usazencort, Today, 01:16 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post usazencort  
                              Started by kaywai, 09-01-2023, 08:44 PM
                              5 responses
                              602 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              6 responses
                              22 views
                              0 likes
                              Last Post xiinteractive  
                              Started by Pattontje, Yesterday, 02:10 PM
                              2 responses
                              20 views
                              0 likes
                              Last Post Pattontje  
                              Started by flybuzz, 04-21-2024, 04:07 PM
                              17 responses
                              230 views
                              0 likes
                              Last Post TradingLoss  
                              Working...
                              X