Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator not finding line drawing object

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

    Indicator not finding line drawing object

    I have an indicator that is looking for a line in DrawObjetcs. The code I'm using is below.


    PHP Code:
            private void CheckForLine()
            {
                found = false;
                lineStop = 0;
                foreach (DrawingTool draw in DrawObjects.ToList())
                {    
    Print(draw.Tag);                
                    if (draw.Tag.Contains("Line"))
                    {
                        entry = draw.Anchors.First().Price;
                        lineStop = draw.Anchors.Last().Price;
                        entryBar = CurrentBar - (int)draw.Anchors.First().SlotIndex;
                        found = true;
                    }
                }
            }
    ​ 
    
    I call CheckForLine() in State.Transition

    PHP Code:
    else if (State == State.Transition)
                {
                    CheckForLine();
                }    
    ​ 
    

    I draw the line, then Press F5 to reload the indicator. I can see the line on the chart and in the Drawing Objects dialog box, but the CheckForLine() method doesn't see it. But it does see the Period draw object.

    Any idea why it doesn't see the line?



    Click image for larger version

Name:	image.png
Views:	111
Size:	149.9 KB
ID:	1339087

    #2
    It should be possible to detect it. I found this post that I think is doing something similar to what you are trying. Maybe give that a look to see what you can get out of it.

    Comment


      #3
      Thanks rockmanx00
      I will give that a try

      Comment


        #4
        Even if you see drawing objects on chart, sometimes when you iterate they are null. Try add a line on chart then add your indicator and see if it works. More often then not it's null. I dont know if they fixed it in NT8.1.X but I've been dealing with this bug for years on 8.0.X. The workaround is to save workspace and restart NT.

        Comment


          #5
          The best place to find DrawingTools in a chart from an indicator or strategy is within the OnRender method.
          You can use a boolean so that the search code is only executed once and not overload unnecessarily the execution of OnRender.
          You could also add a personalized button to the Chart menu bar to start the search at discretion (instead of using the State.Transition or other); In addition to this way you could add and found new DrawingTools without reloading the indicator or strategy.

          cre8able​, if you move the code to OnRender will always work 100%.

          I've been using DrawingTools + indicators + strategies that are communicated through events for years, and I have never had issues (except when the fault was my bad code)

          Comment


            #6
            I use OnRender to draw on the chart but never used it for the code like you suggested cls71 . It worked and found my line. Thanks.

            But now I have a different problem. After I find the line I need to "look forward" to see if my stop or target was hit. I also collect other info like how long the trade was open, etc.

            When I looked for the line in OnBarUpdate, I could "look forward".

            But now when finding the line in OnRender, I can't figure out where to look forward.

            I added a Print statement in 3 different places. OnRender, State.Realtime, OnBarUpdate.

            I wanted to see what each method would see. Here is what the code is:


            PHP Code:
            Print("OnBarUpdate   " + entryBar + "   " + Low[0]);
            ​ 
            

            From the output window, I can see that OnBarUpdate runs, then State.Realtime, then OnRender.

            OnBarUpdate and State.Realtime both have the correct Value for Low[0]., but they don't know what bar is the entryBar. They have it as 0 since OnRender didn't run yet.

            Then OnRender runs and has the correct bar number for the entryBar, but it thinks bar 0 is the first bar on the chart, not the last. So I cant iterate forward to see where the trade goes.

            I know my problem is running the code at the right time where I have all the bars loaded and also know the bar number of the entry bar. I don't know where that is

            any help is appreciated

            Click image for larger version  Name:	image.png Views:	0 Size:	277.5 KB ID:	1339167​​
            Attached Files
            Last edited by cre8able; 03-30-2025, 02:32 PM.

            Comment


              #7
              Leeroy_Jenkins
              If I put the line on the chart then load the indicator it works. But if the indicator is already on the chart, it doesn't see the line when I add it.

              Seems like there should be a way to see it in OnBarUpdate if I can see it in OnRender​

              Comment


                #8
                Originally posted by cre8able View Post
                Leeroy_Jenkins
                If I put the line on the chart then load the indicator it works. But if the indicator is already on the chart, it doesn't see the line when I add it.

                Seems like there should be a way to see it in OnBarUpdate if I can see it in OnRender​
                If you used a boolean in the Onrender to execute the search only once, that is the reason. You would have to remove the boolean or correct the code.

                On the other hand, if you want to know in which bar the exit order was filled, you would have to override the OnOrderUpdate or OnExecutionUpdate method and thus be able to update some variable that you could use in the Onrender to customize the rendering.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                571 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                330 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                548 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                549 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X