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

    #16
    Iray

    Thanks Joydeep, I'm still struggling, I've attached the piece of code and a picture of the error. It looks like I have to define anchor one somewhere, not sure why that would be.


    #region Variables

    private double lineTargetPR3 =0;
    private bool showtargetonePR3 = true;
    private double targetonePR3 = 0;
    //Level 3 resistance

    if (DrawObjects["PR3"] != null && DrawObjects["PR3"].DrawType == DrawType.Ray)
    {
    IRay alertLinePR3 = null;
    IDrawObject drawAlertLinePR3 = DrawObjects["PR3"];
    if (drawAlertLinePR3 != null && drawAlertLinePR3.DrawType == DrawType.Ray)
    alertLinePR3 = (drawAlertLinePR3 as IRay);

    lineTargetPR3 = showtargetonePR3 ? Instrument.MasterInstrument.Round2TickSize(alertLi nePR3.Anchor1Y) : targetonePR3;
    DrawText("tag32", false,"PR3", -10,lineTargetPR3, -10,Color.White,new Font("Arial", 8, FontStyle.Bold),StringAlignment.Center, Color.Plum, Color.Black, 10);
    alertLinePR3.Pen.Color = Color.Plum;
    alertLinePR3.Pen.Width = 5;
    alertLinePR3.Pen.DashStyle = DashStyle.Dot;
    }

    DrawTextFixed("uptick", lineTargetPR3.Anchor1Y.ToString("N0"), trPosition,Color.White, textFontMed, Color.White, Color.Green, 10);


    Cheers
    DJ
    Attached Files

    Comment


      #17
      Hello djkiwi,
      Thanks for the additional info.

      lineTargetPR3 is a double and thus you dont need to assign the Anchor1Y to it. Please use the below code instead.

      Code:
      DrawTextFixed("uptick", lineTargetPR3.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


        #18
        Ray1

        Thanks Joydeep that worked well. I still get quite confused with some of this stuff. I have one more question on it that I was hoping for some guidance. Attached is a chart where I have manually drawn the rays. I am accessing the StartY value so need to make sure it is straight. The problem I'm finding is if I draw a long ray I have to go into the ray properties and then manually change End Y to start Y to make sure it is straight. Ideally what I'd like to do is for EndY to automatically take the value of start Y. I'm ok at changing the color and line width etc after it has been drawn but not sure how to change the Y values.

        Any ideas on this one?

        Thanks in advance
        DJ
        Attached Files

        Comment


          #19
          Hello djkiwi,
          You can programmatically change the start y values.

          Code:
          foreach(IDrawObject o in DrawObjects)
          {
          	if (o.UserDrawn)
          	{
          		if (o.DrawType == DrawType.Ray)
          		{
          			IRay ray = (IRay)o;
          			ray.Anchor1Y = ray.Anchor2Y;
          		}
          	}
          }
          Please let me know if I can assist you any further.
          JoydeepNinjaTrader Customer Service

          Comment


            #20
            Iray

            Hi Joydeep, thanks for that snippet,it works perfectly and am very pleased with it. One thing though I'm not sure about the o eg o.Drawtype etc. What exactly does that do as I cannot see it in the manual anywhere.

            Cheers
            DJ

            Comment


              #21
              Hello djkiwi,
              o is the IDrawObject object which i have declared from the following code

              Code:
              foreach([B]IDrawObject o[/B] in DrawObjects)
              {
                 //rest of codes
              }
              To know more about IDrawObject please refer here http://www.ninjatrader.com/support/h...drawobject.htm

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

              Comment


                #22
                Yvalue line nachoring

                Hi Joydeep. I have another problem with this Yvalue and would appreciate some help. What I'm doing is drawing a line on the chart in the margin (See picture). I have set the margin to 90. The problem with this is it moves as the chart moves (See second picture). What I'm trying to do is anchor the line the margin so it doesn't move. I am using this code which works ok for redrawing colors etc but it doesn't work for the startbarsago and endbarsago. I also looked at drawextendedline but that drew the line to the left and right like horizontal line.

                if (DrawObjects["POC1"] != null)
                {
                ILine alertLine2 = null;
                IDrawObject drawpoc1 = DrawObjects["POC1"];
                if (drawpoc1 != null && drawpoc1.DrawType == DrawType.Line)
                alertLine2 = (drawpoc1 as ILine);

                linePOC1 = showpoc1 ? Instrument.MasterInstrument.Round2TickSize(alertLi ne2.StartY) : poc1;
                alertLine2.Pen.Color = Color.Red;
                alertLine2.Pen.Width = 5;
                alertLine2.Pen.DashStyle = DashStyle.Solid;
                alertLine2.StartBarsAgo = 0;
                alertLine2.EndBarsAgo = -10;
                }

                I thought if I put 0 as start barsago and -10 as endbarsago it shoud draw it ok from the current bar back 10 bars in the margin. I have used this with drawline ok before.

                Any guidance on this one?

                Thanks DJ
                Attached Files

                Comment


                  #23
                  Hello DJ,
                  Unfortunately setting programmatic values of X axis for manually placed drawing objects is not allowed.

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

                  Comment


                    #24
                    You probably need to Plot override and anchor it using
                    graphics.Drawline - and use x,y coords rather than bar nos

                    Comment


                      #25
                      Hi Joydeep, I have a question on how to make the text plot on top of the line instead of underneath the line. For example if you look at the attached chart, you can see the word stop under the red line. I'm trying to put it over the line using this code. I'm not sure why it doesn't work because I'm telling it draw and color the lines and then after that I'm telling it to label the line after the line has been recolored. Any ideas on this one?

                      Thanks in advance
                      DJ


                      PHP Code:
                      //c. StopLine
                                  
                      if (DrawObjects["S1"] != null)
                                  {                
                                  
                      IHorizontalLine    alertLine2    null;
                                  
                      IDrawObject        drawStopline    DrawObjects["S1"];
                                  if (
                      drawStopline != null && drawStopline.DrawType == DrawType.HorizontalLine)
                                  
                      alertLine2 = (drawStopline as IHorizontalLine);
                                  
                      alertLine2.Pen.Color Color.Red;
                                  
                      alertLine2.Pen.Width 5;
                                  
                      alertLine2.Pen.DashStyle DashStyle.Solid;            
                                  
                                  
                                  
                      lineStopline showStopLine Instrument.MasterInstrument.Round2TickSize(alertLine2.Y) : stopline;            
                                  if (
                      Close[0]<lineStopline)
                                  {    
                                  
                      DrawText("tag6"false,"Stop", -10,lineStopline0,Color.White,new Font("Courier"7FontStyle.Bold),StringAlignment.CenterColor.WhiteColor.Red5);                
                                  }
                                  else if (
                      Close[0]>lineStopline)
                                  {    
                                  
                      DrawText("tag6"false,"Stop", -10,lineStopline0,Color.White,new Font("Courier"7FontStyle.Bold),StringAlignment.CenterColor.WhiteColor.Red5);                
                                  }    
                                  
                                  } 
                      Attached Files

                      Comment


                        #26
                        Hello DJ,
                        The line is manually drawn and independent from the indicator.Thus the ZOrder will determine whether the indicator will be on top or the line.

                        Instead, just adjust the text position by changing is position by a tick or two.
                        Code:
                        DrawText("tag6", false,"Stop", -10,lineStopline + [COLOR="Blue"]2 * TickSize[/COLOR], 0,Color.White,new Font("Courier", 7, FontStyle.Bold),StringAlignment.Center, Color.White, Color.Red, 5);
                        Please let me know if I can assist you any further.
                        JoydeepNinjaTrader Customer Service

                        Comment


                          #27
                          Iray

                          Hi Joydeep yes I have bee using that but the problem is when charts are quite different timeframes the writing can be quite far from the bar.

                          In any case I'm trying to find a work around for setting the width of the user drawn line. You mentioned the X value is not accessible using horizontal line. How about if I use an IRay instead and told it to draw the starting bar 5 bars back and end an 0 bars back? Would this redraw the line at every bar so it always started drawing the line 5 bars back? Also how would I do this? I did try this code but nothing changed on the chart. If you notice the red line is still the same width as when it started. Or maybe I could use a date, say keep redrawing the bar from the beginning of the session?

                          The problem I see now is I don't know how to redraw the line using these parameters..

                          ray.Anchor1BarsAgo = 5;
                          ray.Anchor2BarsAgo = 0;


                          Thanks in advance
                          DJ

                          PHP Code:

                                      
                          foreach(IDrawObject o in DrawObjects)
                                      {
                                      if (
                          o.UserDrawn)
                                      {
                                      if (
                          o.DrawType == DrawType.Ray)
                                      {
                                      
                          IRay ray = (IRay)o;
                                      
                          ray.Anchor1Y ray.Anchor2Y;
                                      
                          ray.Anchor1BarsAgo 5;    
                                      
                          ray.Anchor2BarsAgo 0;        
                                      }
                                      }
                                      } 
                          Attached Files
                          Last edited by djkiwi; 04-16-2012, 07:00 PM.

                          Comment


                            #28
                            Hello DJ,
                            You cannot change the X value of a manually draw object via NinjaScript code. Its true for both horizontal line, Ray etc.

                            If you want to bring the text at the front then please change the ZOrder by Shift+mouse wheel.

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

                            Comment


                              #29
                              Zorder

                              Hi Joydeep. I've been looking into the Zorder issue. So what I'm trying to do is put the writing behind the lines Stop, Target 1, Target 2 etc.(see chart). Now the problem is when I do this with the wheel it then puts it behind again sometimes and I have to keep using the mouse and wheel. I have 8 large screens and numerous charts so this is a nuisance adjusting them all the time.

                              So I found this thread and started trying to program it (See code below). According to this thread I can change Zorder in the same program. This doesn't work either.



                              Trying to order things seems overly cumbersome. I think Ninjatrader needs to include a field in each indicator where the user can adjust the order of the indicators. Mind you this wouldn't help me here because I'm just trying to adjust it in the same indicator.

                              Any ideas on this one? Basically I need to set the Zorder for the drawtext part. If that cannot be done, how do I change the transparency of the Ihorizonalline part? In the iltellisense I could not see opacity as an option anywhere.

                              Thanks in advance
                              DJ



                              So I tried this:
                              PHP Code:

                              //d. Target1
                                          
                                          
                              if (DrawObjects["T1"] != null)
                                          {    
                                          
                              IHorizontalLine    alertLine3    null;
                                          
                              IDrawObject        drawTargetone    DrawObjects["T1"];
                                          if (
                              drawTargetone != null && drawTargetone.DrawType == DrawType.HorizontalLine)
                                          
                              alertLine3 = (drawTargetone as IHorizontalLine);
                                          
                              alertLine3.Pen.Color Color.Cyan;
                                          
                              alertLine3.Pen.Width 3;
                                          
                              alertLine3.Pen.DashStyle DashStyle.Solid;
                                          
                              lineTargetone showTargetOne Instrument.MasterInstrument.Round2TickSize(alertLine3.Y) : targetone;    
                                          
                              alertLine3.SeparateZOrder=true;            
                                          
                              ZOrder 100;
                                          
                              DrawText("tag7"false,"Target 1", -10,lineTargetone0,Color.White,new Font("Courier"7FontStyle.Bold),StringAlignment.CenterColor.CyanColor.Black10); 
                              Attached Files
                              Last edited by djkiwi; 04-17-2012, 09:56 PM.

                              Comment


                                #30
                                Hello djkiwi,
                                The alert line draw object is an user drawn line and thus it is separate from the indicator and as such already have its own ZOrder. If the ZOrder dosent works for you and you simply want to change the transpercy of the line then please use the below code:

                                Code:
                                alertLine3.Pen.Color = Color.FromArgb(100, Color.Red);  // transparency set to 100 out of 255
                                Please let me know if I can assist you any further.
                                JoydeepNinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by GussJ, 03-04-2020, 03:11 PM
                                16 responses
                                3,279 views
                                0 likes
                                Last Post Leafcutter  
                                Started by WHICKED, Today, 12:45 PM
                                2 responses
                                19 views
                                0 likes
                                Last Post WHICKED
                                by WHICKED
                                 
                                Started by Tim-c, Today, 02:10 PM
                                1 response
                                8 views
                                0 likes
                                Last Post NinjaTrader_ChelseaB  
                                Started by Taddypole, Today, 02:47 PM
                                0 responses
                                5 views
                                0 likes
                                Last Post Taddypole  
                                Started by chbruno, 04-24-2024, 04:10 PM
                                4 responses
                                51 views
                                0 likes
                                Last Post chbruno
                                by chbruno
                                 
                                Working...
                                X