Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

indicator processing manually drawn Ray before the user finishes the draw

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

    indicator processing manually drawn Ray before the user finishes the draw

    have an indicator that is processing OnPriceChange

    when I hand draw a Ray my indicator starts recognizing the Ray before I'm finished drawing it.....and the anchors are this

    StartAnchor.BarsAgo = -2147483648
    EndAnchor.BarsAgo = -2147483648

    what is going on???


    #2
    Because you haven't let go yet. Just check for that in the indicator. If BarsAgo is int.MinValue it isn't set yet.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Wow...didn't expect that behavior...thank you.

      Comment


        #4
        Hello llanqui,

        Thanks for your post.

        QuantKey_Bruce is correct in stating that this is due the not letting go of the mouse to finish drawing the object yet when the indicator processes logic.

        The workaround that QuantKey_Bruce provided could likely be used to check for this in the indicator.

        Please let us know if we may assist further. ​
        Last edited by NinjaTrader_BrandonH; 05-15-2023, 10:45 AM.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Hello...well, can you please take a look at this code...it looks right to me but returns the negative BarsAgo even after the mouse is up

          protected override void OnBarUpdate()
          {
          if (State == State.Historical)
          return;

          foreach (DrawingTool draw in DrawObjects.ToList())
          {
          // select User Drawn Horizontal or Ray Lines
          if (draw.IsUserDrawn)
          {
          if (draw is DrawingTools.Ray)
          {
          DrawingTools.Ray thisRay = draw as DrawingTools.Ray;

          Print
          (
          "-----------------------------------------------------------------------" +
          Environment.NewLine +
          "thisRay.StartAnchor.BarsAgo = " + thisRay.StartAnchor.BarsAgo.ToString() +
          " ... " +
          "thisRay.EndAnchor.BarsAgo) = " + thisRay.EndAnchor.BarsAgo.ToString()
          );
          }
          }
          }
          }

          }
          }​

          Comment


            #6
            Hello llanqui,

            Thanks for your note.

            ​Since you are detecting manually drawn rays in your script, you will need to use <ChartAnchor>.SlotIndex instead of BarsAgo. This is because BarsAgo cannot be used on manually drawn lines.

            For example, the code might look something like this:
            Code:
            foreach (DrawingTool draw in DrawObjects.ToList())
            {
                if (draw.IsUserDrawn)
                {
                    if (draw is DrawingTools.Ray)
                    {
                        DrawingTools.Ray thisRay = draw as DrawingTools.Ray;
                        Print("-------------------");
                        Print("thisRay.StartAnchor.SlotIndex: " + thisRay.StartAnchor.SlotIndex);
                        Print("thisRay.EndAnchor.SlotIndex: " + thisRay.EndAnchor.SlotIndex);
                    }
                }
            }
            See the help guide documentation below for more information about SlotIndex.

            SlotIndex: https://ninjatrader.com/support/help...l?barindex.htm
            IDrawingTools ChartAnchors: https://ninjatrader.com/support/help...tm#chartanchor
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              Ok, is this documented somewhere??? I have a hard time finding what I need in the online help...

              Comment


                #8
                Oh, sorry, I didn't see your last rererences..that answers this

                Comment


                  #9
                  Is there a way I can convert SlotIndex to BarsAgo?

                  Comment


                    #10
                    would BarsAgo = CurrentBar - SlotIndex ?? for a single series chart?

                    Comment


                      #11
                      Hello llanqui,

                      Thanks for your note.

                      Yes, since the SlotIndex returns a bar index value you could subtract the <ChartAnchor>.SlotIndex value from CurrentBar to get the BarsAgo value of a drawing object's ChartAnchor.

                      For example, say thisRay.EndAnchor.SlotIndex returns a bar index value of 90 and the CurrentBar on the chart is bar 100.

                      You could subtract the SlotIndex value from CurrentBar to get a BarsAgo value of 10 (100 - 90 = 10).

                      The code might look something like this:

                      double rayBarsAgo = CurrentBar - thisRay.EndAnchor.SlotIndex;

                      Please let me know if you have further questions on this topic.
                      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                      Comment


                        #12
                        yes, that works...thank you

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        648 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        369 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        109 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        573 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        575 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X