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

Using DrawText for arrows and numbers

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

    Using DrawText for arrows and numbers

    Hello

    I would like to draw up and down arrows, and have a number above or below that arrow. Here is what I have done followed by my question.

    To do that I am using the following:

    Rising
    DrawText("arr6", false, "á", 0, Lows[6][0], 0, Color.Blue, new Font ("Wingdings", 7, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);
    DrawText("lab6", false, "30", 0, Lows[6][0]-3*TickSize, 0, Color.Blue, new Font ("Arial", 7, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);
    Falling

    DrawText("arr6", false, "â", 0, Highs[6][0], 0, Color.Red, new Font ("Wingdings", 7, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);
    DrawText("lab6", false, "30", 0, Highs[6][0]+3*TickSize, 0, Color.Red, new Font ("Arial", 7, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);

    The problem is with the +-3*TickSize. Sometimes it fits but when the scaling changes, the distance needs to be increased or decreased, or arrow and number are laid over each other.

    Next I tried using the font size e.g.

    Rising
    DrawText("arr6", false, "á", 0, Lows[6][0], 0, Color.Blue, new Font ("Wingdings", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);
    DrawText("lab6", false, "30", 0, Lows[6][0]-fsize*TickSize, 0, Color.Blue, new Font ("Arial", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);

    Falling
    DrawText("arr6", false, "â", 0, Highs[6][0], 0, Color.Red, new Font ("Wingdings", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);
    DrawText("lab6", false, "30", 0, Highs[6][0]+fsize*TickSize, 0, Color.Red, new Font ("Arial", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);

    That gives me better results but it's not optimum yet.

    The 'DrawTextFixed' method with its TopRight and TopBottom uses the "n's" to move up and down. I am wondering whether there's something similar to use in 'DrawText' that I am not aware of yet.

    Any advice to keep arrow and number always close together and not overlapping is appreciated.

    sandman




    #2
    Hello sandman,

    Thanks for your post.

    The only thing I could suggest (in addition to what you have tried) would be to use the Ypixeloffset that is available in the Draw.Text() method. Currently, you have it set to 0. You can try variations to find if something works for you.



    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you PaulH. I think I got the idea and will try it out using a positive Ypixeloffset for the arrows and a negative one for the numbers defined by half the value of the font size.
      Will let you know the result.

      sandman

      Comment


        #4
        Perfect. Does exactly what I tried to achieve.

        To complete it, here is the code that did it, i.e. draw an arrow with the text snuggly above or below the arrow no matter the scaling:

        Rising
        DrawText("arr0", false, "á", 0, Lows[0][0], +fsize/2, Color.Blue, new Font ("Wingdings", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);
        DrawText("lab0", false, "15", 0, Lows[0][0], -fsize/2, Color.Blue, new Font ("Arial", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);

        Falling
        DrawText("arr0", false, "â", 0, Highs[0][0], -fsize/2, Color.Red, new Font ("Wingdings", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);
        DrawText("lab0", false, "15", 0, Highs[0][0], +fsize/2, Color.Red, new Font ("Arial", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);

        Thanks PaulH!

        sandman

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by GLFX005, Today, 03:23 AM
        0 responses
        1 view
        0 likes
        Last Post GLFX005
        by GLFX005
         
        Started by XXtrader, Yesterday, 11:30 PM
        2 responses
        11 views
        0 likes
        Last Post XXtrader  
        Started by Waxavi, Today, 02:10 AM
        0 responses
        6 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Started by TradeForge, Today, 02:09 AM
        0 responses
        14 views
        0 likes
        Last Post TradeForge  
        Started by Waxavi, Today, 02:00 AM
        0 responses
        3 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Working...
        X