Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw.Text Assistance

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

    Draw.Text Assistance

    Greetings!

    Seeking assistance with Draw.Text functionality. For clarity, I created "Condition A" and plotted a triangle under it. I have successfully coded the triangle, the "Buy" text underneath the triangle and color scheme.

    However...
    1. The text does not stay on every instance of "Condition A" (the Triangle). When "Condition A" appears again, the "Buy" text moves. I'd like to see "Buy" every time it occurs on the chart.
    2. I use renko bricks. I set the distance of the "Buy" text to (ticksize - low[0] x 2). This works for lower brick sizes but does not work well for higher brick sizes.

    Any help fixing the above is appreciated!

    #2
    Hello TheTechnician86,

    Thank you for your post.

    The tag for a drawing object is a unique ID used to reference that specific drawing object. If you reuse the same tag, each time you call a drawing object the same drawing object will be referenced and the existing drawing object will be modified instead of a new object being created.

    For example, if you tag your drawing object “myTag”, each time you use “myTag” the same drawing object will be modified.

    To create a new drawing object, use a new unique string as the tag each time you call a Draw method. As an easy way to make a new string unique add ‘CurrentBar’ to the string.

    Help Guide: NinjaScript > Language Reference > Common > OnBarUpdate() > CurrentBar

    The code below will create a new red dot one tick below the low each time it is called.

    Code:
    Draw.Dot(this, "myTag" + CurrentBar, true, 0, Low[0] - TickSize, Brushes.Red);

    Can you explain what you mean by the distance "doesn't work"?

    Please let us know if you have any further questions.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the response!

      Below is a snippet of the code I created unchanged from my original post. I think this meets the unique tag requirements but I may be wrong.

      if (CurrentBar > 0)
      {​
      // Check for the ABuy Condition
      if (ABuy)
      {
      Draw.Text(this, "ABuy", "A", 0, Low[0] - TickSize * 6, Brushes.Green);
      }

      // Check for the ASell Condition
      if (ASell)
      {
      Draw.Text(this, "ASell", "A", 0, High[0] + TickSize * 6, Brushes.Red);
      }
      }

      On the distance calculation
      My understanding is that (for ABuy) the calculation for location of the text starts at the low of the renko brick. That number is then used to subtract the tick size multiplied by six. In equation form:
      Tick Size = 0.25
      Renko Brick Size = 2 ticks
      Top of Renko Brick = $10.50
      Bottom of Renko Brick = $10.00

      $10.00 - (0.25*6) = $8.50​

      The issue I am having is that when using higher brick sizes, the bottom of the renko brick is price is not being used, which results the text being drawn inside the brick even though the equation and result is the same. In equation form:
      Tick Size = 0.25
      Renko Brick Size = 10 ticks
      Top of Renko Brick = $12.50
      Bottom of Renko Brick = $10.00

      $10.00 - (0.25*6) = $8.50​

      Hope the long explanation helps you help me better. Thanks again!

      Comment


        #4
        Hello,

        Thank you for your response.

        Code:
        Draw.Text(this, "ABuy", "A", 0, Low[0] - TickSize * 6, Brushes.Green);
        
        Draw.Text(this, "ASell", "A", 0, High[0] + TickSize * 6, Brushes.Red);
        Each one does not have a unique tag. Each time you use "ABuy", the same "ABuy" drawing object will be modified instead of a new one being created. Same for "ASell".

        If you want to create a new "ABuy" or "ASell" object on each bar instead of the drawing object being modified, you will need to give them unique tag names using CurrentBar.


        The issue I am having is that when using higher brick sizes, the bottom of the renko brick is price is not being used, which results the text being drawn inside the brick even though the equation and result is the same.
        Have you confirmed this using prints to debug?

        To understand why the script is behaving as it is, such as placing orders or not placing orders (or drawing objects or other actions) when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

        In the script add prints (outside of any conditions) that print the values of every variable used in every condition that calls a drawing method along with the time of the bar.

        You can also print out the values being used in the calculations, i.e. High[0] + TickSize * 6 or Low[0] - TickSize * 6.​
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          It worked! Updated the code to this. Thank You!

          if (ASell)
          {
          Draw.Text(this, "ASell"+CurrentBar, "A", 0, High[0] + TickSize * 6, Brushes.Red);
          }

          Working on the print function to see what is going on. WIll update here ASAP. Thanks again!​

          Comment


            #6
            Worked on the reason why the draw.text functions were being drawn inside the bricks of the higher brick sizes.

            This occurred because I did not account for the brick size in the code. I updated to the code below and highlighted the required change.

            Draw.Text(this, "ASell"+CurrentBar, "A", 0, High[0] + ((TickSize * (High[0] - Low[0]))*3) * 6, Brushes.Red);

            For renko, this is required because unlike candles, the bricks are uniform size. Thus the calculation of placing a Draw.Text output above or below a candle requires us to calculate the brick size to figure out the minimum (preferred) ticks below or above the brick.

            Thanks again!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by oneybuchi2, Today, 03:48 PM
            0 responses
            5 views
            0 likes
            Last Post oneybuchi2  
            Started by Graci117, 06-19-2024, 01:39 PM
            6 responses
            53 views
            0 likes
            Last Post Graci117  
            Started by farawayz, Today, 01:20 PM
            0 responses
            11 views
            0 likes
            Last Post farawayz  
            Started by rjm1903, Today, 01:10 PM
            0 responses
            6 views
            0 likes
            Last Post rjm1903
            by rjm1903
             
            Started by AH369, 06-21-2024, 11:09 AM
            3 responses
            21 views
            0 likes
            Last Post AH369
            by AH369
             
            Working...
            X