Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Convert Price (World Coordinates) in to Pixels (Screen Coordinates)

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

    How to Convert Price (World Coordinates) in to Pixels (Screen Coordinates)

    Hello,

    I have an indicator that is drawing text above and below some bar. However, it looks good on a 15-minute chart but looks bad on a daily or I can get it to look good on a daily but then the 15-minute chart looks bad. This is happening because the y parameter value is in Word Coordinates and not Screen Coordinates.

    What I would like is to have the text drawn 5 pixels above and below the bar regardless of the time interval. How can I make this work? Thanks.

    #2
    Hello Kabua,

    Thank you for the post.

    Can you provide a specific example of how you are drawing currently?

    Are you referring to specifically the Price parameter y or its yPixelOffset?

    Code:
    Draw.Text(NinjaScriptBase owner, string tag, bool isAutoScale, string text, DateTime time, [B]double y, int yPixelOffset,[/B]



    I look forward to being of further assistance.

    Comment


      #3
      Draw.Text(indicator, tag, text, barsAgo, y);
      Where
      tickSize = indicator.Instrument.MasterInstrument.TickSize
      y = High + tickSize or Low - tickSize depending on other logic.

      Comment


        #4
        Hello Kabua,

        Thank you for the reply.

        Yes in that situation the drawing will be compressed or decompressed as you scale the chart because you are supplying a price away from another price. The distance between those two prices will compress/decompress with the scale.

        If you wanted the text stationary and always a certain distance from the bar, you could use the bars High or Low price as the Y price, and then enter a yPixelOffset for the number of pixels it should remain away from that price.

        It looks like you are using the shorter syntax to draw the text, you would instead need to use one of the overloads that includes yPixelOffset. Here is one example:

        Code:
        Draw.Text(this, "tag" ,true, "Test", 0, High[0], 25, Brushes.Red, new SimpleFont(), TextAlignment.Center,Brushes.Transparent, Brushes.Transparent, 100);

        I look forward to being of further assistance.

        Comment


          #5
          Okay, great.

          How do I use the system default values for text brush, font, text alignment, outline brush, area brush and area opacity?

          Comment


            #6
            Hello Kabua,

            The Text tool has some defaults which get set and some properties which get read, for full details on all of the values it can have in one specific case, you would need to review the drawing tool its self and its code.

            Here are the highlights for the items you mentioned:

            Code:
            Alignment        = TextAlignment.Left;
            Font            = new Gui.Tools.SimpleFont() { Size = 14 };
            OutlineStroke    = new Stroke(Brushes.Transparent, 2f);
            AreaBrush        = Brushes.Transparent;
            AreaOpacity        = 100;
            YPixelOffset    = 0;
            The standard text brush is:

            Code:
            ChartControl.Properties.ChartText;
            I look forward to being of further assistance.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            566 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            330 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            547 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            548 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X