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

Arrow not drawn on the expected bar

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

    Arrow not drawn on the expected bar

    Hello!
    I have a dynamic rectangle drawn on the chart.
    The idea is to have a candle (body or wick) entering in the rectangle and to draw an arrow on the bar fulfilling this condition.
    I have the dynamic rectangle on the chart and I can retrieve the low and the high of the rectangle, represented by the Anchor.Price.

    ​Here is my code:
    HTML Code:
     foreach(DrawingTool draw in DrawObjects.ToList())
    ​ {
       if(draw is DrawingTools.Rectangle)
       {
          if(draw.Tag == "tag2")
          {
             if(Low[0] < temp.StartAnchor.Price)  // temp.StartAnchor.Price is the low of the rectangle.
             {
                Draw.ArrowUp(this, "ArrowUp"+CurrentBar, true, Time[0], Low[0] , Brushes.Blue);
             }​
          }
       }
     }
    I am having some arrows drawn, not at Bar[0] but 11 to 25 barAgo. This code providestherefore laging arrows.

    I would appreciate any help!

    Thanks in advance!

    #2
    Hello Stanfillirenfro,

    Thank you for your post.

    I recommend debugging the script using prints. Print out the Time[0] which is the time your drawing object is going to be drawn at, along with the tag so you can compare this with what you are seeing on the chart.

    Note that you could also use the following syntax to draw the arrow 0 bars ago (the current bar):

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

    Draw.ArrowUp(this, "ArrowUp"+CurrentBar, true, 0, Low[0] , Brushes.Blue);



    If you need further assistance please let us know.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Many thanks NinjaTrader_Gaby for your help.

      Interesting/weird vaues I am seeing on the output window.

      I have the following code:

      HTML Code:
      for(int i = 0; i < zone_count; i++)
       {
          Draw.Rectangle();
          
          if(Low[i] < HighRecta[i])
          {
             Draw.ArrowUp(this, "ArrowUp"+CurrentBar, true, Time[i], Low[i] , Brushes.Blue);
             Print("Time[0]3a" + " Size " + ":  " + Time[i] + " Time " + ":  " + Time[0]);
          }
       }
      On the output window, I am seeing that Time[i] is quite different from Time[0] (see picture attached). I do not have any probem drawing the rectangles. What could be causing this shift.
      I would strongly appreciate your help!

      Thanks in advance.​

      Comment


        #4
        Picture mentioned above.
        Attached Files

        Comment


          #5
          Hello,

          Time[i] is using the i from the loop. The value of i is going to be 0 through zone_count.

          While Time[0] is always going to be the the timestamp of the currentBar, on each pass of OnBarUpdate() (assuming this code is in OnBarUpdate()) the value of i is going to be calculated for every value 0 through zone_count and since you are also calling this print within the loop you are seeing it print multiple times per bar.

          This is why you are seeing several prints which have the Time[0] timestamp the same but Time[i] is different. i is being updated as you loop through 0 through zone_count but Time[0] is static.
          Gaby V.NinjaTrader Customer Service

          Comment


            #6
            Thanks NinjaTrader_Gaby for your reply.

            (assuming this code is in OnBarUpdate())
            No I have this code in the section #Helpers, but I am calling the function in OnBarUdpade().
            Is there a way to fix this problem outside of OnBarUpdate()? If Yes, any idea please?

            Thanks

            Comment


              #7
              Hello,

              This isn't necessarily a problem, the loop is working as intended. If you only want the arrow drawn on the current bar being updated in OnBarUpdate(), use Time[0] instead of Time[i].
              Gaby V.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by MatthewLesko, 05-21-2021, 09:37 PM
              4 responses
              163 views
              0 likes
              Last Post Mahmad1323  
              Started by samish18, Today, 03:02 PM
              3 responses
              15 views
              0 likes
              Last Post bltdavid  
              Started by Jakub, Today, 11:06 AM
              1 response
              16 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by samish18, Today, 03:50 AM
              10 responses
              19 views
              0 likes
              Last Post samish18  
              Started by Mestor, 06-03-2018, 10:09 AM
              16 responses
              2,872 views
              0 likes
              Last Post myaha1000  
              Working...
              X