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

Horizontal Line

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

    Horizontal Line

    Hi,
    I draw one horizontal line manually on one chart.
    Question is here:
    Is it possible change Color, Width & dash Style of this line from one indicator?
    How i can find "Tag" of this line?
    If Ninja has this option, How i can do that and change H Line properties?
    Regards,

    #2
    RezaFX, here's an example script you could look into - just draw a horizontal line on your chart and then apply this script, it will change the width to 3 and dash style for your HLines. If you add another line, just reload the indicator...it uses the DrawObjects collection exposed in NinjaScript - http://www.ninjatrader.com/support/h...ub=DrawObjects
    Attached Files
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand.

      Thanks for this script.

      I've been modifying it for my use but i have run into a snag.

      The main snag is that i want to "DrawText" at the END of each line but i cannot manage the DateTime end of things because I am a hack and I always run into "time" related issues.

      What I can do is DrawTextFixed() or other some such Draw-thing, and I do get the required text but it is not at the end (EndY) of the lines i have drawn. In fact if i draw more than 1 line it only drawtext() the final line's text.

      Is there a way to draw text at the EndY point of a line? Then maybe we'll talk more than one line as that is an issue as well.

      Comment


        #4
        Oh shoot, i was over thinking it Bertrand. I still have one problem though so hang on a minute.
        First of all I guess we have "EndBarsAgo" that fit the bill for DrawText() in the place that i want it, so all we have left now is to have the ability to draw text on more than one draw object.

        Can I assume since i an using the same tag on each DrawText() that will have to vary the "tag"?

        IE:

        DrawText("tag1", dLogRtn.ToString("0.###"), drawnLine.EndBarsAgo - 3, dEndY, Color.Black);
        Is my text. I just offset the text a bit therefore the "-3" thing, but what do i do about the "tag1" if that is indeed the problem IE not a unique ID?

        thanks

        Comment


          #5
          You know i feel like such a dork figuring this stuff out on my own after asking, lol.

          I was trying to add to the string all night IE

          "tag1" + CurrentBar.ToString()
          but it was not working and in fact was taking a hell of a long time to run and in the end not doing at all what i wanted. It was doing something whacky that i only half understand.

          anyway I just added a unique end (unique enough I guess although duplicate certainly are possible.)

          Since i was running Math.Log as you can see already, I just appended that to "tag1" and now i have everything i want.

          If you can maybe explain why adding the currentbar.tostring(), etc to tag1 was not working in your script that would be cool. If you could suggest a better unique ID to append that would be great as well.

          thanks again.
          Last edited by Steve R; 12-09-2013, 11:58 PM.

          Comment


            #6
            Hello Steve R,

            Using the "CurrentBar.ToString()" will work but the main issue that you can run into is that running this script Historically is that it is going to create a DrawText object for every bar (since CurrentBar is going to be unique for each one) which is going to take up a lot of memory and can cause some performance issues. For a unique tag for the DrawText you may want to use the tag name of the line that you are getting that way when DrawText is only drawing them for each object that you are drawing. So that way NinjaTrader will overwrite the previous DrawText object if the "tag" name that you give it plus the "tag" name of the drawing object are the same. For example:

            Code:
            protected override void OnBarUpdate()
            {
                   foreach (IDrawObject draw in DrawObjects)
                   {
            		if (draw is ILine && draw.UserDrawn && draw.DrawType == DrawType.HorizontalLine)
            		{
            			ILine drawnLine = (ILine) draw;
            			drawnLine.Pen.Width = 3;
            			drawnLine.Pen.DashStyle = DashStyle.DashDotDot;
            			
            			DrawText("tag1" +[COLOR="Red"]drawnLine.Tag[/COLOR], "Time: "+ToTime(Time[0]), 0, drawnLine.EndY+1*TickSize, Color.Black);
            		}							
            	}
            }
            JCNinjaTrader Customer Service

            Comment


              #7
              thanks JC. Some of what you've got there isn't working for me but i have mostly what i need now anyway, but I have one more issues than I cannot fix with DrawText()

              I'm trying to change the font, size and in bold if i can, but i cannot even get the first part to work..

              what i have is:
              sTagString = "tag1" + drawnLine.Tag;
              dEndY = drawnLine.EndY;
              dLogRtn = Math.Log(dEndY / dStartY);

              DrawText(sTagString, dLogRtn.ToString("0.###"), drawnLine.EndBarsAgo - 3, dEndY, Color.Black);
              BTW i am not using it on horizontal lines, not that it matters.

              i've tried to add in there somewhere new Font("Arial", 12) as i have seen that before but i get an argument (count) error in my DrawText() line and the script will not compile.

              what's wrong with it? where do i also place the BOLD part?
              Last edited by Steve R; 12-10-2013, 06:16 PM.

              Comment


                #8
                Hello Steve R,

                You would have to use another DrawText() overload method that will take a "Font" parameters so the overload that you may use is:
                DrawText(string tag, bool autoScale, string text, int barsAgo, double y, int yPixelOffset, Color textColor, Font font, StringAlignment alignment, Color outlineColor, Color areaColor, int areaOpacity)

                Then here you an define a "Font" to change the size, and if it is bold for example:

                Code:
                DrawText("textbox", false, "SomeText", 0, Close[0], 0, Color.Black, new Font("Arial", 20, FontStyle.Bold), StringAlignment.Center , Color.Blue, Color.White, 0);
                JCNinjaTrader Customer Service

                Comment


                  #9
                  that's the thing JC. I've tried and i get nothing but errors. The help file "isn't" because it doesn't give enough actual examples to be of any use for me. I see the parameters but there's nothing I've done that has worked.

                  Can you use the example I gave and just stick in the font where it belongs? That was what i was after which is why i put it up there.

                  Comment


                    #10
                    Ya know what JC. I've got it kind of working. It's not exactly what I want but it's better than what i had. Given what it is I am not all that worked-up about it, so we can call this one done.

                    Thanks

                    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