Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing Objects Help

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

    Drawing Objects Help

    I am trying to make my Strategy draw an Up Arrow every time I have a condition fill but when I put in what the language reference says I get nothing on my chart.
    Tried finding examples or documentation and can find none that are helping.
    Below is my code, any ideas?

    Draw.ArrowUp(this,"BuyTag", false, CurrentBar, High[0] + TickSize, Brushes.ForestGreen);

    I have this in my if() statement within the OnBarUpdate() method. I know this line is executing in my strategy but not sure why arrows are not showing.

    Also I have tried all of the different ways listed in ninjascript reference

    Thanks for your help!

    #2
    Hello Vikuno1,

    Thank you for your post.

    I suspect the use of "CurrentBar" rather than barsAgo is the culprit here. The method signature for Draw.ArrowUp() is as follows:

    Draw.ArrowUp(NinjaScriptBase owner, string tag, bool isAutoScale, int barsAgo, double y, Brush brush)

    CurrentBar is a bar index for the current bar, where 0 is the first bar on the left of the chart and CurrentBar is the highest number that has been indexed so far. If you want to draw the ArrowUp on the current bar, you would simply need to use 0 for the int barsAgo. This is also what is demonstrated in the example from the help guide page for Draw.ArrowUp():
    // Paints a red up arrow on the current bar 1 tick below the low
    Draw.ArrowUp(this, "tag1", true, 0, Low[0] - TickSize, Brushes.Red);
    For additional information regarding bar indexing, please see the following help guide section:



    If you have any additional questions or concerns, please feel free to post them here.

    Comment


      #3
      Originally posted by NinjaTrader_Emily View Post
      Hello Vikuno1,

      Thank you for your post.

      I suspect the use of "CurrentBar" rather than barsAgo is the culprit here. The method signature for Draw.ArrowUp() is as follows:

      Draw.ArrowUp(NinjaScriptBase owner, string tag, bool isAutoScale, int barsAgo, double y, Brush brush)

      CurrentBar is a bar index for the current bar, where 0 is the first bar on the left of the chart and CurrentBar is the highest number that has been indexed so far. If you want to draw the ArrowUp on the current bar, you would simply need to use 0 for the int barsAgo. This is also what is demonstrated in the example from the help guide page for Draw.ArrowUp():
      // Paints a red up arrow on the current bar 1 tick below the low
      Draw.ArrowUp(this, "tag1", true, 0, Low[0] - TickSize, Brushes.Red);
      For additional information regarding bar indexing, please see the following help guide section:



      If you have any additional questions or concerns, please feel free to post them here.
      I plugged this in (which I had already tried) and still no arrows appeared. I tested my condition as well to see if it is executing and it is.

      How do I add an arrow under a bar every time a condition is true?

      Comment


        #4
        Hello Vikuno1,

        Thank you for your reply.

        Are there any errors in the log tab of the Control Center when you are running your strategy? I also recommend (if you have not already) adding Print() statements both inside and outside of your condition that prints the time and any variables being used inside of the condition. If the prints outside of the condition are the only prints that show up in the NinjaScript Output window, that means that the condition is not being met. If the print inside of the condition does show up as well but the arrows are not appearing on the chart, that means there may be an error in regard to drawing the arrows.

        There are more details about using prints to debug your code here:



        If you would like to provide the condition that should be drawing the arrows, I would be glad to provide an example print statement more specific to your script.

        I appreciate your patience. Please let me know if I may be of further assistance.

        Comment


          #5
          Originally posted by NinjaTrader_Emily View Post
          Hello Vikuno1,

          Thank you for your reply.

          Are there any errors in the log tab of the Control Center when you are running your strategy? I also recommend (if you have not already) adding Print() statements both inside and outside of your condition that prints the time and any variables being used inside of the condition. If the prints outside of the condition are the only prints that show up in the NinjaScript Output window, that means that the condition is not being met. If the print inside of the condition does show up as well but the arrows are not appearing on the chart, that means there may be an error in regard to drawing the arrows.

          There are more details about using prints to debug your code here:



          If you would like to provide the condition that should be drawing the arrows, I would be glad to provide an example print statement more specific to your script.

          I appreciate your patience. Please let me know if I may be of further assistance.
          I have done debugging with Print statements, My condition is returning true. Even when I put the statement: Draw.ArrowUp(this, "tag1", true, 0, Low[0] - TickSize, Brushes.Red); just out in the "OnBarUpdate()" Method (Which should just print under every bar) it does nothing

          Comment


            #6
            Hello Vikuno1,

            Thank you for your reply.

            If I create a new indicator and paste this into the OnBarUpdate() method I do get a red up arrow drawn on my chart:

            protected override void OnBarUpdate()
            {
            Draw.ArrowUp(this, "tag1", true, 0, Low[0] - TickSize, Brushes.Red);
            }

            If I open the drawing objects window, I see the arrow with tag1. If you want an arrow under every single bar, you would need to use a unique tag for each bar like using "tag1" + CurrentBar.ToString(). That being said, it is important to keep in mind the performance impact of creating excessive drawing objects.

            Are you getting any errors in the NinjaScript Output window or the Log tab of the Control Center? If possible, please provide a reduced sample of your code that I may import on my end to test out the behavior and see if the arrows are being drawn properly or not.

            I look forward to resolving this item with you.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            44 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            124 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            65 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X