Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to detach a drawn line from an indicator?

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

    How to detach a drawn line from an indicator?

    My indicator draws (global) horizontal lines for SL and TP.
    The SL line is not locked, the TP line is locked.
    I have two chart for the same instrument, both with my indicator on it.
    When the indicator on one of the charts draws the lines, they're visible on both chart (as expected).
    But when I reload one of the charts, the TP line remains (on both charts) but the SL line is gone (on both charts)..

    I suppose this behavior occurs because reloading the indicator seems to (try to) remove all indicator attached lines.
    And the TP line is locked and it seems (maybe) that it therefore is not removed, the SL line is not locked and removed.

    Question:
    Is my above assumption correct?

    Question:
    I'd like to keep BOTH lines when I reload the chart (cq the indicator).
    So I'm looking for a way to 'detach' the lines from the indicator directly after I've drawn them (if that's the problem).

    Any thoughts?

    #2
    Hello wjadevries,

    Are you certain that the TP line is being left behind and not just re drawn when you had reloaded the script? Is the condition to draw the SL line happening? That would be the first item I would suggest to check or that after reloading if the SL line condition is true again. In general its expected for the objects to be removed with the script, the script is the owner of the object.

    I look forward to being of further assistance.

    Comment


      #3
      The TP line is NOT redrawn after reloading, I'm 100% sure about that.
      So the only reason I can think of that the TP line stays on the chart after the script is reloaded is that it's locked.

      But I'm perfectly fine with that; and I want the SL to remain on the chart also.
      And I don't want to lock the SL line.
      So my question is: can I somehow from within my indicator 'detach' the line(s) from the indicator, so they remain on the chart?

      I saw an AttachedTo property in the Drawing Tools section (https://ninjatrader.com/support/help...attachedto.htm) but I can't find a way how to use it ('unset' it).

      Comment


        #4
        Hello wjadevries,

        You wouldn't be able to detach it but from the given details it sounds like the condition to draw it was not true after reloading it. Did you try using a print to confirm the condition was true?

        I look forward to being of further assistance.

        Comment


          #5
          The indicator uses a wpf button to initiate drawing the lines.
          if you press the button, both lines are drawn.
          So I'm 100% sure that the situation is as I described it.
          Only the locked line remains on screen after F5, the unlocked line is removed.
          Nothing is redrawn automatically after the reload, the drawing is only initiated manually by clicking the button.

          And the question is: how can I detach the line from the indicator or something else, so it doesn't get removed (like the locked one).

          Comment


            #6
            Hello wjadevries,

            There's not supported way to detach it, your script is the owner since it drew it. You could lock the other line as it seems that has the desired result although it is expected for the script to be removing the objects when its terminated. Alternatively the script would need to redraw the line somehow when it restarts, you may look into saving the current lines to file or in some way during the terminated event and reloading that information when the script starts.


            I look forward to being of further assistance.

            Comment


              #7
              Oke, thanks for the suggestion.
              I'll try to find a way around it.

              Comment


                #8
                Hello wjadevries,

                I've looked high and low for what you're looking for. The only trick that I've found that vaguely works is setting the DrawnBy property to null.

                Code:
                lineObject.DrawnBy = null;
                I theorize that setting the owner to the chart when initially creating the object will solve this issue, however, I cannot find the proper chart owner to reference unless it calls upon a user-drawn object. This cannot be guaranteed though. The property mentioned above is not supposed to be edited.

                See the bottom of this page for more details on the sudo workaround:
                https://www.oceantradingindicators.x...ons-user-guide
                Last edited by Unsuitable; 02-16-2021, 06:05 PM.
                Unsuitable
                NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                Comment


                  #9
                  Thanks very much for looking into it!
                  I'm gonna try it asap.

                  Comment


                    #10
                    Thanks again! Works like a charm!

                    Comment


                      #11
                      Hello wjadevries,

                      No problem!
                      Unsuitable
                      NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      602 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      347 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      103 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      560 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      559 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X