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

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        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.

            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by andrewtrades, Today, 04:57 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            5 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            7 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X