Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do you calculate the height of a Dot/Diamond/Arrow to put text under it?

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

    How do you calculate the height of a Dot/Diamond/Arrow to put text under it?

    Hi. I am drawing a Dot, Diamond or Arrow on the chart. I want it some space below the low, then I want to put some text below that. How do I figure out how large a dot, diamond and arrow is, so I can put the text under it and not overlap it or have too much space?

    Here is the code I have written to date, it just doesn't work when I go to a different chart - I am using TickSize as the factor to space it out... bad idea.

    Please help.

    public static void MFDrawItem (this NinjaScript ns, NinjaScriptBase nsb, ref int dcounter, int drawtype, int panel, bool direction, string IDPrefix, int currbar, int barsback, double drawony, double drawoffset, Brush brush, string txtstrval1, string txtstrval2)
    {
    double lbloffset = 0;
    // double defaultoffset; // ticks below the Y value to draw the arrow
    // double drawTicksOffset;
    double prevarrowoffset;
    double ts;
    // bool nextarrow = false; // used to increment the arrow if we get 2 in 1 bar in same direction

    ts = (double) Instrument.Instruments[0].MasterInstrument.TickSize;

    // drawTicksOffset = drawoffset * ts; // ticks below the Y value to draw the arrow
    // defaultoffset = 40.0 * ts;
    // lbloffset = defaultoffset;

    if (direction) // long direction
    {
    if (LastUpArrowBar == currbar)
    {
    ns.Print ("another up arrow on bar <" + currbar + ">");
    prevarrowoffset = LastUpArrowOffset;
    } else {
    prevarrowoffset = 0.0;
    }
    switch(drawtype)
    {
    case 0: // draw a dot
    lbloffset = drawony - ((drawoffset * ts) + (ts * .03)) + prevarrowoffset;
    DrawingTools.Draw.Dot (nsb, (IDPrefix+currbar.ToString()+dcounter.ToString()), true, barsback, lbloffset, brush);
    if (txtstrval1 != "" || txtstrval2 != "")
    lbloffset -= (ts * .07);
    dcounter++;
    break;
    case 1: // draw an diamond
    lbloffset = drawony - ((drawoffset * ts) + (ts * .03)) + prevarrowoffset;
    DrawingTools.Draw.Diamond(nsb, (IDPrefix+currbar.ToString()+dcounter.ToString()), true, barsback, lbloffset, brush);
    if (txtstrval1 != "" || txtstrval2 != "")
    lbloffset -= (ts * .1);
    dcounter++;
    break;
    case 2: // draw an arrow
    lbloffset = drawony - ((drawoffset * ts) - (ts * .07)) + prevarrowoffset;
    DrawingTools.Draw.ArrowUp(nsb, (IDPrefix+currbar.ToString()+dcounter.ToString()), true, barsback, lbloffset, brush);
    if (txtstrval1 != "" || txtstrval2 != "")
    lbloffset -= (ts * .23);
    dcounter++;
    break;
    }
    if (txtstrval1 != "")
    {
    DrawingTools.Draw.Text(nsb, "Txt1"+(IDPrefix+currbar.ToString()+dcounter.ToStr ing()), txtstrval1, barsback, lbloffset, brush);
    lbloffset -= (ts * .13);
    dcounter++;
    }
    if (txtstrval2 != "")
    {
    DrawingTools.Draw.Text(nsb, "Txt2"+(IDPrefix+currbar.ToString()+dcounter.ToStr ing()), txtstrval2, barsback, lbloffset, brush);
    lbloffset -= (ts * .13);
    dcounter++;
    }
    lbloffset -= (ts * .08); // spacer for the next one
    LastUpArrowOffset = lbloffset - drawony; // save this we may need to print another arrow below it
    LastUpArrowBar = currbar;
    }
    else
    {
    if (LastDownArrowBar == currbar)
    {
    ns.Print ("another down arrow on bar <" + currbar + ">");
    prevarrowoffset = LastDownArrowOffset;
    } else {
    prevarrowoffset = 0.0;
    }
    switch(drawtype)
    {
    case 0: // draw a dot
    lbloffset = drawony + ((drawoffset * ts) + (ts * .03)) + prevarrowoffset;;
    DrawingTools.Draw.Dot(nsb, (IDPrefix+currbar.ToString()+dcounter.ToString()), true, barsback, lbloffset, brush);
    if (txtstrval1 != "" || txtstrval2 != "")
    lbloffset += (ts * .31);
    dcounter++;
    break;
    case 1: // draw an diamond
    lbloffset = drawony + ((drawoffset * ts) + (ts * .03)) + prevarrowoffset;;
    DrawingTools.Draw.Diamond(nsb, (IDPrefix+currbar.ToString()+dcounter.ToString()), true, barsback, lbloffset, brush);
    if (txtstrval1 != "" || txtstrval2 != "")
    lbloffset += (ts * .32);
    dcounter++;
    break;
    case 2: // draw an arrow
    lbloffset = drawony + ((drawoffset * ts) + (ts * .00)) + prevarrowoffset;
    DrawingTools.Draw.ArrowDown(nsb, (IDPrefix+currbar.ToString()+dcounter.ToString()), true, barsback, lbloffset, brush);
    if (txtstrval1 != "" || txtstrval2 != "")
    lbloffset += (ts * .45);
    dcounter++;
    break;
    }
    if (txtstrval2 != "")
    {
    DrawingTools.Draw.Text(nsb, "Txt2"+(IDPrefix+currbar.ToString()+dcounter.ToStr ing()), txtstrval2, barsback, lbloffset, brush);
    lbloffset += (ts * .13);
    dcounter++;
    }
    if (txtstrval1 != "")
    {
    DrawingTools.Draw.Text(nsb, "Txt1"+(IDPrefix+currbar.ToString()+dcounter.ToStr ing()), txtstrval1, barsback, lbloffset, brush);
    lbloffset += (ts * .13);
    dcounter++;
    }
    lbloffset += (ts * .07); // spacer for the next one
    LastDownArrowOffset = lbloffset - drawony; // save this we may need to print another arrow above it
    LastDownArrowBar = currbar;
    }
    }
    }

    #2
    Originally posted by DaFish View Post
    Hi. I am drawing a Dot, Diamond or Arrow on the chart. I want it some space below the low, then I want to put some text below that. How do I figure out how large a dot, diamond and arrow is, so I can put the text under it and not overlap it or have too much space?

    Here is the code I have written to date, it just doesn't work when I go to a different chart - I am using TickSize as the factor to space it out... bad idea.

    Please help.

    public static void MFDrawItem (this NinjaScript ns, NinjaScriptBase nsb, ref int dcounter, int drawtype, int panel, bool direction, string IDPrefix, int currbar, int barsback, double drawony, double drawoffset, Brush brush, string txtstrval1, string txtstrval2)
    {
    double lbloffset = 0;
    // double defaultoffset; // ticks below the Y value to draw the arrow
    // double drawTicksOffset;
    double prevarrowoffset;
    double ts;
    // bool nextarrow = false; // used to increment the arrow if we get 2 in 1 bar in same direction

    ts = (double) Instrument.Instruments[0].MasterInstrument.TickSize;

    // drawTicksOffset = drawoffset * ts; // ticks below the Y value to draw the arrow
    // defaultoffset = 40.0 * ts;
    // lbloffset = defaultoffset;

    if (direction) // long direction
    {
    if (LastUpArrowBar == currbar)
    {
    ns.Print ("another up arrow on bar <" + currbar + ">");
    prevarrowoffset = LastUpArrowOffset;
    } else {
    prevarrowoffset = 0.0;
    }
    switch(drawtype)
    {
    case 0: // draw a dot
    lbloffset = drawony - ((drawoffset * ts) + (ts * .03)) + prevarrowoffset;
    DrawingTools.Draw.Dot (nsb, (IDPrefix+currbar.ToString()+dcounter.ToString()), true, barsback, lbloffset, brush);
    if (txtstrval1 != "" || txtstrval2 != "")
    lbloffset -= (ts * .07);
    dcounter++;
    break;
    case 1: // draw an diamond
    lbloffset = drawony - ((drawoffset * ts) + (ts * .03)) + prevarrowoffset;
    DrawingTools.Draw.Diamond(nsb, (IDPrefix+currbar.ToString()+dcounter.ToString()), true, barsback, lbloffset, brush);
    if (txtstrval1 != "" || txtstrval2 != "")
    lbloffset -= (ts * .1);
    dcounter++;
    break;
    case 2: // draw an arrow
    lbloffset = drawony - ((drawoffset * ts) - (ts * .07)) + prevarrowoffset;
    DrawingTools.Draw.ArrowUp(nsb, (IDPrefix+currbar.ToString()+dcounter.ToString()), true, barsback, lbloffset, brush);
    if (txtstrval1 != "" || txtstrval2 != "")
    lbloffset -= (ts * .23);
    dcounter++;
    break;
    }
    if (txtstrval1 != "")
    {
    DrawingTools.Draw.Text(nsb, "Txt1"+(IDPrefix+currbar.ToString()+dcounter.ToStr ing()), txtstrval1, barsback, lbloffset, brush);
    lbloffset -= (ts * .13);
    dcounter++;
    }
    if (txtstrval2 != "")
    {
    DrawingTools.Draw.Text(nsb, "Txt2"+(IDPrefix+currbar.ToString()+dcounter.ToStr ing()), txtstrval2, barsback, lbloffset, brush);
    lbloffset -= (ts * .13);
    dcounter++;
    }
    lbloffset -= (ts * .08); // spacer for the next one
    LastUpArrowOffset = lbloffset - drawony; // save this we may need to print another arrow below it
    LastUpArrowBar = currbar;
    }
    else
    {
    if (LastDownArrowBar == currbar)
    {
    ns.Print ("another down arrow on bar <" + currbar + ">");
    prevarrowoffset = LastDownArrowOffset;
    } else {
    prevarrowoffset = 0.0;
    }
    switch(drawtype)
    {
    case 0: // draw a dot
    lbloffset = drawony + ((drawoffset * ts) + (ts * .03)) + prevarrowoffset;;
    DrawingTools.Draw.Dot(nsb, (IDPrefix+currbar.ToString()+dcounter.ToString()), true, barsback, lbloffset, brush);
    if (txtstrval1 != "" || txtstrval2 != "")
    lbloffset += (ts * .31);
    dcounter++;
    break;
    case 1: // draw an diamond
    lbloffset = drawony + ((drawoffset * ts) + (ts * .03)) + prevarrowoffset;;
    DrawingTools.Draw.Diamond(nsb, (IDPrefix+currbar.ToString()+dcounter.ToString()), true, barsback, lbloffset, brush);
    if (txtstrval1 != "" || txtstrval2 != "")
    lbloffset += (ts * .32);
    dcounter++;
    break;
    case 2: // draw an arrow
    lbloffset = drawony + ((drawoffset * ts) + (ts * .00)) + prevarrowoffset;
    DrawingTools.Draw.ArrowDown(nsb, (IDPrefix+currbar.ToString()+dcounter.ToString()), true, barsback, lbloffset, brush);
    if (txtstrval1 != "" || txtstrval2 != "")
    lbloffset += (ts * .45);
    dcounter++;
    break;
    }
    if (txtstrval2 != "")
    {
    DrawingTools.Draw.Text(nsb, "Txt2"+(IDPrefix+currbar.ToString()+dcounter.ToStr ing()), txtstrval2, barsback, lbloffset, brush);
    lbloffset += (ts * .13);
    dcounter++;
    }
    if (txtstrval1 != "")
    {
    DrawingTools.Draw.Text(nsb, "Txt1"+(IDPrefix+currbar.ToString()+dcounter.ToStr ing()), txtstrval1, barsback, lbloffset, brush);
    lbloffset += (ts * .13);
    dcounter++;
    }
    lbloffset += (ts * .07); // spacer for the next one
    LastDownArrowOffset = lbloffset - drawony; // save this we may need to print another arrow above it
    LastDownArrowBar = currbar;
    }
    }
    }
    Use Draw.Text() and draw text arrows, dots, etc. There is at least one overload of Draw.Text() that allows precise placement of the object by definite offset.
    Last edited by koganam; 09-16-2016, 12:47 PM. Reason: Corrected grammar.

    Comment


      #3
      Originally posted by koganam View Post
      Use Draw.Text() and draw text arrows, dots, etc. There is at least one overload of Draw.Text() allows precise placement of the object by definite offset.
      Hi koganam. I am using Draw.Text.

      That is the problem though, I don't have the exact sizing, and I don't know how to get the exact location.

      I want to do the following (think of this as a bar). Under the bar I want:

      Low of bar
      space (few pixels)
      DOT/Diamond/Arrow
      space (few pixels)
      Text 1 (IE: CCI)
      Text 2 (IE: DN)

      What I don't know:
      1) The location of the low
      2) how to specify a few pixels (I was using TickSize times a fudge factor)
      3) how big the dot/diamond/arrow is to put the text below it
      4) how bit the text is to put the next text line below it....

      Comment


        #4
        Originally posted by DaFish View Post
        Hi koganam. I am using Draw.Text.

        That is the problem though, I don't have the exact sizing, and I don't know how to get the exact location.

        I want to do the following (think of this as a bar). Under the bar I want:

        Low of bar
        space (few pixels)
        DOT/Diamond/Arrow
        space (few pixels)
        Text 1 (IE: CCI)
        Text 2 (IE: DN)

        What I don't know:
        1) The location of the low
        2) how to specify a few pixels (I was using TickSize times a fudge factor)
        3) how big the dot/diamond/arrow is to put the text below it
        4) how bit the text is to put the next text line below it....
        No you are not. You are using Draw.Dot(), Draw.Diamond etc. Look up the overloads for Draw.Text(): there is at least one overload that has all the information that you are asking for. Then use Draw.Text() to draw text dots etc. You may have to bring up the Character Map in Windows (or another tool) to see what text character glyphs you need.
        Last edited by koganam; 08-05-2015, 05:16 PM.

        Comment


          #5
          I think koganam has the right idea here, it would be a lot of work to dynamically calculate the radius of the chart marker natively from an indicator and position it on the chart as the scales updates. On the other hand, you could theoretically create your own custom Drawing Tool by referencing the logic in DrawingTools\@ChartMarkers and adding text to what is rendered, however those objects likely have some concepts that are new to you at this point, perhaps something to tackle later down the road...

          But the easy way out is just use a unicode chracter in the text argument for Draw.Text():



          Code:
          // u25CF draws black dot + \n creates a new line + yourText
          Draw.Text(this, "text", "\u25CF" + "\n" + "Hi", 0, Low[0]);
          MatthewNinjaTrader Product Management

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by RubenCazorla, 08-30-2022, 06:36 AM
          3 responses
          77 views
          0 likes
          Last Post PaulMohn  
          Started by f.saeidi, Yesterday, 12:14 PM
          9 responses
          23 views
          0 likes
          Last Post f.saeidi  
          Started by Tim-c, Today, 03:54 AM
          0 responses
          3 views
          0 likes
          Last Post Tim-c
          by Tim-c
           
          Started by FrancisMorro, Today, 03:24 AM
          0 responses
          3 views
          0 likes
          Last Post FrancisMorro  
          Started by Segwin, 05-07-2018, 02:15 PM
          10 responses
          1,772 views
          0 likes
          Last Post Leafcutter  
          Working...
          X